logging: thread tags

This commit is contained in:
Cynthia Foxwell 2025-04-30 20:20:48 -06:00
parent 70dbc62394
commit 9dcc211fd9
Signed by: Cynosphere
SSH key fingerprint: SHA256:H3SM8ufP/uxqLwKSH7xY89TDnbR9uOHzjLoBr0tlajk

View file

@ -200,6 +200,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
value: `<#${entry.target.parentID}> (${
entry.guild.channels.get(entry.target.parentID)?.name ?? "<uncached>"
})`,
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 ?? "<uncached>"})`,
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 ?? "<uncached>"
})`,
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 ?? "<uncached>"
})`,
inline: true,
},
].filter((x) => !!x),
footer: {