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/commands/mod.rs | |
parent | 7017762a4a38266aa88976be141f7bd663647edc (diff) |
Commands to interact with discocaml, associated IPC.
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(()) + } + } +} |