Compare commits

..

2 commits

Author SHA1 Message Date
7254a242db No ratelimit global variable 2022-12-18 23:30:34 +01:00
d225d7037c Move ratelimiter to its own function 2022-12-18 23:30:25 +01:00
4 changed files with 11 additions and 6 deletions

View file

@ -52,8 +52,9 @@ export default {
*/
// Check the ratelimit
const doRateLimit = ratelimiter.check(userID, commandName, command);
const doRateLimit = ratelimiter.check(interaction.user, 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(userID, commandName, command);
const doRateLimit = ratelimiter.check(message.author, commandName, command);
if (doRateLimit) {
return message.reply({ content: doRateLimit, ephemeral: true });

View file

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

View file

@ -1,8 +1,12 @@
const ratelimit = {};
export default {
check,
};
function check(userID, commandName, commands) {
const ratelimit = global.ratelimit;
function check(user, commandName, commands) {
const userID = user.id;
const userTag = user.tag;
if (!ratelimit[userID]) {
ratelimit[userID] = {};
}
@ -17,6 +21,7 @@ function check(userID, 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.`;
}
}