From 00d0bfced902e97eeae5257c14134d4bc7efc710 Mon Sep 17 00:00:00 2001 From: Nathan Ringo Date: Thu, 18 Jan 2024 10:58:36 -0600 Subject: Commands to interact with discocaml, associated IPC. --- src/handlers/commands.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/handlers/commands.rs (limited to 'src/handlers/commands.rs') 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); + } + } +} -- cgit v1.2.3