logging: cleanup
This commit is contained in:
parent
c6cc65b61e
commit
b1b7d2d09d
1 changed files with 36 additions and 25 deletions
|
@ -14,7 +14,6 @@ const {
|
||||||
const {JoinSourceTypeNames, ChannelTypeNames} = require("#util/constants.js");
|
const {JoinSourceTypeNames, ChannelTypeNames} = require("#util/constants.js");
|
||||||
const {formatUsername, getDefaultAvatar} = require("#util/misc.js");
|
const {formatUsername, getDefaultAvatar} = require("#util/misc.js");
|
||||||
const {snowflakeToTimestamp} = require("#util/time.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_ADDED = 0x399d53;
|
||||||
const COLOR_REMOVED = 0xe55152;
|
const COLOR_REMOVED = 0xe55152;
|
||||||
|
@ -29,7 +28,7 @@ function formatNameChange(before, after) {
|
||||||
const beforeFormatted = before != null ? before : "<no value>";
|
const beforeFormatted = before != null ? before : "<no value>";
|
||||||
const afterFormatted = after != null ? after : "<no value>";
|
const afterFormatted = after != null ? after : "<no value>";
|
||||||
|
|
||||||
return `\`${beforeFormatted}\` > \`${afterFormatted}\``;
|
return `\`${beforeFormatted}\` -> \`${afterFormatted}\``;
|
||||||
}
|
}
|
||||||
|
|
||||||
const WHITELISTED_EVENTS = new Set([
|
const WHITELISTED_EVENTS = new Set([
|
||||||
|
@ -144,9 +143,9 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
||||||
case AuditLogActions.CHANNEL_DELETE:
|
case AuditLogActions.CHANNEL_DELETE:
|
||||||
case AuditLogActions.CHANNEL_CREATE: {
|
case AuditLogActions.CHANNEL_CREATE: {
|
||||||
const fields = [];
|
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) {
|
switch (key) {
|
||||||
case "name": {
|
case "name": {
|
||||||
fields.push({
|
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({
|
channel.createMessage({
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
color: hasCreated ? COLOR_ADDED : COLOR_REMOVED,
|
color: isCreate ? COLOR_ADDED : COLOR_REMOVED,
|
||||||
title: `Channel ${hasCreated ? "created" : "deleted"}`,
|
title: `Channel ${isCreate ? "Created" : "Deleted"}`,
|
||||||
description: `<@${entry.user.id}> (${formatUsername(entry.user)}) ${
|
description: `<@${entry.user.id}> (${formatUsername(entry.user)}) ${isCreate ? "created" : "deleted"} <#${
|
||||||
hasCreated ? `created channel <#${entry.targetID}>` : `deleted channel`
|
entry.targetID
|
||||||
}`,
|
}>${entry.target != null ? ` (${entry.target.name})` : ""}`,
|
||||||
fields,
|
fields,
|
||||||
footer: {
|
footer: {
|
||||||
text: `Channel ID: ${entry.targetID}`,
|
text: `Channel ID: ${entry.targetID}`,
|
||||||
|
@ -220,15 +225,15 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "icon_hash": {
|
case "icon_hash": {
|
||||||
const oldIconURL = new URL(GUILD_ICON(entry.targetID, oldValue), CDN_URL);
|
const oldIconURL = CDNEndpoints.GUILD_ICON(entry.targetID, oldValue);
|
||||||
const newIconURL = new URL(GUILD_ICON(entry.targetID, newValue), CDN_URL);
|
const newIconURL = CDNEndpoints.GUILD_ICON(entry.targetID, newValue);
|
||||||
|
|
||||||
const oldIconFormatted = `[Old](${oldIconURL})`;
|
const oldIconFormatted = `[Old](${oldIconURL})`;
|
||||||
const newIconFormatted = `[New](${newIconURL})`;
|
const newIconFormatted = `[New](${newIconURL})`;
|
||||||
|
|
||||||
fields.push({
|
fields.push({
|
||||||
name: "Icon",
|
name: "Icon",
|
||||||
value: `${oldIconFormatted} > ${newIconFormatted}`,
|
value: `${oldIconFormatted} -> ${newIconFormatted}`,
|
||||||
inline: true,
|
inline: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -236,15 +241,15 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "banner_hash": {
|
case "banner_hash": {
|
||||||
const oldBannerURL = new URL(BANNER(entry.targetID, oldValue), CDN_URL);
|
const oldBannerURL = CDNEndpoints.BANNER(entry.targetID, oldValue);
|
||||||
const newBannerURL = new URL(BANNER(entry.targetID, newValue), CDN_URL);
|
const newBannerURL = CDNEndpoints.BANNER(entry.targetID, newValue);
|
||||||
|
|
||||||
const oldBannerFormatted = `[Old](${oldBannerURL})`;
|
const oldBannerFormatted = `[Old](${oldBannerURL})`;
|
||||||
const newBannerFormated = `[Old](${newBannerURL})`;
|
const newBannerFormated = `[New](${newBannerURL})`;
|
||||||
|
|
||||||
fields.push({
|
fields.push({
|
||||||
name: "Banner",
|
name: "Banner",
|
||||||
value: `${oldBannerFormatted} > ${newBannerFormated}`,
|
value: `${oldBannerFormatted} -> ${newBannerFormated}`,
|
||||||
inline: true,
|
inline: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -252,19 +257,18 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "system_channel_id": {
|
case "system_channel_id": {
|
||||||
// system_channel_id never has a before value, afaik?
|
|
||||||
// this might be wrong
|
|
||||||
|
|
||||||
fields.push({
|
fields.push({
|
||||||
name: "System Channel",
|
name: "System Channel",
|
||||||
value: `${newValue}`,
|
value: `${oldValue ?? "<no value>"} -> ${newValue}`,
|
||||||
|
inline: true,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "widget_enabled": {
|
case "widget_enabled": {
|
||||||
fields.push({
|
fields.push({
|
||||||
name: "Widget Enabled",
|
name: "Widget",
|
||||||
value: newValue == true ? "Yes" : "No",
|
value: newValue == true ? "Enabled" : "Disabled",
|
||||||
|
inline: true,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -272,14 +276,14 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
||||||
fields.push({
|
fields.push({
|
||||||
name: "Max Members",
|
name: "Max Members",
|
||||||
value: newValue,
|
value: newValue,
|
||||||
|
inline: true,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
// 🙏
|
|
||||||
fields.push({
|
fields.push({
|
||||||
name: key,
|
name: key,
|
||||||
value: `${oldValue} > ${newValue}`,
|
value: `\`${oldValue}\` -> \`${newValue}\``,
|
||||||
inline: true,
|
inline: true,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -338,6 +342,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
||||||
fields.push({
|
fields.push({
|
||||||
name: "Visibility",
|
name: "Visibility",
|
||||||
value: formatNameChange(oldVisibility, newVisibility),
|
value: formatNameChange(oldVisibility, newVisibility),
|
||||||
|
inline: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -346,9 +351,15 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
||||||
fields.push({
|
fields.push({
|
||||||
name: "Updated by",
|
name: "Updated by",
|
||||||
value: `<@${entry.user.id}>`,
|
value: `<@${entry.user.id}>`,
|
||||||
inline: false,
|
inline: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (entry.reason != null)
|
||||||
|
fields.push({
|
||||||
|
name: "Reason",
|
||||||
|
value: `\`${entry.reason.replaceAll("`", "\u02cb")}\``,
|
||||||
|
});
|
||||||
|
|
||||||
channel.createMessage({
|
channel.createMessage({
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue