moderation.tidy: fix message count

This commit is contained in:
Cynthia Foxwell 2023-11-24 13:37:06 -07:00
parent 99510766d4
commit 0006b5eaa4

View file

@ -19,12 +19,14 @@ tidy.callback = async function (msg, line, [subcommand, count, extra]) {
switch (subcommand) {
case "all": {
const messages = await msg.channel.getMessages({
const messages = await msg.channel
.getMessages({
before: msg.id,
limit: count && parseInt(count) > 0 ? parseInt(count) : 10,
});
})
.then((msgs) => msgs.map((m) => m.id));
await msg.channel.deleteMessages(
messages.map((m) => m.id),
messages,
`Message purge by ${formatUsername(msg.author)}`
);
@ -35,12 +37,16 @@ tidy.callback = async function (msg, line, [subcommand, count, extra]) {
if (typeof user === "string") {
return user;
} else {
const messages = await msg.channel.getMessages({
const messages = await msg.channel
.getMessages({
before: msg.id,
limit: extra && parseInt(extra) > 0 ? parseInt(extra) : 10,
});
})
.then((msgs) =>
msgs.filter((m) => m.author.id == user.id).map((m) => m.id)
);
await msg.channel.deleteMessages(
messages.filter((m) => m.author.id == user.id).map((m) => m.id),
messages,
`Message purge by ${formatUsername(
msg.author
)} targeting ${formatUsername(user)}`
@ -50,12 +56,14 @@ tidy.callback = async function (msg, line, [subcommand, count, extra]) {
}
}
case "bots": {
const messages = await msg.channel.getMessages({
const messages = await msg.channel
.getMessages({
before: msg.id,
limit: count && parseInt(count) > 0 ? parseInt(count) : 50,
});
})
.then((msgs) => msgs.filter((m) => msg.author.bot).map((m) => m.id));
await msg.channel.deleteMessages(
messages.filter((m) => msg.author.bot).map((m) => m.id),
messages,
`Message purge by ${formatUsername(msg.author)} targeting bots`
);
@ -65,12 +73,16 @@ tidy.callback = async function (msg, line, [subcommand, count, extra]) {
if (count.length === 0)
return "Filter must be at least 1 character long.";
const messages = await msg.channel.getMessages({
const messages = await msg.channel
.getMessages({
before: msg.id,
limit: extra && parseInt(extra) > 0 ? parseInt(extra) : 10,
});
})
.then((msgs) =>
msgs.filter((m) => m.content.indexOf(count) > -1).map((m) => m.id)
);
await msg.channel.deleteMessages(
messages.filter((m) => m.content.indexOf(count) > -1).map((m) => m.id),
messages,
`Message purge by ${formatUsername(msg.author)} targeting "${count}"`
);