From cc380546adb54299945fa2e6541478a773442270 Mon Sep 17 00:00:00 2001 From: Eddie Jaoude Date: Wed, 15 May 2024 12:17:19 +0100 Subject: [PATCH] fix: log updates to admin channel (#798) * fix: log updates to admin channel * fix: null asssertions --- .env.example | 1 + src/events/onUpdate.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/.env.example b/.env.example index 77c48856..025462d2 100644 --- a/.env.example +++ b/.env.example @@ -3,3 +3,4 @@ EDDIEBOT_MONGO_CONNECTION_STRING= DEBUG_HOOK= HOME_GUILD= NODE_ENV="development" +ADMIN_CHANNEL= diff --git a/src/events/onUpdate.ts b/src/events/onUpdate.ts index a1f40956..ecb11712 100644 --- a/src/events/onUpdate.ts +++ b/src/events/onUpdate.ts @@ -28,6 +28,33 @@ export const onUpdate = async ( await checkLinks(bot, newMessage); + // log to admin channel updates + const oldContent = oldMessage.content; + const newContent = newMessage.content; + + if (oldContent !== newContent) { + const logChannel = bot.channels.cache.get(process.env.ADMIN_CHANNEL!); + if (logChannel && logChannel.isTextBased()) { + const logEmbed = new EmbedBuilder() + .setTitle(`Message Updated by "${newMessage.author?.username}"`) + .setDescription(`Message updated in ${newMessage.channel} channel`) + .addFields( + { + name: 'Old Message', + value: oldContent ?? 'No old message available', + }, + { + name: 'New Message', + value: newContent ?? 'No new message available', + }, + { name: 'Author', value: newMessage.author.toString() }, + { name: 'Channel', value: newMessage.channel.toString() }, + ) + .setTimestamp(); + await logChannel.send({ embeds: [logEmbed] }); + } + } + try { const triggeredWarnings: EmbedBuilder[] = []; const cleaned = await sentenceTypoFixer(