Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
fix: log updates to admin channel (#798)
Browse files Browse the repository at this point in the history
* fix: log updates to admin channel

* fix: null asssertions
  • Loading branch information
eddiejaoude authored May 15, 2024
1 parent cd7081d commit cc38054
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ EDDIEBOT_MONGO_CONNECTION_STRING=
DEBUG_HOOK=
HOME_GUILD=
NODE_ENV="development"
ADMIN_CHANNEL=
27 changes: 27 additions & 0 deletions src/events/onUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!);

Check warning on line 36 in src/events/onUpdate.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion
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(
Expand Down

0 comments on commit cc38054

Please sign in to comment.