pub 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(()) } }, Interaction::Component(component) => { if component.data.custom_id.starts_with("discocaml-") { discocaml::handle_button(ctx, &config.discocaml, db, component) .await .context("failed to handle discocaml command") } else { log::warn!("unexpected interaction: {:#?}", interaction); Ok(()) } } _ => { log::warn!("unexpected interaction: {:#?}", interaction); Ok(()) } } }