From bef8fda3daeef3e688f313dfbb198c57e667f38a Mon Sep 17 00:00:00 2001 From: jamesbt365 Date: Tue, 4 Jun 2024 01:21:03 +0100 Subject: [PATCH] Make manual cooldowns on commands optional & document --- macros/src/command/mod.rs | 4 ++-- macros/src/command/prefix.rs | 5 ++++- macros/src/command/slash.rs | 10 ++++++++-- macros/src/lib.rs | 2 +- src/structs/command.rs | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/macros/src/command/mod.rs b/macros/src/command/mod.rs index d94beb2b2d0f..5b1decf89714 100644 --- a/macros/src/command/mod.rs +++ b/macros/src/command/mod.rs @@ -49,7 +49,7 @@ pub struct CommandArgs { category: Option, custom_data: Option, - manual_cooldowns: bool, + manual_cooldowns: Option, // In seconds global_cooldown: Option, @@ -282,7 +282,7 @@ fn generate_command(mut inv: Invocation) -> Result Result Result>::to_action(|ctx, value| { Box::pin(async move { - if !ctx.framework.options.manual_cooldowns && !ctx.command.manual_cooldowns { + let is_framework_cooldown = !ctx.command.manual_cooldowns + .unwrap_or_else(|| ctx.framework.options.manual_cooldowns); + + if is_framework_cooldown { ctx.command.cooldowns.lock().unwrap().start_cooldown(ctx.cooldown_context()); } diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 5316651af233..670806501ffd 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -67,7 +67,7 @@ for example for command-specific help (i.e. `~help command_name`). Escape newlin - `reuse_response`: After the first response, post subsequent responses as edits to the initial message (prefix only) ## Cooldown - +- `manual_cooldowns`: Allows overriding the framework's built-in cooldowns tracking without affecting other commands. - `global_cooldown`: Minimum duration in seconds between invocations, globally - `user_cooldown`: Minimum duration in seconds between invocations, per user - `guild_cooldown`: Minimum duration in seconds between invocations, per guild diff --git a/src/structs/command.rs b/src/structs/command.rs index 540965f31d7a..9a300b3f9369 100644 --- a/src/structs/command.rs +++ b/src/structs/command.rs @@ -62,7 +62,7 @@ pub struct Command { /// /// Will override [`crate::FrameworkOptions::manual_cooldowns`] allowing manual cooldowns /// on select commands. - pub manual_cooldowns: bool, + pub manual_cooldowns: Option, /// Handles command cooldowns. Mainly for framework internal use pub cooldowns: std::sync::Mutex, /// Configuration for the [`crate::CooldownTracker`]