forked from Supositware/Haha-Yes
Always register a cooldown even when the limit has not been hit
This commit is contained in:
parent
2c37b3a64f
commit
f8cf11e7ff
1 changed files with 7 additions and 10 deletions
|
@ -13,7 +13,7 @@ function check(user, commandName, commands) {
|
|||
|
||||
const date = new Date();
|
||||
if (ratelimit[userID][commandName]) {
|
||||
if (ratelimit[userID][commandName].cooldown) {
|
||||
if (ratelimit[userID][commandName].cooldown && ratelimit[userID][commandName].limit === commands.ratelimit) {
|
||||
if (date > ratelimit[userID][commandName].cooldown) {
|
||||
ratelimit[userID][commandName].limit = 0;
|
||||
ratelimit[userID][commandName].cooldown = undefined;
|
||||
|
@ -24,20 +24,17 @@ function check(user, commandName, commands) {
|
|||
const seconds = Math.floor((ratelimit[userID][commandName].cooldown - date) / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const dateString = `${hours > 0 ? `${Math.floor(hours)} hours` : ''}${minutes > 0 ? ` ${Math.floor(minutes % 60)} minutes` : ''}${seconds > 0 ? ` ${Math.floor(seconds % 60)} seconds` : ''}`;
|
||||
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m is rate limited on \x1b[33m${commandName}\x1b[0m for ${dateString}.`);
|
||||
return `You are being rate limited. You can try again in ${dateString}.`;
|
||||
const dateString = `${hours > 0 ? ` ${Math.floor(hours)} hours` : ''}${minutes > 0 ? ` ${Math.floor(minutes % 60)} minutes` : ''}${seconds > 0 ? ` ${Math.floor(seconds % 60)} seconds` : ''}`;
|
||||
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m is rate limited on \x1b[33m${commandName}\x1b[0m for${dateString}.`);
|
||||
return `You are being rate limited. You can try again in${dateString}.`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (commands.ratelimit) {
|
||||
ratelimit[userID][commandName] = { limit: ratelimit[userID][commandName] ? ratelimit[userID][commandName].limit + 1 : 1 };
|
||||
if (commands.ratelimit === ratelimit[userID][commandName].limit) {
|
||||
date.setSeconds(date.getSeconds() + commands.cooldown);
|
||||
ratelimit[userID][commandName] = { limit: ratelimit[userID][commandName] ? ratelimit[userID][commandName].limit + 1 : 1, cooldown: date };
|
||||
}
|
||||
|
||||
ratelimit[userID][commandName] = { limit: ratelimit[userID][commandName].limit, cooldown: date };
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
Loading…
Reference in a new issue