From fdccd9057d00530989aa8f05f2000814d050db49 Mon Sep 17 00:00:00 2001 From: Navy Date: Wed, 5 May 2021 17:47:04 +0300 Subject: [PATCH] random bs --- structure/client/RateLimiter.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/structure/client/RateLimiter.js b/structure/client/RateLimiter.js index ea0ebff..ee8b742 100644 --- a/structure/client/RateLimiter.js +++ b/structure/client/RateLimiter.js @@ -17,7 +17,7 @@ class RateLimiter { this.lastSend = {}; //used by limitSend - this.sendInterval = 7.5; //How frequently sending is allowed in seconds + this.sendInterval = 7.5 * 1000; //How frequently sending is allowed in seconds this.deleteInterval = 2.5; //How frequently delete queues should be executed } @@ -167,16 +167,17 @@ class RateLimiter { limitSend(channel, message, limit = 15, utility = 'default') { return new Promise((resolve, reject) => { - if(!channel || !(channel instanceof TextChannel)) reject(new Error('Missing channel')); - if(!channel.permissionsFor(channel.guild.me).has('SEND_MESSAGES')) reject(new Error('Missing permission SEND_MESSAGES')); - if(!message) reject(new Error('Missing message')); + if (!channel || !(channel instanceof TextChannel)) reject(new Error('Missing channel')); + if (!channel.permissionsFor(channel.guild.me).has('SEND_MESSAGES')) reject(new Error('Missing permission SEND_MESSAGES')); + if (!message) reject(new Error('Missing message')); + if (limit === null) limit = 15; - const now = Math.floor(Date.now()/1000); - if(!this.lastSend[channel.id]) this.lastSend[channel.id] = {}; - if(!this.lastSend[channel.id][utility]) this.lastSend[channel.id][utility] = 0; + const now = Date.now(); + if (!this.lastSend[channel.id]) this.lastSend[channel.id] = {}; + if (!this.lastSend[channel.id][utility]) this.lastSend[channel.id][utility] = 0; const lastSent = this.lastSend[channel.id][utility]; - if(now-limit >= lastSent) { + if(now-limit*1000 >= lastSent) { this.lastSend[channel.id][utility] = now; resolve(channel.send(message)); } else resolve(false);