@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
39 lines (37 loc) • 1.65 kB
JavaScript
import { BucketScope, CommandPreConditions } from "../types/Enums.mjs";
import "../utils/preconditions/PreconditionContainerArray.mjs";
import { container } from "@sapphire/pieces";
//#region src/lib/precondition-resolvers/cooldown.ts
/**
* Appends the `Cooldown` precondition when {@link Command.Options.cooldownLimit} and
* {@link Command.Options.cooldownDelay} are both non-zero.
*
* @param command The command to parse cooldowns for.
* @param cooldownLimit The cooldown limit to use.
* @param cooldownDelay The cooldown delay to use.
* @param cooldownScope The cooldown scope to use.
* @param cooldownFilteredUsers The cooldown filtered users to use.
* @param preconditionContainerArray The precondition container array to append the precondition to.
*/
function parseConstructorPreConditionsCooldown(command, cooldownLimit, cooldownDelay, cooldownScope, cooldownFilteredUsers, preconditionContainerArray) {
const { defaultCooldown } = container.client.options;
const filtered = defaultCooldown?.filteredCommands?.includes(command.name) ?? false;
const limit = cooldownLimit ?? (filtered ? 0 : defaultCooldown?.limit ?? 1);
const delay = cooldownDelay ?? (filtered ? 0 : defaultCooldown?.delay ?? 0);
if (limit && delay) {
const scope = cooldownScope ?? defaultCooldown?.scope ?? BucketScope.User;
const filteredUsers = cooldownFilteredUsers ?? defaultCooldown?.filteredUsers;
preconditionContainerArray.append({
name: CommandPreConditions.Cooldown,
context: {
scope,
limit,
delay,
filteredUsers
}
});
}
}
//#endregion
export { parseConstructorPreConditionsCooldown };
//# sourceMappingURL=cooldown.mjs.map