diff --git a/src/modules/moderation.js b/src/modules/moderation.js index e58c8f4..79957d1 100644 --- a/src/modules/moderation.js +++ b/src/modules/moderation.js @@ -19,12 +19,14 @@ tidy.callback = async function (msg, line, [subcommand, count, extra]) { switch (subcommand) { case "all": { - const messages = await msg.channel.getMessages({ - before: msg.id, - limit: count && parseInt(count) > 0 ? parseInt(count) : 10, - }); + 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({ - before: msg.id, - limit: extra && parseInt(extra) > 0 ? parseInt(extra) : 10, - }); + 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({ - before: msg.id, - limit: count && parseInt(count) > 0 ? parseInt(count) : 50, - }); + 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({ - before: msg.id, - limit: extra && parseInt(extra) > 0 ? parseInt(extra) : 10, - }); + 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}"` );