diff --git a/src/modules/logging.js b/src/modules/logging.js index 9b09e2d..0c3d361 100644 --- a/src/modules/logging.js +++ b/src/modules/logging.js @@ -14,7 +14,6 @@ const { const {JoinSourceTypeNames, ChannelTypeNames} = require("#util/constants.js"); const {formatUsername, getDefaultAvatar} = require("#util/misc.js"); const {snowflakeToTimestamp} = require("#util/time.js"); -const {GUILD_ICON, BANNER, CDN_URL} = require("@projectdysnomia/dysnomia/lib/rest/Endpoints.js"); const COLOR_ADDED = 0x399d53; const COLOR_REMOVED = 0xe55152; @@ -29,7 +28,7 @@ function formatNameChange(before, after) { const beforeFormatted = before != null ? before : ""; const afterFormatted = after != null ? after : ""; - return `\`${beforeFormatted}\` > \`${afterFormatted}\``; + return `\`${beforeFormatted}\` -> \`${afterFormatted}\``; } const WHITELISTED_EVENTS = new Set([ @@ -144,9 +143,9 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) { case AuditLogActions.CHANNEL_DELETE: case AuditLogActions.CHANNEL_CREATE: { const fields = []; - const hasCreated = entry.actionType == AuditLogActions.CHANNEL_CREATE; + const isCreate = entry.actionType == AuditLogActions.CHANNEL_CREATE; - for (const [key, value] of Object.entries(hasCreated ? after : before)) { + for (const [key, value] of Object.entries(isCreate ? after : before)) { switch (key) { case "name": { fields.push({ @@ -176,14 +175,20 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) { } } + if (entry.reason != null) + fields.push({ + name: "Reason", + value: `\`${entry.reason.replaceAll("`", "\u02cb")}\``, + }); + channel.createMessage({ embeds: [ { - color: hasCreated ? COLOR_ADDED : COLOR_REMOVED, - title: `Channel ${hasCreated ? "created" : "deleted"}`, - description: `<@${entry.user.id}> (${formatUsername(entry.user)}) ${ - hasCreated ? `created channel <#${entry.targetID}>` : `deleted channel` - }`, + color: isCreate ? COLOR_ADDED : COLOR_REMOVED, + title: `Channel ${isCreate ? "Created" : "Deleted"}`, + description: `<@${entry.user.id}> (${formatUsername(entry.user)}) ${isCreate ? "created" : "deleted"} <#${ + entry.targetID + }>${entry.target != null ? ` (${entry.target.name})` : ""}`, fields, footer: { text: `Channel ID: ${entry.targetID}`, @@ -220,15 +225,15 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) { }); break; case "icon_hash": { - const oldIconURL = new URL(GUILD_ICON(entry.targetID, oldValue), CDN_URL); - const newIconURL = new URL(GUILD_ICON(entry.targetID, newValue), CDN_URL); + const oldIconURL = CDNEndpoints.GUILD_ICON(entry.targetID, oldValue); + const newIconURL = CDNEndpoints.GUILD_ICON(entry.targetID, newValue); const oldIconFormatted = `[Old](${oldIconURL})`; const newIconFormatted = `[New](${newIconURL})`; fields.push({ name: "Icon", - value: `${oldIconFormatted} > ${newIconFormatted}`, + value: `${oldIconFormatted} -> ${newIconFormatted}`, inline: true, }); @@ -236,15 +241,15 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) { break; } case "banner_hash": { - const oldBannerURL = new URL(BANNER(entry.targetID, oldValue), CDN_URL); - const newBannerURL = new URL(BANNER(entry.targetID, newValue), CDN_URL); + const oldBannerURL = CDNEndpoints.BANNER(entry.targetID, oldValue); + const newBannerURL = CDNEndpoints.BANNER(entry.targetID, newValue); const oldBannerFormatted = `[Old](${oldBannerURL})`; - const newBannerFormated = `[Old](${newBannerURL})`; + const newBannerFormated = `[New](${newBannerURL})`; fields.push({ name: "Banner", - value: `${oldBannerFormatted} > ${newBannerFormated}`, + value: `${oldBannerFormatted} -> ${newBannerFormated}`, inline: true, }); @@ -252,19 +257,18 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) { break; } case "system_channel_id": { - // system_channel_id never has a before value, afaik? - // this might be wrong - fields.push({ name: "System Channel", - value: `${newValue}`, + value: `${oldValue ?? ""} -> ${newValue}`, + inline: true, }); break; } case "widget_enabled": { fields.push({ - name: "Widget Enabled", - value: newValue == true ? "Yes" : "No", + name: "Widget", + value: newValue == true ? "Enabled" : "Disabled", + inline: true, }); break; } @@ -272,14 +276,14 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) { fields.push({ name: "Max Members", value: newValue, + inline: true, }); break; } default: { - // 🙏 fields.push({ name: key, - value: `${oldValue} > ${newValue}`, + value: `\`${oldValue}\` -> \`${newValue}\``, inline: true, }); break; @@ -338,6 +342,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) { fields.push({ name: "Visibility", value: formatNameChange(oldVisibility, newVisibility), + inline: true, }); } } @@ -346,9 +351,15 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) { fields.push({ name: "Updated by", value: `<@${entry.user.id}>`, - inline: false, + inline: true, }); + if (entry.reason != null) + fields.push({ + name: "Reason", + value: `\`${entry.reason.replaceAll("`", "\u02cb")}\``, + }); + channel.createMessage({ embeds: [ {