From c972c62ee1aee4b8cb48d04761b70caeb5741a5b Mon Sep 17 00:00:00 2001 From: Vamsi Krishna Date: Wed, 7 Jul 2021 09:35:19 +0530 Subject: [PATCH] Improve Logging for moderation (#114) * Improve Logging for moderation * Address Review comments * image logging --- src/server.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/server.ts b/src/server.ts index c2e6dc7..485a9ef 100644 --- a/src/server.ts +++ b/src/server.ts @@ -82,14 +82,20 @@ client.on('messageDelete', message => { let parent = (message.channel as discord.TextChannel).parent; if (parent && IsIgnoredCategory(parent.name) === false) { if (message.content && message.content.startsWith('.') === false && message.author?.bot === false) { + let messageAttachment = message.attachments.size > 0 ? message.attachments.array()[0].url : null + const deletionEmbed = new discord.MessageEmbed() .setAuthor(message.author?.tag, message.author?.displayAvatarURL()) .setDescription(`Message deleted in ${message.channel.toString()}`) .addField('Content', message.cleanContent, false) .setTimestamp() .setColor('RED'); + + if (messageAttachment) deletionEmbed.setImage(messageAttachment) - state.msglogChannel.send(deletionEmbed); + let userInfo = `${message.author?.toString()} (${message.author?.username}) (${message.author})` + + state.msglogChannel.send(userInfo, { embed: deletionEmbed }); logger.info(`${message.author?.username} ${message.author} deleted message: ${message.cleanContent}.`); } } @@ -108,6 +114,8 @@ client.on('messageUpdate', (oldMessage, newMessage) => { const oldM = oldMessage.cleanContent; const newM = newMessage.cleanContent; if (oldMessage.content !== newMessage.content && oldM && newM) { + let messageAttachment = oldMessage.attachments.size > 0 ? oldMessage.attachments.array()[0].url : null + const editedEmbed = new discord.MessageEmbed() .setAuthor(oldMessage.author?.tag, oldMessage.author?.displayAvatarURL()) .setDescription(`Message edited in ${oldMessage.channel.toString()} [Jump To Message](${newMessage.url})`) @@ -115,8 +123,12 @@ client.on('messageUpdate', (oldMessage, newMessage) => { .addField('After', newM, false) .setTimestamp() .setColor('GREEN'); + + if (messageAttachment) editedEmbed.setImage(messageAttachment) - state.msglogChannel.send(editedEmbed); + let userInfo = `${oldMessage.author?.toString()} (${oldMessage.author?.username}) (${oldMessage.author})` + + state.msglogChannel.send(userInfo, { embed: editedEmbed }); logger.info(`${oldMessage.author?.username} ${oldMessage.author} edited message from: ${oldM} to: ${newM}.`); } }