From 8718697115d8c9c7fb2de570abc572571265d731 Mon Sep 17 00:00:00 2001 From: JonnyBro Date: Sun, 27 Mar 2022 21:57:01 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20clear=20all?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/Moderation/clear.js | 94 +++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/commands/Moderation/clear.js b/commands/Moderation/clear.js index 799a98cc..e4b1c27d 100644 --- a/commands/Moderation/clear.js +++ b/commands/Moderation/clear.js @@ -19,57 +19,61 @@ class Clear extends Command { async run(message, args) { if (args[0] === "all") { message.channel.send(message.translate("moderation/clear:ALL_CONFIRM")); - - await message.channel.awaitMessages((m) => (m.author.id === message.author.id) && (m.content === "confirm"), { - max: 1, - time: 20000, - errors: ["time"] - }).catch(() => { - return message.error("misc:TIMES_UP"); + + const filter = m => m.author.id === message.author.id && m.content === "confirm"; + const collector = message.channel.createMessageCollector({ + filter, + time: 120000 // 2 minutes }); - const position = message.channel.position; - const newChannel = await message.channel.clone(); - await message.channel.delete(); - newChannel.setPosition(position); - return newChannel.send({ - content: message.translate("moderation/clear:CHANNEL_CLEARED") + collector.on("collect", async message => { + const position = message.channel.position; + const newChannel = await message.channel.clone(); + await message.channel.delete(); + newChannel.setPosition(position); + return newChannel.send({ + content: message.translate("moderation/clear:CHANNEL_CLEARED") + }); }); - } - const amount = args[0]; - if (!amount || isNaN(amount) || parseInt(amount) < 1) return message.error("moderation/clear:MISSING_AMOUNT"); - - await message.delete(); - - const user = message.mentions.users.first(); - - let messages = await message.channel.messages.fetch({ - limit: amount - }); - if (user) messages = messages.filter((m) => m.author.id === user.id); - if (messages.length > amount) messages.length = parseInt(amount, 10); - - messages = messages.filter((m) => !m.pinned); - - message.channel.bulkDelete(messages, true); - - let toDelete = null; - - if (user) { - toDelete = await message.channel.send(message.translate("moderation/clear:CLEARED_MEMBER", { - amount: `${amount} ${message.getNoun(amount, message.translate("misc:NOUNS:MESSAGES:1"), message.translate("misc:NOUNS:MESSAGES:2"), message.translate("misc:NOUNS:MESSAGES:5"))}`, - username: user.tag - })); + collector.on("end", (_, reason) => { + if (reason === "time") return message.error("misc:TIMES_UP"); + }); } else { - toDelete = await message.channel.send(message.translate("moderation/clear:CLEARED", { - amount: `${amount} ${message.getNoun(amount, message.translate("misc:NOUNS:MESSAGES:1"), message.translate("misc:NOUNS:MESSAGES:2"), message.translate("misc:NOUNS:MESSAGES:5"))}` - })); - } + const amount = args[0]; + if (!amount || isNaN(amount) || parseInt(amount) < 1) return message.error("moderation/clear:MISSING_AMOUNT"); - setTimeout(function () { - toDelete.delete(); - }, 2000); + await message.delete(); + + const user = message.mentions.users.first(); + + let messages = await message.channel.messages.fetch({ + limit: amount + }); + if (user) messages = messages.filter((m) => m.author.id === user.id); + if (messages.length > amount) messages.length = parseInt(amount, 10); + + messages = messages.filter((m) => !m.pinned); + + message.channel.bulkDelete(messages, true); + + let toDelete = null; + + if (user) { + toDelete = await message.channel.send(message.translate("moderation/clear:CLEARED_MEMBER", { + amount: `${amount} ${message.getNoun(amount, message.translate("misc:NOUNS:MESSAGES:1"), message.translate("misc:NOUNS:MESSAGES:2"), message.translate("misc:NOUNS:MESSAGES:5"))}`, + username: user.tag + })); + } else { + toDelete = await message.channel.send(message.translate("moderation/clear:CLEARED", { + amount: `${amount} ${message.getNoun(amount, message.translate("misc:NOUNS:MESSAGES:1"), message.translate("misc:NOUNS:MESSAGES:2"), message.translate("misc:NOUNS:MESSAGES:5"))}` + })); + } + + setTimeout(function () { + toDelete.delete(); + }, 2000); + } } }