Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: register cooldown correctly #304

Merged
merged 2 commits into from
Oct 17, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/lib/structures/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,21 @@ export abstract class Command<T = Args, O extends CommandOptions = CommandOption
* @param options The command options given from the constructor.
*/
protected parseConstructorPreConditionsCooldown(options: CommandOptions) {
const { cooldownLimit, cooldownDelay, cooldownScope, cooldownFilteredUsers } = options;
const { defaultCooldown } = this.container.client.options;

if ((defaultCooldown && !defaultCooldown.filteredCommands?.includes(this.name)) || (cooldownLimit && cooldownDelay)) {
// We will check for whether the command is filtered from the defaults, but we will allow overridden values to
// be set. If an overridden value is passed, it will have priority. Otherwise it will default to 0 if filtered
// (causing the precondition to not be registered) or the default value with a fallback to a single-use cooldown.
const filtered = defaultCooldown?.filteredCommands?.includes(this.name) ?? false;
const limit = options.cooldownLimit ?? (filtered ? 0 : defaultCooldown!.limit ?? 1);
const delay = options.cooldownDelay ?? (filtered ? 0 : defaultCooldown!.delay ?? 0);

if (limit && delay) {
const scope = options.cooldownScope ?? defaultCooldown?.scope ?? BucketScope.User;
const filteredUsers = options.cooldownFilteredUsers ?? defaultCooldown?.filteredUsers;
this.preconditions.append({
name: CommandPreConditions.Cooldown,
context: {
scope: cooldownScope ?? defaultCooldown?.scope ?? BucketScope.User,
limit: cooldownLimit ?? defaultCooldown?.limit ?? 1,
delay: cooldownDelay ?? defaultCooldown?.delay ?? 0,
filteredUsers: cooldownFilteredUsers ?? defaultCooldown?.filteredUsers
}
context: { scope, limit, delay, filteredUsers }
});
}
}
Expand Down