random bs
This commit is contained in:
parent
a7b0098695
commit
fdccd9057d
@ -17,7 +17,7 @@ class RateLimiter {
|
|||||||
|
|
||||||
this.lastSend = {}; //used by limitSend
|
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
|
this.deleteInterval = 2.5; //How frequently delete queues should be executed
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -167,16 +167,17 @@ class RateLimiter {
|
|||||||
limitSend(channel, message, limit = 15, utility = 'default') {
|
limitSend(channel, message, limit = 15, utility = 'default') {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if(!channel || !(channel instanceof TextChannel)) reject(new Error('Missing channel'));
|
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 (!channel.permissionsFor(channel.guild.me).has('SEND_MESSAGES')) reject(new Error('Missing permission SEND_MESSAGES'));
|
||||||
if(!message) reject(new Error('Missing message'));
|
if (!message) reject(new Error('Missing message'));
|
||||||
|
if (limit === null) limit = 15;
|
||||||
|
|
||||||
const now = Math.floor(Date.now()/1000);
|
const now = Date.now();
|
||||||
if(!this.lastSend[channel.id]) this.lastSend[channel.id] = {};
|
if (!this.lastSend[channel.id]) this.lastSend[channel.id] = {};
|
||||||
if(!this.lastSend[channel.id][utility]) this.lastSend[channel.id][utility] = 0;
|
if (!this.lastSend[channel.id][utility]) this.lastSend[channel.id][utility] = 0;
|
||||||
|
|
||||||
const lastSent = this.lastSend[channel.id][utility];
|
const lastSent = this.lastSend[channel.id][utility];
|
||||||
if(now-limit >= lastSent) {
|
if(now-limit*1000 >= lastSent) {
|
||||||
this.lastSend[channel.id][utility] = now;
|
this.lastSend[channel.id][utility] = now;
|
||||||
resolve(channel.send(message));
|
resolve(channel.send(message));
|
||||||
} else resolve(false);
|
} else resolve(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user