Cooldown
Pure utility functions for cooldown and concurrency state management.
Summary
Functions
Cooldown.checkCooldown(cooldowns: { [string]: number }, commandName: string, rules: { command.CooldownRule }, interaction: classes.TypesCommand) → number?Cooldown.applyCooldown(cooldowns: { [string]: number }, commandName: string, rules: { command.CooldownRule }, interaction: classes.TypesCommand)Cooldown.acquireConcurrency(concurrency: { [string]: number }, commandName: string, rule: { limit: number, per: "user" | "guild" | "channel" | "member" | "global" }, interaction: classes.TypesCommand) → booleanCooldown.releaseConcurrency(concurrency: { [string]: number }, commandName: string, rule: { limit: number, per: "user" | "guild" | "channel" | "member" | "global" }, interaction: classes.TypesCommand)Functions
Section titled “Functions”checkCooldown
Section titled “checkCooldown”Cooldown . checkCooldown ( cooldowns , commandName , rules , interaction ) -> number?
Returns the maximum remaining cooldown in seconds across all rules, or nil if no cooldown is active.
Parameters
| cooldowns: { { [string]: number } } | |
| commandName: string | |
| rules: CooldownRule } | |
| interaction: TypesCommand |
Returns
| number? |
applyCooldown
Section titled “applyCooldown”Cooldown . applyCooldown ( cooldowns , commandName , rules , interaction ) -> ()
Records a cooldown expiry for each rule, keyed by the rule's per scope.
Parameters
| cooldowns: { { [string]: number } } | |
| commandName: string | |
| rules: CooldownRule } | |
| interaction: TypesCommand |
acquireConcurrency
Section titled “acquireConcurrency”Cooldown . acquireConcurrency ( concurrency , commandName , rule , interaction ) -> boolean
Attempts to acquire a concurrency slot. Returns false if the limit for the scope is already reached.
Parameters
| concurrency: { { [string]: number } } | |
| commandName: string | |
| rule: { limit: number, per: "user" | "guild" | "channel" | "member" | "global", } | |
| interaction: TypesCommand |
Returns
| boolean |
releaseConcurrency
Section titled “releaseConcurrency”Cooldown . releaseConcurrency ( concurrency , commandName , rule , interaction ) -> ()
Releases a previously acquired concurrency slot.
Parameters
| concurrency: { { [string]: number } } | |
| commandName: string | |
| rule: { limit: number, per: "user" | "guild" | "channel" | "member" | "global", } | |
| interaction: TypesCommand |