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/commands/mod.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/commands/mod.rs (limited to 'src/commands/mod.rs') 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(()) + } + } +} -- cgit v1.2.3