Compare commits

..

1 commit

Author SHA1 Message Date
afdbbee495 Move ratelimiter to its own function 2022-12-18 23:20:53 +01:00
4 changed files with 6 additions and 11 deletions

View file

@ -52,9 +52,8 @@ export default {
*/
// Check the ratelimit
const doRateLimit = ratelimiter.check(interaction.user, commandName, command);
const doRateLimit = ratelimiter.check(userID, commandName, command);
if (doRateLimit) {
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m is rate limited on \x1b[33m${commandName}\x1b[0m for ${ratelimiter.timeLeft(userID, commandName)} seconds`);
return interaction.reply({ content: doRateLimit, ephemeral: true });
}

View file

@ -313,7 +313,7 @@ export default {
}
// Check the ratelimit
const doRateLimit = ratelimiter.check(message.author, commandName, command);
const doRateLimit = ratelimiter.check(userID, commandName, command);
if (doRateLimit) {
return message.reply({ content: doRateLimit, ephemeral: true });

View file

@ -6,6 +6,7 @@ export default {
once: true,
async execute(client) {
// Init global variables.
global.ratelimit = {};
global.boards = {};
const ytdlpVersion = await new Promise((resolve, reject) => {

View file

@ -1,12 +1,8 @@
const ratelimit = {};
export default {
check,
};
function check(user, commandName, commands) {
const userID = user.id;
const userTag = user.tag;
function check(userID, commandName, commands) {
const ratelimit = global.ratelimit;
if (!ratelimit[userID]) {
ratelimit[userID] = {};
}
@ -21,7 +17,6 @@ function check(user, commandName, commands) {
}
if (commands.ratelimit === ratelimit[userID][commandName].limit) {
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m is rate limited on \x1b[33m${commandName}\x1b[0m for ${Math.floor((ratelimit[userID][commandName].cooldown - date) / 1000)} seconds`);
return `You are being rate limited. You can try again in ${Math.floor((ratelimit[userID][commandName].cooldown - date) / 1000)} seconds.`;
}
}
@ -36,4 +31,4 @@ function check(user, commandName, commands) {
}
}
return false;
}
}