diff options
| author | seth <[email protected]> | 2023-12-02 19:13:03 -0500 |
|---|---|---|
| committer | seth <[email protected]> | 2023-12-15 16:41:13 -0500 |
| commit | 36bb911f312a9baa5c152cc591060b2e4f8bc930 (patch) | |
| tree | 1d1eebee29c389649cea6ef446ad0fc4390f706a /src/main.rs | |
| parent | 0025ad5ea8d412aacc3184d18063fd5ff3de0175 (diff) | |
chore: register guild commands for servers that opt-in
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 32 |
1 files changed, 24 insertions, 8 deletions
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<String> = 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) }) }); |
