From 36bb911f312a9baa5c152cc591060b2e4f8bc930 Mon Sep 17 00:00:00 2001 From: seth Date: Sat, 2 Dec 2023 19:13:03 -0500 Subject: chore: register guild commands for servers that opt-in --- src/main.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 6921f8a..afedd1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use log::*; use poise::{ serenity_prelude as serenity, EditTracker, Framework, FrameworkOptions, PrefixFrameworkOptions, }; +use redis::AsyncCommands; use settings::Settings; mod api; @@ -68,18 +69,33 @@ async fn main() -> Result<()> { .options(options) .setup(|ctx, _ready, framework| { Box::pin(async move { + let data = Data::new()?; + poise::builtins::register_globally(ctx, &framework.options().commands).await?; info!("Registered global commands!"); - poise::builtins::register_in_guild( - ctx, - &commands::to_guild_commands(), - consts::TEAWIE_GUILD, - ) - .await?; - info!("Registered guild commands to {}", consts::TEAWIE_GUILD); + // register "extra" commands in guilds that allow it + let mut con = data.redis.get_async_connection().await?; + + info!("Fetching all guild settings from Redis...this might take a while"); + let guilds: Vec = con.keys(format!("{}:*", settings::ROOT_KEY)).await?; + + for guild in guilds { + let settings: Settings = con.get(guild).await?; + + if settings.optional_commands_enabled { + poise::builtins::register_in_guild( + ctx, + &commands::to_guild_commands(), + settings.guild_id, + ) + .await?; + info!("Registered guild commands to {}", settings.guild_id); + } else { + debug!("Not registering guild commands to {} since optional_commands_enabled is False", settings.guild_id); + } + } - let data = Data::new()?; Ok(data) }) }); -- cgit v1.2.3