From 9dcc211fd969cfd757ad05e3c822c74ac1ebff7c Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Wed, 30 Apr 2025 20:20:48 -0600 Subject: [PATCH] logging: thread tags --- src/modules/logging.js | 54 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/src/modules/logging.js b/src/modules/logging.js index c8cf69c..1cdc7df 100644 --- a/src/modules/logging.js +++ b/src/modules/logging.js @@ -200,6 +200,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) { value: `<#${entry.target.parentID}> (${ entry.guild.channels.get(entry.target.parentID)?.name ?? "" })`, + inline: true, }, ].filter((x) => !!x), footer: { @@ -212,6 +213,41 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) { break; } case AuditLogActions.THREAD_UPDATE: { + const parentChannel = entry.guild.channels.get(entry.target.parentID); + + let tagDiff; + if (entry.after.applied_tags != null) { + const newTags = new Set(entry.after.applied_tags); + const oldTags = new Set(entry.before.applied_tags ?? []); + + let addedTags = Array.from(newTags.difference(oldTags)); + let removedTags = Array.from(oldTags.difference(newTags)); + + if (parentChannel != null) { + addedTags = addedTags.map((id) => { + const tag = parentChannel.availableTags.find((t) => t.id === id); + + return tag != null ? `${tag.emojiName} ${tag.name}` : id; + }); + removedTags = removedTags.map((id) => { + const tag = parentChannel.availableTags.find((t) => t.id === id); + + return tag != null ? `${tag.emojiName} ${tag.name}` : id; + }); + } + + tagDiff = "```diff\n"; + + if (addedTags.length > 0) tagDiff += "+ " + addedTags.join("\n+ "); + + if (removedTags.length > 0) { + if (addedTags.length > 0) tagDiff += "\n"; + tagDiff += "- " + removedTags.join("\n- "); + } + + tagDiff += "```"; + } + channel .createMessage({ embeds: [ @@ -240,20 +276,27 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) { entry.after.name != null && { name: "Name", value: `\`${entry.before.name}\` -> \`${entry.after.name}\``, + inline: true, + }, + entry.target?.parentID != null && { + name: "Parent Channel", + value: `<#${entry.target.parentID}> (${parentChannel?.name ?? ""})`, + inline: true, }, entry.after.auto_archive_duration != null && { name: "Hide After Inactivity", value: `\`${entry.before.auto_archive_duration}\` -> \`${entry.after.auto_archive_duration}\``, + inline: true, }, entry.after.rate_limit_per_user != null && { name: "Slowmode", value: `\`${entry.before.rate_limit_per_user}\` -> \`${entry.after.rate_limit_per_user}\``, + inline: true, }, - entry.target?.parentID != null && { - name: "Parent Channel", - value: `<#${entry.target.parentID}> (${ - entry.guild.channels.get(entry.target.parentID)?.name ?? "" - })`, + tagDiff != null && { + name: "Tags", + value: tagDiff, + inline: false, }, ].filter((x) => !!x), footer: { @@ -285,6 +328,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) { value: `<#${entry.target.parentID}> (${ entry.guild.channels.get(entry.target.parentID)?.name ?? "" })`, + inline: true, }, ].filter((x) => !!x), footer: {