Improve Logging for moderation (#114)

* Improve Logging for moderation

* Address Review comments

* image logging
This commit is contained in:
Vamsi Krishna 2021-07-07 09:35:19 +05:30 committed by GitHub
parent 6eb3499085
commit c972c62ee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -82,6 +82,8 @@ client.on('messageDelete', message => {
let parent = (message.channel as discord.TextChannel).parent; let parent = (message.channel as discord.TextChannel).parent;
if (parent && IsIgnoredCategory(parent.name) === false) { if (parent && IsIgnoredCategory(parent.name) === false) {
if (message.content && message.content.startsWith('.') === false && message.author?.bot === 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() const deletionEmbed = new discord.MessageEmbed()
.setAuthor(message.author?.tag, message.author?.displayAvatarURL()) .setAuthor(message.author?.tag, message.author?.displayAvatarURL())
.setDescription(`Message deleted in ${message.channel.toString()}`) .setDescription(`Message deleted in ${message.channel.toString()}`)
@ -89,7 +91,11 @@ client.on('messageDelete', message => {
.setTimestamp() .setTimestamp()
.setColor('RED'); .setColor('RED');
state.msglogChannel.send(deletionEmbed); if (messageAttachment) deletionEmbed.setImage(messageAttachment)
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}.`); 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 oldM = oldMessage.cleanContent;
const newM = newMessage.cleanContent; const newM = newMessage.cleanContent;
if (oldMessage.content !== newMessage.content && oldM && newM) { if (oldMessage.content !== newMessage.content && oldM && newM) {
let messageAttachment = oldMessage.attachments.size > 0 ? oldMessage.attachments.array()[0].url : null
const editedEmbed = new discord.MessageEmbed() const editedEmbed = new discord.MessageEmbed()
.setAuthor(oldMessage.author?.tag, oldMessage.author?.displayAvatarURL()) .setAuthor(oldMessage.author?.tag, oldMessage.author?.displayAvatarURL())
.setDescription(`Message edited in ${oldMessage.channel.toString()} [Jump To Message](${newMessage.url})`) .setDescription(`Message edited in ${oldMessage.channel.toString()} [Jump To Message](${newMessage.url})`)
@ -116,7 +124,11 @@ client.on('messageUpdate', (oldMessage, newMessage) => {
.setTimestamp() .setTimestamp()
.setColor('GREEN'); .setColor('GREEN');
state.msglogChannel.send(editedEmbed); if (messageAttachment) editedEmbed.setImage(messageAttachment)
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}.`); logger.info(`${oldMessage.author?.username} ${oldMessage.author} edited message from: ${oldM} to: ${newM}.`);
} }
} }