2021-12-10 21:39:54 +05:00
|
|
|
const Command = require("../../base/Command.js");
|
|
|
|
|
|
|
|
class Clear extends Command {
|
2021-12-26 19:29:37 +05:00
|
|
|
constructor(client) {
|
2021-12-10 21:39:54 +05:00
|
|
|
super(client, {
|
|
|
|
name: "clear",
|
|
|
|
dirname: __dirname,
|
|
|
|
enabled: true,
|
|
|
|
guildOnly: true,
|
2021-12-26 19:29:37 +05:00
|
|
|
aliases: ["clear", "bulkdelete", "purge"],
|
|
|
|
memberPermissions: ["MANAGE_MESSAGES"],
|
|
|
|
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS", "MANAGE_MESSAGES"],
|
2021-12-10 21:39:54 +05:00
|
|
|
nsfw: false,
|
|
|
|
ownerOnly: false,
|
2022-01-01 00:50:09 +05:00
|
|
|
cooldown: 1000
|
2021-12-10 21:39:54 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-26 19:29:37 +05:00
|
|
|
async run(message, args) {
|
2021-12-11 01:11:50 +05:00
|
|
|
if (args[0] === "all") {
|
2021-12-10 21:39:54 +05:00
|
|
|
message.sendT("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 position = message.channel.position;
|
|
|
|
const newChannel = await message.channel.clone();
|
|
|
|
await message.channel.delete();
|
|
|
|
newChannel.setPosition(position);
|
|
|
|
return newChannel.send(message.translate("moderation/clear:CHANNEL_CLEARED"));
|
2021-12-11 01:11:50 +05:00
|
|
|
};
|
2021-12-10 21:39:54 +05:00
|
|
|
|
|
|
|
let amount = args[0];
|
2021-12-11 01:11:50 +05:00
|
|
|
if (!amount || isNaN(amount) || parseInt(amount) < 1) return message.error("moderation/clear:MISSING_AMOUNT");
|
2021-12-10 21:39:54 +05:00
|
|
|
|
|
|
|
await message.delete();
|
|
|
|
|
|
|
|
const user = message.mentions.users.first();
|
|
|
|
|
2021-12-26 19:29:37 +05:00
|
|
|
let messages = await message.channel.messages.fetch({
|
|
|
|
limit: 100
|
|
|
|
});
|
2021-12-10 21:39:54 +05:00
|
|
|
messages = messages.array();
|
2021-12-11 01:11:50 +05:00
|
|
|
if (user) messages = messages.filter((m) => m.author.id === user.id);
|
|
|
|
if (messages.length > amount) messages.length = parseInt(amount, 10);
|
|
|
|
|
2021-12-10 21:39:54 +05:00
|
|
|
messages = messages.filter((m) => !m.pinned);
|
|
|
|
amount++;
|
|
|
|
|
|
|
|
message.channel.bulkDelete(messages, true);
|
|
|
|
|
|
|
|
let toDelete = null;
|
|
|
|
|
2021-12-11 01:11:50 +05:00
|
|
|
if (user) {
|
2021-12-26 19:29:37 +05:00
|
|
|
toDelete = await message.success("moderation/clear:CLEARED_MEMBER", {
|
2022-01-03 01:45:20 +05:00
|
|
|
amount: `${--amount} ${message.getNoun(--amount, message.translate("misc:NOUNS:MESSAGES:1"), message.translate("misc:NOUNS:MESSAGES:2"), message.translate("misc:NOUNS:MESSAGES:5"))}`,
|
2021-12-26 19:29:37 +05:00
|
|
|
username: user.tag
|
|
|
|
});
|
2021-12-10 21:39:54 +05:00
|
|
|
} else {
|
2021-12-26 19:29:37 +05:00
|
|
|
toDelete = await message.success("moderation/clear:CLEARED", {
|
2022-01-03 01:45:20 +05:00
|
|
|
amount: `${--amount} ${message.getNoun(--amount, message.translate("misc:NOUNS:MESSAGES:1"), message.translate("misc:NOUNS:MESSAGES:2"), message.translate("misc:NOUNS:MESSAGES:5"))}`
|
2021-12-26 19:29:37 +05:00
|
|
|
});
|
2021-12-11 01:11:50 +05:00
|
|
|
};
|
2021-12-10 21:39:54 +05:00
|
|
|
|
2021-12-26 19:29:37 +05:00
|
|
|
setTimeout(function () {
|
2021-12-10 21:39:54 +05:00
|
|
|
toDelete.delete();
|
|
|
|
}, 2000);
|
|
|
|
}
|
2021-12-11 01:11:50 +05:00
|
|
|
};
|
2021-12-10 21:39:54 +05:00
|
|
|
|
2021-12-18 20:57:47 +05:00
|
|
|
module.exports = Clear;
|