diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-01-18 10:58:36 -0600 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-01-18 10:58:36 -0600 |
commit | 00d0bfced902e97eeae5257c14134d4bc7efc710 (patch) | |
tree | ee026f328614e03aec3ed373d9f2e6c8e255f834 /src/handlers/commands.rs | |
parent | 7017762a4a38266aa88976be141f7bd663647edc (diff) |
Commands to interact with discocaml, associated IPC.
Diffstat (limited to 'src/handlers/commands.rs')
-rw-r--r-- | src/handlers/commands.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/handlers/commands.rs b/src/handlers/commands.rs new file mode 100644 index 0000000..d07bdcb --- /dev/null +++ b/src/handlers/commands.rs @@ -0,0 +1,29 @@ +use crate::commands::{handle_interaction, set_commands, CommandsConfig}; +use serenity::{ + all::{Interaction, Ready}, + async_trait, + client::{Context, EventHandler}, +}; +use sqlx::SqlitePool; + +/// A handler that sets up the commands. +pub struct Commands { + pub config: CommandsConfig, + pub db: SqlitePool, +} + +#[async_trait] +impl EventHandler for Commands { + async fn ready(&self, ctx: Context, _data_about_bot: Ready) { + if let Err(err) = set_commands(&ctx).await { + log::error!("failed to set commands: {:?}", err) + } + } + + async fn interaction_create(&self, ctx: Context, interaction: Interaction) { + if let Err(err) = handle_interaction(&ctx, &self.config, &self.db, &interaction).await { + log::error!("failed to handle interaction: {:?}", err); + log::error!("failed interaction was: {:?}", interaction); + } + } +} |