Skip to content

WebUI Controller

Aaron Graubert requested to merge staging-4.0.0 into master

This is Beymax's biggest change in a while, which adds library support for a web interface. The website is part of the codebase, which means that any of you reading this can easily spin up your own Discord bot with its own web interface, and that future improvements made to the site will come to yours as well. The changes include

Beymax Version 4.0.0 / API 1.0.0

API Changes

  • BREAKING CHANGE: AbstractControlInterface.config_get() now takes a guild_id argument. This is used to get config for a specific guild, although controllers may choose to ignore the argument, as the Dummy controller does.
  • BREAKING CHANGE: Client.channel_references is now a set, not a dict. This is to allow the reference lookup to be handled more by the controller on a guild-by-guild basis
  • BREAKING CHANGE: Removed Client.add_legacy_task_chain() and the legacy argument to CommandSuite.add_task(). Legacy tasks were kind of shit.
  • BREAKING CHANGE: The previous beymax.Client.fetch_channel has been renamed to beymax.Client.fetch_channel_reference() so as not to conflict with discord.Client.fetch_channel
  • BREAKING CHANGE: Removed the event argument to Client.shutdown(). The client will now always attempt to set the controller's .shutdown attribute, if possible
  • BREAKING CHANGE: Client.on_message has been moved to an event handler in APIEssesntials so that it can be hooked just like any other event handler. It's behavior has also been tweaked slightly
  • BREAKING CHANGE: Added a mandatory guild_context argument to Client.dispatch_future(). This is to prevent a situation where one shard may dispatch a future event, but a different shard could retrieve the event from the database. guild_context should only be set to None or DEFAULT_NULL_GUILD_ID if it truely does not matter which shard extracts an event. It is worth noting that, due to the dynamic time interval of the future dispatch loop, intentionally dispatching a future event to a different shard's guild is not a supported use case. The "receiving" shard may never detect the event if it doesn't already have other future events.
  • Added beymax.control.WebUIControlInterface. This control interface adds a /config command to the client, as well as a few database tables and some event handlers.
  • Improved some error logging and handling in the AbstractControlInterface base class
  • Added a .shutdown attribute to the AbstractControlInterface base class. This asyncio Event can be used anywhere by the client or controller to signal the event loop to halt. Triggering the event will (more or less) immediately halt the main event loop, assuming it was called using controller.start_loop_interrupt_safe(). It's best not to use this event directly, and instead call client.shutdown(). Triggering the event will cause an ungraceful shutdown of the controller.
  • Added a DEFAULT_NULL_GUILD_ID constant. This is to comply with the schema for APIEssentials:KeyValue, which uses the guild_id as a pkey. DEFAULT_NULL_GUILD_ID should be used whenever you're using the key/value store outside of a guild context
  • Migrations can now fail without crashing the bot
  • Removed the ignored roles logic
  • APIEssentials:FutureDispatch is now a regular table which can be queried by the /viewdb command
  • A CommandSuite dependency is no longer force-enabled. Instead, during WebUIControlInterface.suite_enabled_in_guild(), the suite reports as enabled if any suite which depends on it is also enabled OR if the suite itself has been enabled
  • Added a new mention event. This event is triggered any time the bot is mentioned in a message it can see. The bot does not need access to the message_content privileged intent, as the bot can access the content implicitly from messages where it is mentioned.

Production Changes

Note: For now the Webui, and changes to it, will be considered part of the production codebase. This may change in the future, and we might start tracking a third version number

  • Added the WebUI controller implementation
  • Switched the production codebase to using the webui. However, there still is a script to run the same codebase using the dummy controller.
Edited by Aaron Graubert

Merge request reports