-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcooldowns-manager.js
33 lines (26 loc) · 997 Bytes
/
cooldowns-manager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const Discord = require('discord.js-light');
const { cooldownsEnabled, defaultCooldownAmount } = require('../../config/commands-config.json');
const cooldowns = new Discord.Collection();
module.exports = {
// Taken from https://discordjs.guide/command-handling/adding-features.html#cooldowns
async isCmdOnCooldown(userID, command) {
if (!cooldownsEnabled) {
return false;
}
if (!cooldowns.has(command.name)) {
cooldowns.set(command.name, new Discord.Collection());
}
const now = Date.now();
const timestamps = cooldowns.get(command.name);
const cooldownAmount = (command.cooldown || defaultCooldownAmount);
if (timestamps.has(userID)) {
const expirationTime = timestamps.get(userID) + cooldownAmount;
if (now < expirationTime) {
// const timeLeft = (expirationTime - now) / 1000;
return true;
}
}
timestamps.set(userID, now);
return false;
},
};