aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/handlers/commands.rs')
-rw-r--r--src/handlers/commands.rs29
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);
+ }
+ }
+}