Compare commits

..

No commits in common. "b1b7d2d09de5d538423db3eae8f0c9e82d9ae2e1" and "3635dc0bfd6c3db776c76356f451e55cd2826765" have entirely different histories.

2 changed files with 8 additions and 308 deletions

View file

@ -4,14 +4,8 @@ const logger = require("#lib/logger.js");
const {getGuildData} = require("#lib/guildData.js"); const {getGuildData} = require("#lib/guildData.js");
const events = require("#lib/events.js"); const events = require("#lib/events.js");
const { const {AuditLogActions, APIEndpoints, CDNEndpoints, GuildIntegrationTypes} = require("#util/dconstants.js");
AuditLogActions, const {JoinSourceTypeNames} = require("#util/constants.js");
APIEndpoints,
CDNEndpoints,
GuildIntegrationTypes,
GuildProfileVisibility,
} = require("#util/dconstants.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");
@ -24,13 +18,6 @@ async function getLoggingChannel(guild) {
return guild.channels.get(channelId) ?? guild.threads.get(channelId); return guild.channels.get(channelId) ?? guild.threads.get(channelId);
} }
function formatNameChange(before, after) {
const beforeFormatted = before != null ? before : "<no value>";
const afterFormatted = after != null ? after : "<no value>";
return `\`${beforeFormatted}\` -> \`${afterFormatted}\``;
}
const WHITELISTED_EVENTS = new Set([ const WHITELISTED_EVENTS = new Set([
"GUILD_UPDATE", "GUILD_UPDATE",
"CHANNEL_CREATE", "CHANNEL_CREATE",
@ -86,17 +73,18 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
if (!channel) return; if (!channel) return;
try { try {
const before = entry.before;
const after = entry.after;
switch (entry.actionType) { switch (entry.actionType) {
case AuditLogActions.GUILD_UPDATE:
case AuditLogActions.CHANNEL_CREATE:
case AuditLogActions.CHANNEL_UPDATE: case AuditLogActions.CHANNEL_UPDATE:
case AuditLogActions.CHANNEL_DELETE:
case AuditLogActions.CHANNEL_OVERWRITE_CREATE: case AuditLogActions.CHANNEL_OVERWRITE_CREATE:
case AuditLogActions.CHANNEL_OVERWRITE_UPDATE: case AuditLogActions.CHANNEL_OVERWRITE_UPDATE:
case AuditLogActions.CHANNEL_OVERWRITE_DELETE: case AuditLogActions.CHANNEL_OVERWRITE_DELETE:
case AuditLogActions.MEMBER_KICK: case AuditLogActions.MEMBER_KICK:
case AuditLogActions.MEMBER_BAN_ADD: case AuditLogActions.MEMBER_BAN_ADD:
case AuditLogActions.MEMBER_BAN_REMOVE: case AuditLogActions.MEMBER_BAN_REMOVE:
case AuditLogActions.MEMBER_UPDATE:
case AuditLogActions.BOT_ADD: case AuditLogActions.BOT_ADD:
case AuditLogActions.ROLE_CREATE: case AuditLogActions.ROLE_CREATE:
case AuditLogActions.ROLE_UPDATE: case AuditLogActions.ROLE_UPDATE:
@ -126,7 +114,8 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
case AuditLogActions.CLYDE_AI_PROFILE_UPDATE: case AuditLogActions.CLYDE_AI_PROFILE_UPDATE:
case AuditLogActions.GUILD_SCHEDULED_EVENT_EXCEPTION_CREATE: case AuditLogActions.GUILD_SCHEDULED_EVENT_EXCEPTION_CREATE:
case AuditLogActions.GUILD_SCHEDULED_EVENT_EXCEPTION_UPDATE: case AuditLogActions.GUILD_SCHEDULED_EVENT_EXCEPTION_UPDATE:
case AuditLogActions.GUILD_SCHEDULED_EVENT_EXCEPTION_DELETE: { case AuditLogActions.GUILD_SCHEDULED_EVENT_EXCEPTION_DELETE:
case AuditLogActions.GUILD_PROFILE_UPDATE: {
channel channel
.createMessage({ .createMessage({
content: Object.entries(AuditLogActions).find(([name, val]) => val === entry.actionType)[0], content: Object.entries(AuditLogActions).find(([name, val]) => val === entry.actionType)[0],
@ -140,289 +129,6 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
.catch(() => {}); .catch(() => {});
break; break;
} }
case AuditLogActions.CHANNEL_DELETE:
case AuditLogActions.CHANNEL_CREATE: {
const fields = [];
const isCreate = entry.actionType == AuditLogActions.CHANNEL_CREATE;
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({
name: "Type",
value: typeName,
inline: true,
});
break;
}
case "nsfw": {
fields.push({
name: "NSFW",
value: value == true ? "Yes" : "No",
inline: true,
});
break;
}
}
}
if (entry.reason != null)
fields.push({
name: "Reason",
value: `\`${entry.reason.replaceAll("`", "\u02cb")}\``,
});
channel.createMessage({
embeds: [
{
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}`,
},
timestamp: new Date().toISOString(),
},
],
});
break;
}
case AuditLogActions.GUILD_UPDATE: {
const fields = [];
let thumbnail;
let image;
for (const [key, newValue] of Object.entries(after)) {
const oldValue = before[key];
switch (key) {
case "name":
fields.push({
name: "Name",
value: formatNameChange(oldValue, newValue),
inline: true,
});
break;
case "description":
fields.push({
name: "Description",
value: formatNameChange(oldValue, newValue),
inline: true,
});
break;
case "icon_hash": {
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}`,
inline: true,
});
thumbnail = newIconURL;
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})`;
fields.push({
name: "Banner",
value: `${oldBannerFormatted} -> ${newBannerFormated}`,
inline: true,
});
image = newBannerFormated;
break;
}
case "system_channel_id": {
fields.push({
name: "System Channel",
value: `${oldValue ?? "<no value>"} -> ${newValue}`,
inline: true,
});
break;
}
case "widget_enabled": {
fields.push({
name: "Widget",
value: newValue == true ? "Enabled" : "Disabled",
inline: true,
});
break;
}
case "max_members": {
fields.push({
name: "Max Members",
value: newValue,
inline: true,
});
break;
}
default: {
fields.push({
name: key,
value: `\`${oldValue}\` -> \`${newValue}\``,
inline: true,
});
break;
}
}
}
fields.push({
name: "Updated by",
value: `<@${entry.user.id}>`,
inline: false,
});
channel.createMessage({
embeds: [
{
color: COLOR_CHANGED,
title: `Server updated`,
fields,
thumbnail:
thumbnail != undefined
? {
url: thumbnail,
}
: null,
image:
image != undefined
? {
url: image,
}
: null,
footer: {
text: `Guild ID: ${entry.targetID}`,
},
timestamp: new Date().toISOString(),
},
],
});
break;
}
case AuditLogActions.GUILD_PROFILE_UPDATE: {
const fields = [];
for (const [key, newValue] of Object.entries(after)) {
const oldValue = before[key];
switch (key) {
case "visibility": {
const newVisibility = GuildProfileVisibility[newValue]
? GuildProfileVisibility[newValue]
: `Unknown ${newValue}`;
const oldVisibility = GuildProfileVisibility[oldValue]
? GuildProfileVisibility[oldValue]
: `Unknown ${oldValue}`;
fields.push({
name: "Visibility",
value: formatNameChange(oldVisibility, newVisibility),
inline: true,
});
}
}
}
fields.push({
name: "Updated by",
value: `<@${entry.user.id}>`,
inline: true,
});
if (entry.reason != null)
fields.push({
name: "Reason",
value: `\`${entry.reason.replaceAll("`", "\u02cb")}\``,
});
channel.createMessage({
embeds: [
{
color: COLOR_CHANGED,
title: `Server Profile updated`,
fields,
footer: {
text: `Guild ID: ${entry.targetID}`,
},
timestamp: new Date().toISOString(),
},
],
});
break;
}
case AuditLogActions.MEMBER_UPDATE: {
const fields = [];
const bot = hf.bot;
const target = bot.users.get(entry.targetID);
const oldNickname = before?.nick;
const newNickname = after?.nick;
const isTimedOut = after?.communication_disabled_until != undefined;
if (oldNickname != newNickname) {
fields.push({
name: "Nickname",
value: formatNameChange(oldNickname, newNickname),
inline: true,
});
}
const timeoutDuration = new Date(
isTimedOut ? after?.communication_disabled_until : before?.communication_disabled_until
);
fields.push({
name: isTimedOut ? "Timed out" : "Was timed out until",
value: `<t:${Math.round(timeoutDuration.getTime() / 1000)}>`,
inline: true,
});
channel.createMessage({
embeds: [
{
color: COLOR_CHANGED,
title: `Member updated`,
description: `<@${entry.user.id}> (${formatUsername(entry.user)}) updated member <@${
entry.targetID
}> (${formatUsername(target)})`,
fields,
footer: {
text: `User ID: ${entry.targetID}`,
},
timestamp: new Date().toISOString(),
},
],
});
break;
}
case AuditLogActions.MEMBER_ROLE_UPDATE: { case AuditLogActions.MEMBER_ROLE_UPDATE: {
const isAdd = entry.after.$add != null; const isAdd = entry.after.$add != null;
const isSelf = entry.user.id === entry.targetID; const isSelf = entry.user.id === entry.targetID;

View file

@ -207,9 +207,3 @@ module.exports.VerificationLevelStrings = [
"(╯°□°)╯︵ ┻━┻ (High)", "(╯°□°)╯︵ ┻━┻ (High)",
"┻━┻ ミヽ(ಠ益ಠ)ノ彡┻━┻ (Very High/Phone)", "┻━┻ ミヽ(ಠ益ಠ)ノ彡┻━┻ (Very High/Phone)",
]; ];
module.exports.GuildProfileVisibility = {
1: "Public",
2: "Restricted",
3: "Public (application-only)",
};