mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-22 13:14:58 +05:00
Фикс clear all
This commit is contained in:
parent
0afc33e9c3
commit
8718697115
1 changed files with 49 additions and 45 deletions
|
@ -20,56 +20,60 @@ class Clear extends Command {
|
||||||
if (args[0] === "all") {
|
if (args[0] === "all") {
|
||||||
message.channel.send(message.translate("moderation/clear:ALL_CONFIRM"));
|
message.channel.send(message.translate("moderation/clear:ALL_CONFIRM"));
|
||||||
|
|
||||||
await message.channel.awaitMessages((m) => (m.author.id === message.author.id) && (m.content === "confirm"), {
|
const filter = m => m.author.id === message.author.id && m.content === "confirm";
|
||||||
max: 1,
|
const collector = message.channel.createMessageCollector({
|
||||||
time: 20000,
|
filter,
|
||||||
errors: ["time"]
|
time: 120000 // 2 minutes
|
||||||
}).catch(() => {
|
|
||||||
return message.error("misc:TIMES_UP");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const position = message.channel.position;
|
collector.on("collect", async message => {
|
||||||
const newChannel = await message.channel.clone();
|
const position = message.channel.position;
|
||||||
await message.channel.delete();
|
const newChannel = await message.channel.clone();
|
||||||
newChannel.setPosition(position);
|
await message.channel.delete();
|
||||||
return newChannel.send({
|
newChannel.setPosition(position);
|
||||||
content: message.translate("moderation/clear:CHANNEL_CLEARED")
|
return newChannel.send({
|
||||||
|
content: message.translate("moderation/clear:CHANNEL_CLEARED")
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
const amount = args[0];
|
collector.on("end", (_, reason) => {
|
||||||
if (!amount || isNaN(amount) || parseInt(amount) < 1) return message.error("moderation/clear:MISSING_AMOUNT");
|
if (reason === "time") return message.error("misc:TIMES_UP");
|
||||||
|
});
|
||||||
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 {
|
} else {
|
||||||
toDelete = await message.channel.send(message.translate("moderation/clear:CLEARED", {
|
const amount = args[0];
|
||||||
amount: `${amount} ${message.getNoun(amount, message.translate("misc:NOUNS:MESSAGES:1"), message.translate("misc:NOUNS:MESSAGES:2"), message.translate("misc:NOUNS:MESSAGES:5"))}`
|
if (!amount || isNaN(amount) || parseInt(amount) < 1) return message.error("moderation/clear:MISSING_AMOUNT");
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(function () {
|
await message.delete();
|
||||||
toDelete.delete();
|
|
||||||
}, 2000);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue