18 lines
450 B
JavaScript
18 lines
450 B
JavaScript
const cooldowns = new Map();
|
|
|
|
function isOnCooldown(actionId, cooldownSeconds) {
|
|
if (!cooldownSeconds) return false;
|
|
const last = cooldowns.get(actionId);
|
|
if (!last) return false;
|
|
return (Date.now() - last) < cooldownSeconds * 1000;
|
|
}
|
|
|
|
function setCooldown(actionId) {
|
|
cooldowns.set(actionId, Date.now());
|
|
}
|
|
|
|
function resetCooldown(actionId) {
|
|
cooldowns.delete(actionId);
|
|
}
|
|
|
|
module.exports = { isOnCooldown, setCooldown, resetCooldown };
|