mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 02:15:10 +02:00
Improve phone ratelimit
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "116.13.2",
|
"version": "116.13.3",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ module.exports = class PhoneCall {
|
|||||||
this.timeout = null;
|
this.timeout = null;
|
||||||
this.ownerOrigin = ownerOrigin || false;
|
this.ownerOrigin = ownerOrigin || false;
|
||||||
this.cooldown = new Set();
|
this.cooldown = new Set();
|
||||||
|
this.ratelimitMeters = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
@@ -93,12 +94,20 @@ module.exports = class PhoneCall {
|
|||||||
}
|
}
|
||||||
if (this.cooldown.has(msg.author.id) && !this.client.isOwner(msg.author)) {
|
if (this.cooldown.has(msg.author.id) && !this.client.isOwner(msg.author)) {
|
||||||
const badChannel = channel.id === this.origin.id ? this.recipient : this.origin;
|
const badChannel = channel.id === this.origin.id ? this.recipient : this.origin;
|
||||||
return badChannel.send(`☎️ ${msg.author}, please wait **5** seconds between messages!`);
|
return badChannel.send(`☎️ ${msg.author}, slow down! You're sending messages too fast!`);
|
||||||
}
|
}
|
||||||
this.setTimeout();
|
this.setTimeout();
|
||||||
if (!this.client.isOwner(msg.author)) {
|
if (!this.client.isOwner(msg.author)) {
|
||||||
this.cooldown.add(msg.author.id);
|
const ratelimit = this.ratelimitMeters.get(msg.author.id);
|
||||||
setTimeout(() => this.cooldown.delete(msg.author.id), 5000);
|
if (!ratelimit) ratelimit.set(msg.author.id, 1);
|
||||||
|
if (ratelimit > 2) {
|
||||||
|
this.cooldown.add(msg.author.id);
|
||||||
|
setTimeout(() => this.cooldown.delete(msg.author.id), 10000);
|
||||||
|
ratelimit.set(msg.author.id, 0);
|
||||||
|
} else {
|
||||||
|
ratelimit.set(msg.author.id, ratelimit + 1);
|
||||||
|
setTimeout(() => ratelimit.set(msg.author.id, 0), 5000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const attachments = hasImage ? msg.attachments.map(a => a.url).join('\n') : null;
|
const attachments = hasImage ? msg.attachments.map(a => a.url).join('\n') : null;
|
||||||
if (!hasText && hasImage) return channel.send(`☎️ **${msg.author.tag}:**\n${attachments}`);
|
if (!hasText && hasImage) return channel.send(`☎️ **${msg.author.tag}:**\n${attachments}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user