Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event handling #1

Merged
merged 7 commits into from
Apr 4, 2024
Merged

Event handling #1

merged 7 commits into from
Apr 4, 2024

Conversation

lcox74
Copy link
Contributor

@lcox74 lcox74 commented Apr 4, 2024

This PR introduces event routing for interactions, including buttons and modals, within App Commands. It also refactors our terminology from "commands" to "applications" to more accurately reflect the functionality that can either handle events, commands, or both. Additionally, this PR includes crucial fixes and an example to facilitate understanding of the new features.

Key Changes

  • Feature Integration for Event-Driven Interactions: Implemented a framework to support interactions such as buttons and modals through event routing. This allows app.OnEvent(...) to be directly managed, offering a more intuitive handling of user interactions.

  • Documentation and Examples: Added some documentation on utilising custom IDs for event handling, along with a practical example demonstrating the use of events and buttons. This aims to provide clear guidance on how to leverage the new functionalities effectively.

  • Application Type Flexibility: Introduced the ability for applications to be classified not just as commands but also as event-only applications, enhancing the versatility of our bot's operational capabilities.

  • Refactoring: Shifted the terminology from "commands" to "applications" to better encompass the dual nature of these functionalities, which can now be either event-driven, command-driven, or both.

  • Environment Configuration Fix: Corrected the sequence of loading environment variables to ensure that token variables are set post-loading the .env file, addressing a critical setup issue.

  • Library Update and Bug Fix: Updated the discordgo library to its latest version, which resolves a bug related to message component buttons. This fix permits the omission of emojis in message components, where previously an emoji was required, preventing potential errors.

Implementation Details

  • Events and interactions are now seamlessly integrated through the application type, with a routing mechanism for handling events app.OnEvent(...).

  • The use of custom_id in interactions follows a structured format, facilitating the parsing of commands and subcommands, and is accessible via ctx.EventValue().

  • Provided an illustrative example of a ping button, showcasing the practical application of the event system and demonstrating the ease of implementing interactive components.

@lcox74 lcox74 merged commit 8a2819f into main Apr 4, 2024
@lcox74 lcox74 deleted the event_handling branch April 4, 2024 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant