JaBa/commands/Moderation/clear.js

76 lines
2.3 KiB
JavaScript
Raw Normal View History

const Command = require("../../base/Command");
2022-01-04 02:18:28 +05:00
class Clear extends Command {
constructor(client) {
super(client, {
name: "clear",
dirname: __dirname,
enabled: true,
guildOnly: true,
2022-01-05 22:04:46 +05:00
aliases: ["cl", "purge"],
2022-01-04 02:18:28 +05:00
memberPermissions: ["MANAGE_MESSAGES"],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS", "MANAGE_MESSAGES"],
nsfw: false,
ownerOnly: false,
cooldown: 1000
});
}
async run(message, args) {
if (args[0] === "all") {
2022-02-15 01:40:18 +05:00
message.channel.send(message.translate("moderation/clear:ALL_CONFIRM"));
2022-01-04 02:18:28 +05:00
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");
});
2022-02-15 01:40:18 +05:00
2022-01-04 02:18:28 +05:00
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")
});
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
const amount = args[0];
2022-01-04 02:18:28 +05:00
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
2022-01-04 02:18:28 +05:00
});
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) {
2022-02-07 12:45:55 +05:00
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"))}`,
2022-01-04 02:18:28 +05:00
username: user.tag
2022-02-07 12:45:55 +05:00
}));
2022-01-04 02:18:28 +05:00
} else {
2022-02-07 12:45:55 +05:00
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"))}`
2022-02-07 12:45:55 +05:00
}));
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
setTimeout(function () {
toDelete.delete();
}, 2000);
}
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
module.exports = Clear;