diff options
Diffstat (limited to 'src/commands/mod.rs')
-rw-r--r-- | src/commands/mod.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/commands/mod.rs b/src/commands/mod.rs new file mode 100644 index 0000000..083b200 --- /dev/null +++ b/src/commands/mod.rs @@ -0,0 +1,47 @@ +mod discocaml; + +use crate::commands::discocaml::DiscocamlConfig; +use anyhow::{Context as _, Result}; +use serde::Deserialize; +use serenity::{ + all::{Command, Interaction}, + client::Context, +}; +use sqlx::SqlitePool; + +#[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct CommandsConfig { + pub discocaml: DiscocamlConfig, +} + +pub async fn set_commands(ctx: &Context) -> Result<()> { + Command::set_global_commands(&ctx.http, vec![discocaml::command()]) + .await + .context("failed to set commands")?; + Ok(()) +} + +pub async fn handle_interaction( + ctx: &Context, + config: &CommandsConfig, + db: &SqlitePool, + interaction: &Interaction, +) -> Result<()> { + match interaction { + Interaction::Command(cmd) => match &cmd.data.name as &str { + "discocaml" => discocaml::handle_command(ctx, &config.discocaml, db, cmd) + .await + .context("failed to handle discocaml command"), + _ => { + log::warn!("unexpected interaction: {:?}", interaction); + Ok(()) + } + }, + + _ => { + log::warn!("unexpected interaction: {:?}", interaction); + Ok(()) + } + } +} |