logging: more cleanup and consistency
This commit is contained in:
parent
2b75ef0ec2
commit
1d891b5932
1 changed files with 228 additions and 228 deletions
|
@ -24,7 +24,7 @@ async function getLoggingChannel(guild) {
|
|||
return guild.channels.get(channelId) ?? guild.threads.get(channelId);
|
||||
}
|
||||
|
||||
function formatNameChange(before, after) {
|
||||
function formatChange(before, after) {
|
||||
const beforeFormatted = before != null ? before : "<no value>";
|
||||
const afterFormatted = after != null ? after : "<no value>";
|
||||
|
||||
|
@ -147,14 +147,6 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
|
||||
for (const [key, value] of Object.entries(isCreate ? after : before)) {
|
||||
switch (key) {
|
||||
case "name": {
|
||||
fields.push({
|
||||
name: "Name",
|
||||
value: `#${value}`,
|
||||
inline: true,
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "type": {
|
||||
const typeName = ChannelTypeNames[value];
|
||||
fields.push({
|
||||
|
@ -213,14 +205,14 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
case "name":
|
||||
fields.push({
|
||||
name: "Name",
|
||||
value: formatNameChange(oldValue, newValue),
|
||||
value: formatChange(oldValue, newValue),
|
||||
inline: true,
|
||||
});
|
||||
break;
|
||||
case "description":
|
||||
fields.push({
|
||||
name: "Description",
|
||||
value: formatNameChange(oldValue, newValue),
|
||||
value: formatChange(oldValue, newValue),
|
||||
inline: true,
|
||||
});
|
||||
break;
|
||||
|
@ -228,8 +220,8 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
const oldIconURL = CDNEndpoints.GUILD_ICON(entry.targetID, oldValue);
|
||||
const newIconURL = CDNEndpoints.GUILD_ICON(entry.targetID, newValue);
|
||||
|
||||
const oldIconFormatted = `[Old](${oldIconURL})`;
|
||||
const newIconFormatted = `[New](${newIconURL})`;
|
||||
const oldIconFormatted = oldValue != null ? `[Old](${oldIconURL})` : "None";
|
||||
const newIconFormatted = newValue != null ? `[New](${newIconURL})` : "None";
|
||||
|
||||
fields.push({
|
||||
name: "Icon",
|
||||
|
@ -237,15 +229,15 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
inline: true,
|
||||
});
|
||||
|
||||
thumbnail = newIconURL;
|
||||
thumbnail = newValue ? newIconURL : null;
|
||||
break;
|
||||
}
|
||||
case "banner_hash": {
|
||||
const oldBannerURL = CDNEndpoints.BANNER(entry.targetID, oldValue);
|
||||
const newBannerURL = CDNEndpoints.BANNER(entry.targetID, newValue);
|
||||
|
||||
const oldBannerFormatted = `[Old](${oldBannerURL})`;
|
||||
const newBannerFormated = `[New](${newBannerURL})`;
|
||||
const oldBannerFormatted = oldValue != null ? `[Old](${oldBannerURL})` : "None";
|
||||
const newBannerFormated = newValue != null ? `[New](${newBannerURL})` : "None";
|
||||
|
||||
fields.push({
|
||||
name: "Banner",
|
||||
|
@ -253,13 +245,17 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
inline: true,
|
||||
});
|
||||
|
||||
image = newBannerFormated;
|
||||
image = newValue ? newBannerURL : null;
|
||||
break;
|
||||
}
|
||||
case "system_channel_id": {
|
||||
fields.push({
|
||||
name: "System Channel",
|
||||
value: `${oldValue ?? "<no value>"} -> ${newValue}`,
|
||||
value: `${
|
||||
oldValue != null
|
||||
? `<#${oldValue}> (${entry.guild.channels.get(oldValue)?.name ?? "<uncached>"})`
|
||||
: "None"
|
||||
} -> <#${newValue}> (${entry.guild.channels.get(newValue)?.name ?? "<uncached>"})`,
|
||||
inline: true,
|
||||
});
|
||||
break;
|
||||
|
@ -293,7 +289,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
|
||||
fields.push({
|
||||
name: "Updated by",
|
||||
value: `<@${entry.user.id}>`,
|
||||
value: `<@${entry.user.id}> (${formatUsername(entry.user)})`,
|
||||
inline: false,
|
||||
});
|
||||
|
||||
|
@ -304,13 +300,13 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
title: `Server updated`,
|
||||
fields,
|
||||
thumbnail:
|
||||
thumbnail != undefined
|
||||
thumbnail != null
|
||||
? {
|
||||
url: thumbnail,
|
||||
}
|
||||
: null,
|
||||
image:
|
||||
image != undefined
|
||||
image != null
|
||||
? {
|
||||
url: image,
|
||||
}
|
||||
|
@ -341,7 +337,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
|
||||
fields.push({
|
||||
name: "Visibility",
|
||||
value: formatNameChange(oldVisibility, newVisibility),
|
||||
value: formatChange(oldVisibility, newVisibility),
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
|
@ -350,7 +346,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
|
||||
fields.push({
|
||||
name: "Updated by",
|
||||
value: `<@${entry.user.id}>`,
|
||||
value: `<@${entry.user.id}> (${formatUsername(entry.user)})`,
|
||||
inline: true,
|
||||
});
|
||||
|
||||
|
@ -364,7 +360,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
embeds: [
|
||||
{
|
||||
color: COLOR_CHANGED,
|
||||
title: `Server Profile updated`,
|
||||
title: `Server Profile Updated`,
|
||||
fields,
|
||||
footer: {
|
||||
text: `Guild ID: ${entry.targetID}`,
|
||||
|
@ -388,7 +384,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
if (oldNickname != newNickname) {
|
||||
fields.push({
|
||||
name: "Nickname",
|
||||
value: formatNameChange(oldNickname, newNickname),
|
||||
value: formatChange(oldNickname, newNickname),
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
|
@ -399,20 +395,31 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
const timeoutDuration = new Date(timeout);
|
||||
|
||||
fields.push({
|
||||
name: isTimedOut ? "Timed out" : "Was timed out until",
|
||||
name: isTimedOut ? "Timed out until" : "Was timed out until",
|
||||
value: `<t:${Math.round(timeoutDuration.getTime() / 1000)}>`,
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
|
||||
let verb = "updated";
|
||||
if (after.bypasses_verification) {
|
||||
verb = "bypassed verification for";
|
||||
} else if (after.communication_disabled_until != null) {
|
||||
verb = "timed out";
|
||||
} else if (before.communication_disabled_until != null) {
|
||||
verb = "cleared timeout for";
|
||||
}
|
||||
|
||||
channel.createMessage({
|
||||
embeds: [
|
||||
{
|
||||
color: COLOR_CHANGED,
|
||||
title: `Member updated`,
|
||||
description: `<@${entry.user.id}> (${formatUsername(entry.user)}) updated member <@${
|
||||
entry.targetID
|
||||
}> (${formatUsername(target)})`,
|
||||
title: `Member Updated`,
|
||||
description: `<@${entry.user.id}> (${formatUsername(entry.user)}) ${verb} ${
|
||||
entry.targetID === entry.user.id
|
||||
? "themselves"
|
||||
: `member <@${entry.targetID}> (${formatUsername(target)})`
|
||||
}`,
|
||||
fields,
|
||||
footer: {
|
||||
text: `User ID: ${entry.targetID}`,
|
||||
|
@ -424,11 +431,11 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
break;
|
||||
}
|
||||
case AuditLogActions.MEMBER_ROLE_UPDATE: {
|
||||
const isAdd = entry.after.$add != null;
|
||||
const isAdd = after.$add != null;
|
||||
const isSelf = entry.user.id === entry.targetID;
|
||||
|
||||
const added = entry.after.$add;
|
||||
const removed = entry.after.$remove;
|
||||
const added = after.$add;
|
||||
const removed = after.$remove;
|
||||
let roles = added ?? removed;
|
||||
|
||||
const addAndRemove = added != null && removed != null;
|
||||
|
@ -436,8 +443,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
|
||||
const plural = roles.length > 1 ? "s" : "";
|
||||
|
||||
channel
|
||||
.createMessage({
|
||||
channel.createMessage({
|
||||
embeds: [
|
||||
{
|
||||
color: addAndRemove ? COLOR_CHANGED : isAdd ? COLOR_ADDED : COLOR_REMOVED,
|
||||
|
@ -473,26 +479,24 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
.catch(() => {});
|
||||
});
|
||||
break;
|
||||
}
|
||||
case AuditLogActions.WEBHOOK_CREATE: {
|
||||
channel
|
||||
.createMessage({
|
||||
channel.createMessage({
|
||||
embeds: [
|
||||
{
|
||||
color: COLOR_ADDED,
|
||||
title: `${entry.after.application_id != null ? "Application " : ""}Webhook Created`,
|
||||
title: `${after.application_id != null ? "Application " : ""}Webhook Created`,
|
||||
description: `<@${entry.user.id}> (${formatUsername(
|
||||
entry.user
|
||||
)}) created webhook \`${entry.after.name.replaceAll("`", "\u02cb")}\` in <#${
|
||||
entry.after.channel_id
|
||||
}> (${entry.guild.channels.get(entry.after.channel_id)?.name ?? "<uncached>"})`,
|
||||
)}) created webhook \`${after.name.replaceAll("`", "\u02cb")}\` in <#${entry.after.channel_id}> (${
|
||||
entry.guild.channels.get(after.channel_id)?.name ?? "<uncached>"
|
||||
})`,
|
||||
fields: [
|
||||
entry.after.application_id != null && {
|
||||
after.application_id != null && {
|
||||
name: "Application ID",
|
||||
value: entry.after.application_id,
|
||||
value: after.application_id,
|
||||
inline: true,
|
||||
},
|
||||
entry.reason != null && {
|
||||
|
@ -504,25 +508,23 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
text: `Webhook ID: ${entry.targetID}`,
|
||||
},
|
||||
thumbnail:
|
||||
entry.after.avatar_hash != null
|
||||
after.avatar_hash != null
|
||||
? {
|
||||
url: `https://cdn.discordapp.com/avatars/${entry.targetID}/${entry.after.avatar_hash}.png?size=4096`,
|
||||
url: `https://cdn.discordapp.com/avatars/${entry.targetID}/${after.avatar_hash}.png?size=4096`,
|
||||
}
|
||||
: null,
|
||||
},
|
||||
],
|
||||
})
|
||||
.catch(() => {});
|
||||
});
|
||||
break;
|
||||
}
|
||||
case AuditLogActions.THREAD_CREATE: {
|
||||
channel
|
||||
.createMessage({
|
||||
channel.createMessage({
|
||||
embeds: [
|
||||
{
|
||||
color: COLOR_ADDED,
|
||||
title: `${entry.after.invitable != null ? "Private " : ""}Thread Created`,
|
||||
description: `<#${entry.targetID}> (${entry.after.name})`,
|
||||
title: `${after.invitable != null ? "Private " : ""}Thread Created`,
|
||||
description: `<#${entry.targetID}> (${after.name})`,
|
||||
timestamp: new Date().toISOString(),
|
||||
fields: [
|
||||
{
|
||||
|
@ -547,17 +549,16 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
.catch(() => {});
|
||||
});
|
||||
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 ?? []);
|
||||
if (after.applied_tags != null) {
|
||||
const newTags = new Set(after.applied_tags);
|
||||
const oldTags = new Set(before.applied_tags ?? []);
|
||||
|
||||
let addedTags = Array.from(newTags.difference(oldTags));
|
||||
let removedTags = Array.from(oldTags.difference(newTags));
|
||||
|
@ -587,34 +588,36 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
tagDiff += "```";
|
||||
}
|
||||
|
||||
channel
|
||||
.createMessage({
|
||||
let verb = "updated";
|
||||
if (before.locked === true && after.locked === false) {
|
||||
verb = "unlocked";
|
||||
} else if (before.locked === false && after.locked === true) {
|
||||
verb = "locked";
|
||||
} else if (before.archived === true && after.archived === false) {
|
||||
verb = "unarchived";
|
||||
} else if (before.archived === false && after.archived === true) {
|
||||
verb = "archived";
|
||||
} else if (before.invitable === false && after.invitable === true) {
|
||||
verb = "enabled mention inviting for";
|
||||
} else if (before.invitable === true && after.invitable === false) {
|
||||
verb = "disabled mention inviting for";
|
||||
}
|
||||
|
||||
channel.createMessage({
|
||||
embeds: [
|
||||
{
|
||||
color: COLOR_CHANGED,
|
||||
title: `${
|
||||
entry.target != null && entry.target instanceof PrivateThreadChannel ? "Private " : ""
|
||||
}Thread Updated`,
|
||||
description: `<#${entry.targetID}>${entry.target?.name != null ? ` (${entry.target.name})` : ""} ${
|
||||
entry.before.locked === true && entry.after.locked === false
|
||||
? "unlocked"
|
||||
: entry.before.locked === false && entry.after.locked === true
|
||||
? "locked"
|
||||
: entry.before.archived === true && entry.after.archived === false
|
||||
? "unarchived"
|
||||
: entry.before.archived === false && entry.after.archived === true
|
||||
? "archived"
|
||||
: entry.before.invitable === false && entry.after.invitable === true
|
||||
? "mention inviting enabled"
|
||||
: entry.before.invitable === true && entry.after.invitable === false
|
||||
? "mention inviting disabled"
|
||||
: "updated"
|
||||
} by <@${entry.user.id}> (${formatUsername(entry.user)})`,
|
||||
description: `<@${entry.user.id}> (${formatUsername(entry.user)}) ${verb} <#${entry.targetID}>${
|
||||
entry.target?.name != null ? ` (${entry.target.name})` : ""
|
||||
}`,
|
||||
timestamp: new Date().toISOString(),
|
||||
fields: [
|
||||
entry.after.name != null && {
|
||||
after.name != null && {
|
||||
name: "Name",
|
||||
value: `\`${entry.before.name}\` -> \`${entry.after.name}\``,
|
||||
value: formatChange(before.name, after.name),
|
||||
inline: true,
|
||||
},
|
||||
entry.target?.parentID != null && {
|
||||
|
@ -647,13 +650,11 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
.catch(() => {});
|
||||
});
|
||||
break;
|
||||
}
|
||||
case AuditLogActions.THREAD_DELETE: {
|
||||
channel
|
||||
.createMessage({
|
||||
channel.createMessage({
|
||||
embeds: [
|
||||
{
|
||||
color: COLOR_REMOVED,
|
||||
|
@ -683,8 +684,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
|||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
.catch(() => {});
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue