From 4025afa6ce026aedf711af06a7287e1951f51879 Mon Sep 17 00:00:00 2001 From: jamesbt365 Date: Mon, 20 May 2024 16:54:33 +0100 Subject: [PATCH] Add support for using manual cooldowns on single commands --- macros/Cargo.lock | 2 +- macros/src/command/mod.rs | 4 ++++ macros/src/command/prefix.rs | 2 +- macros/src/command/slash.rs | 4 ++-- src/structs/command.rs | 5 +++++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/macros/Cargo.lock b/macros/Cargo.lock index de9713ee6919..c8eb1734ae78 100644 --- a/macros/Cargo.lock +++ b/macros/Cargo.lock @@ -51,7 +51,7 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "poise_macros" -version = "0.5.7" +version = "0.6.1" dependencies = [ "darling", "proc-macro2", diff --git a/macros/src/command/mod.rs b/macros/src/command/mod.rs index 8c7f8bbd6136..d94beb2b2d0f 100644 --- a/macros/src/command/mod.rs +++ b/macros/src/command/mod.rs @@ -49,6 +49,8 @@ pub struct CommandArgs { category: Option, custom_data: Option, + manual_cooldowns: bool, + // In seconds global_cooldown: Option, user_cooldown: Option, @@ -280,6 +282,7 @@ fn generate_command(mut inv: Invocation) -> Result Result Result Result>::to_action(|ctx, value| { Box::pin(async move { - if !ctx.framework.options.manual_cooldowns { + if !ctx.framework.options.manual_cooldowns && !ctx.command.manual_cooldowns { ctx.command.cooldowns.lock().unwrap().start_cooldown(ctx.cooldown_context()); } diff --git a/src/structs/command.rs b/src/structs/command.rs index 453a4840151f..540965f31d7a 100644 --- a/src/structs/command.rs +++ b/src/structs/command.rs @@ -58,6 +58,11 @@ pub struct Command { /// Multiline description with detailed usage instructions. Displayed in the command specific /// help: `~help command_name` pub help_text: Option, + /// if `true`, disables automatic cooldown handling before this commands invocation. + /// + /// Will override [`crate::FrameworkOptions::manual_cooldowns`] allowing manual cooldowns + /// on select commands. + pub manual_cooldowns: bool, /// Handles command cooldowns. Mainly for framework internal use pub cooldowns: std::sync::Mutex, /// Configuration for the [`crate::CooldownTracker`]