aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/commands.rs
blob: d07bdcbc9892102716a1f8ea3045afd2970f8b7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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);
        }
    }
}