From db88b94feef7c276f44ff24e3d4b81e04d347a49 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 22 May 2022 19:39:07 +0200 Subject: [PATCH] log bulk deletes in message log --- bot/src/bot/commands/moderation/purge.ts | 8 +++++-- bot/src/bot/modules/mod_logs.ts | 27 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/bot/src/bot/commands/moderation/purge.ts b/bot/src/bot/commands/moderation/purge.ts index 6cc7e0a..66dbb7b 100644 --- a/bot/src/bot/commands/moderation/purge.ts +++ b/bot/src/bot/commands/moderation/purge.ts @@ -85,8 +85,12 @@ export default { .catch(console.error); setTimeout(async () => { - await replyMsg?.delete(); - if (!messages.find(m => m._id == message._id)) await message.delete(); + try { + await message.channel?.deleteMessages([ + replyMsg!._id, + message._id, + ]); + } catch(e) { console.error(e) } }, 6000); } catch(e) { console.error(e); diff --git a/bot/src/bot/modules/mod_logs.ts b/bot/src/bot/modules/mod_logs.ts index 0abe445..c23adcb 100644 --- a/bot/src/bot/modules/mod_logs.ts +++ b/bot/src/bot/modules/mod_logs.ts @@ -106,6 +106,33 @@ client.on('packet', async (packet) => { console.error(e); } } + + if (packet.type == 'BulkMessageDelete') { + const channel = client.channels.get(packet.channel); + if (!channel) return; + + try { + let config = await dbs.SERVERS.findOne({ id: channel.server?._id }); + if (config?.logs?.messageUpdate) { + let embed: LogMessage = { + title: `Bulk delete in in ${channel.server?.name}`, + description: `${packet.ids.length} messages deleted in ` + + `[#${channel.name}](/server/${channel.server_id}/channel/${channel._id})`, + fields: [], + color: '#ff392b', + overrides: { + discord: { + description: `${packet.ids.length} messages deleted in #${channel.name}`, + } + } + } + + await sendLogMessage(config.logs.messageUpdate, embed); + } + } catch(e) { + console.error(e); + } + } }); async function logModAction(type: 'warn'|'kick'|'ban'|'votekick', server: Server, mod: Member, target: string, reason: string|null, infractionID: string, extraText?: string): Promise {