Bug fixes and ~~performance~~ typing improvements
diff --git a/src/events/channelCreate.ts b/src/events/channelCreate.ts
index 7350ebd..19f5c9b 100644
--- a/src/events/channelCreate.ts
+++ b/src/events/channelCreate.ts
@@ -1,19 +1,9 @@
export const event = "channelCreate";
export async function callback(client, channel) {
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderChannel
- } = channel.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = channel.client.logger;
const auditLog = await getAuditLog(channel.guild, "CHANNEL_CREATE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === channel.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === channel.id).first();
if (audit.executor.id === client.user.id) return;
let emoji;
let readableType;
@@ -73,10 +63,7 @@
channel.parent ? channel.parent.name : "Uncategorised"
),
createdBy: entry(audit.executor.id, renderUser(audit.executor)),
- created: entry(
- channel.createdTimestamp,
- renderDelta(channel.createdTimestamp)
- )
+ created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp))
},
hidden: {
guild: channel.guild.id
diff --git a/src/events/channelDelete.ts b/src/events/channelDelete.ts
index ee46204..44bbc8e 100644
--- a/src/events/channelDelete.ts
+++ b/src/events/channelDelete.ts
@@ -1,15 +1,22 @@
+import {
+ BaseGuildTextChannel,
+ BaseGuildVoiceChannel,
+ GuildChannel,
+ StageChannel,
+ ThreadChannel,
+ VoiceChannel
+} from "discord.js";
+// @ts-expect-error
+import type { HaikuClient } from "jshaiku";
import getEmojiByName from "../utils/getEmojiByName.js";
export const event = "channelDelete";
-export async function callback(client, channel) {
- const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } =
- channel.client.logger;
+export async function callback(client: HaikuClient, channel: GuildChannel) {
+ const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = client.logger;
const auditLog = await getAuditLog(channel.guild, "CHANNEL_DELETE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === channel.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === channel.id).first();
if (audit.executor.id === client.user.id) return;
let emoji;
@@ -60,27 +67,26 @@
channel.parent ? channel.parent.name : "Uncategorised"
),
nsfw: null,
- created: entry(
- channel.createdTimestamp,
- renderDelta(channel.createdTimestamp)
- ),
+ created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp)),
deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
deletedBy: entry(audit.executor.id, renderUser(audit.executor))
};
- if (channel.topic !== null ?? false)
- list.topic = entry(
- channel.topic,
- `\`\`\`\n${channel.topic.replace("`", "'")}\n\`\`\``
- );
+ if ((channel instanceof BaseGuildTextChannel || channel instanceof StageChannel) && channel.topic !== null)
+ list.topic = entry(channel.topic, `\`\`\`\n${channel.topic.replace("`", "'")}\n\`\`\``);
else delete list.topic;
- if (channel.nsfw !== null ?? false)
+ if (
+ channel instanceof BaseGuildTextChannel ||
+ channel instanceof VoiceChannel ||
+ channel instanceof ThreadChannel
+ ) {
+ const nsfw = channel instanceof ThreadChannel ? (channel as ThreadChannel).parent?.nsfw ?? false : channel.nsfw;
list.nsfw = entry(
- channel.nsfw,
- channel.nsfw
- ? `${getEmojiByName("CONTROL.TICK")} Yes`
- : `${getEmojiByName("CONTROL.CROSS")} No`
+ nsfw,
+ nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
);
- else delete list.nsfw;
+ } else {
+ delete list.nsfw;
+ }
const data = {
meta: {
diff --git a/src/events/channelUpdate.ts b/src/events/channelUpdate.ts
index 6717661..a7af453 100644
--- a/src/events/channelUpdate.ts
+++ b/src/events/channelUpdate.ts
@@ -5,22 +5,12 @@
export async function callback(client, oc, nc) {
const config = await client.memory.readGuildInfo(nc.guild.id);
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderDelta,
- renderUser,
- renderChannel
- } = client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderChannel } = client.logger;
if (nc.parent && nc.parent.id === config.tickets.category) return;
const auditLog = await getAuditLog(nc.guild, "CHANNEL_UPDATE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === nc.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === nc.id).first();
if (audit.executor.id === client.user.id) return;
let emoji: string;
@@ -30,18 +20,11 @@
channelId: entry(nc.id, `\`${nc.id}\``),
channel: entry(nc.id, renderChannel(nc)),
edited: entry(new Date().getTime(), renderDelta(new Date().getTime())),
- editedBy: entry(
- audit.executor.id,
- renderUser((await nc.guild.members.fetch(audit.executor.id)).user)
- )
+ editedBy: entry(audit.executor.id, renderUser((await nc.guild.members.fetch(audit.executor.id)).user))
};
- if (oc.name !== nc.name)
- changes.name = entry([oc.name, nc.name], `${oc.name} -> ${nc.name}`);
+ if (oc.name !== nc.name) changes.name = entry([oc.name, nc.name], `${oc.name} -> ${nc.name}`);
if (oc.position !== nc.position)
- changes.position = entry(
- [oc.position, nc.position],
- `${oc.position} -> ${nc.position}`
- );
+ changes.position = entry([oc.position, nc.position], `${oc.position} -> ${nc.position}`);
switch (nc.type) {
case "GUILD_TEXT": {
@@ -52,45 +35,28 @@
newTopic = nc.topic;
if (oldTopic) {
if (oldTopic.length > 256)
- oldTopic = `\`\`\`\n${
- oldTopic.replace("`", "'").substring(0, 253) + "..."
- }\n\`\`\``;
+ oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
else oldTopic = `\`\`\`\n${oldTopic.replace("`", "'")}\n\`\`\``;
} else {
oldTopic = "None";
}
if (newTopic) {
if (newTopic.length > 256)
- newTopic = `\`\`\`\n${
- newTopic.replace("`", "'").substring(0, 253) + "..."
- }\n\`\`\``;
+ newTopic = `\`\`\`\n${newTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
else newTopic = `\`\`\`\n${newTopic.replace("`", "'")}\n\`\`\``;
} else {
newTopic = "None";
}
const nsfw = ["", ""];
- nsfw[0] = oc.nsfw
- ? `${getEmojiByName("CONTROL.TICK")} Yes`
- : `${getEmojiByName("CONTROL.CROSS")} No`;
- nsfw[1] = nc.nsfw
- ? `${getEmojiByName("CONTROL.TICK")} Yes`
- : `${getEmojiByName("CONTROL.CROSS")} No`;
+ nsfw[0] = oc.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+ nsfw[1] = nc.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
if (oc.topic !== nc.topic)
- changes.description = entry(
- [oc.topic, nc.topic],
- `\nBefore: ${oldTopic}\nAfter: ${newTopic}`
- );
- if (oc.nsfw !== nc.nsfw)
- changes.nsfw = entry(
- [oc.nsfw, nc.nsfw],
- `${nsfw[0]} -> ${nsfw[1]}`
- );
+ changes.description = entry([oc.topic, nc.topic], `\nBefore: ${oldTopic}\nAfter: ${newTopic}`);
+ if (oc.nsfw !== nc.nsfw) changes.nsfw = entry([oc.nsfw, nc.nsfw], `${nsfw[0]} -> ${nsfw[1]}`);
if (oc.rateLimitPerUser !== nc.rateLimitPerUser)
changes.rateLimitPerUser = entry(
[oc.rateLimitPerUser, nc.rateLimitPerUser],
- `${humanizeDuration(
- oc.rateLimitPerUser * 1000
- )} -> ${humanizeDuration(nc.rateLimitPerUser * 1000)}`
+ `${humanizeDuration(oc.rateLimitPerUser * 1000)} -> ${humanizeDuration(nc.rateLimitPerUser * 1000)}`
);
break;
@@ -103,27 +69,20 @@
newTopic = nc.topic;
if (oldTopic) {
if (oldTopic.length > 256)
- oldTopic = `\`\`\`\n${
- oldTopic.replace("`", "'").substring(0, 253) + "..."
- }\n\`\`\``;
+ oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
else oldTopic = `\`\`\`\n${oldTopic.replace("`", "'")}\n\`\`\``;
} else {
oldTopic = "None";
}
if (newTopic) {
if (newTopic.length > 256)
- newTopic = `\`\`\`\n${
- newTopic.replace("`", "'").substring(0, 253) + "..."
- }\n\`\`\``;
+ newTopic = `\`\`\`\n${newTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
else newTopic = `\`\`\`\n${newTopic.replace("`", "'")}\n\`\`\``;
} else {
newTopic = "None";
}
if (oc.nsfw !== nc.nsfw)
- changes.nsfw = entry(
- [oc.nsfw, nc.nsfw],
- `${oc.nsfw ? "On" : "Off"} -> ${nc.nsfw ? "On" : "Off"}`
- );
+ changes.nsfw = entry([oc.nsfw, nc.nsfw], `${oc.nsfw ? "On" : "Off"} -> ${nc.nsfw ? "On" : "Off"}`);
break;
}
case "GUILD_VOICE": {
@@ -131,23 +90,16 @@
readableType = "Voice";
displayName = "Voice Channel";
if (oc.bitrate !== nc.bitrate)
- changes.bitrate = entry(
- [oc.bitrate, nc.bitrate],
- `${oc.bitrate} -> ${nc.bitrate}`
- );
+ changes.bitrate = entry([oc.bitrate, nc.bitrate], `${oc.bitrate} -> ${nc.bitrate}`);
if (oc.userLimit !== nc.userLimit)
changes.maxUsers = entry(
[oc.userLimit, nc.userLimit],
- `${oc.userLimit ? oc.userLimit : "Unlimited"} -> ${
- nc.userLimit
- }`
+ `${oc.userLimit ? oc.userLimit : "Unlimited"} -> ${nc.userLimit}`
);
if (oc.rtcRegion !== nc.rtcRegion)
changes.region = entry(
[oc.rtcRegion, nc.rtcRegion],
- `${oc.rtcRegion || "Automatic"} -> ${
- nc.rtcRegion || "Automatic"
- }`
+ `${oc.rtcRegion || "Automatic"} -> ${nc.rtcRegion || "Automatic"}`
);
break;
}
@@ -159,40 +111,29 @@
newTopic = nc.topic;
if (oldTopic) {
if (oldTopic.length > 256)
- oldTopic = `\`\`\`\n${
- oldTopic.replace("`", "'").substring(0, 253) + "..."
- }\n\`\`\``;
+ oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
else oldTopic = `\`\`\`\n${oldTopic.replace("`", "'")}\n\`\`\``;
} else {
oldTopic = "None";
}
if (newTopic) {
if (newTopic.length > 256)
- newTopic = `\`\`\`\n${
- newTopic.replace("`", "'").substring(0, 253) + "..."
- }\n\`\`\``;
+ newTopic = `\`\`\`\n${newTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
else newTopic = `\`\`\`\n${newTopic.replace("`", "'")}\n\`\`\``;
} else {
newTopic = "None";
}
if (oc.bitrate !== nc.bitrate)
- changes.bitrate = entry(
- [oc.bitrate, nc.bitrate],
- `${oc.bitrate} -> ${nc.bitrate}`
- );
+ changes.bitrate = entry([oc.bitrate, nc.bitrate], `${oc.bitrate} -> ${nc.bitrate}`);
if (oc.userLimit !== nc.userLimit)
changes.maxUsers = entry(
[oc.userLimit, nc.userLimit],
- `${oc.userLimit ? oc.userLimit : "Unlimited"} -> ${
- nc.userLimit
- }`
+ `${oc.userLimit ? oc.userLimit : "Unlimited"} -> ${nc.userLimit}`
);
if (oc.rtcRegion !== nc.rtcRegion)
changes.region = entry(
[oc.rtcRegion, nc.rtcRegion],
- `${oc.rtcRegion || "Automatic"} -> ${
- nc.rtcRegion || "Automatic"
- }`
+ `${oc.rtcRegion || "Automatic"} -> ${nc.rtcRegion || "Automatic"}`
);
break;
}
@@ -210,10 +151,7 @@
}
const t = oc.type.split("_")[1];
if (oc.type !== nc.type)
- changes.type = entry(
- [oc.type, nc.type],
- `${t[0] + t.splice(1).toLowerCase()} -> ${readableType}`
- );
+ changes.type = entry([oc.type, nc.type], `${t[0] + t.splice(1).toLowerCase()} -> ${readableType}`);
if (!(Object.values(changes).length - 4)) return;
const data = {
meta: {
diff --git a/src/events/emojiCreate.ts b/src/events/emojiCreate.ts
index 53f564c..b4e9dfa 100644
--- a/src/events/emojiCreate.ts
+++ b/src/events/emojiCreate.ts
@@ -1,19 +1,9 @@
export const event = "emojiCreate";
export async function callback(client, emoji) {
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderEmoji
- } = emoji.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = emoji.client.logger;
const auditLog = await getAuditLog(emoji.guild, "EMOJI_CREATE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === emoji.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === emoji.id).first();
if (audit.executor.id === client.user.id) return;
const data = {
meta: {
@@ -28,10 +18,7 @@
emojiId: entry(emoji.id, `\`${emoji.id}\``),
emoji: entry(emoji.name, renderEmoji(emoji)),
createdBy: entry(audit.executor.id, renderUser(audit.executor)),
- created: entry(
- emoji.createdTimestamp,
- renderDelta(emoji.createdTimestamp)
- )
+ created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp))
},
hidden: {
guild: emoji.guild.id
diff --git a/src/events/emojiDelete.ts b/src/events/emojiDelete.ts
index 041b432..c4b1535 100644
--- a/src/events/emojiDelete.ts
+++ b/src/events/emojiDelete.ts
@@ -1,19 +1,9 @@
export const event = "emojiDelete";
export async function callback(client, emoji) {
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderEmoji
- } = emoji.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = emoji.client.logger;
const auditLog = await getAuditLog(emoji.guild, "EMOJI_DELETE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === emoji.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === emoji.id).first();
if (audit.executor.id === client.user.id) return;
const data = {
meta: {
@@ -28,14 +18,8 @@
emojiId: entry(emoji.id, `\`${emoji.id}\``),
emoji: entry(emoji.name, renderEmoji(emoji)),
deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
- created: entry(
- emoji.createdTimestamp,
- renderDelta(emoji.createdTimestamp)
- ),
- deleted: entry(
- audit.createdTimestamp,
- renderDelta(audit.createdTimestamp)
- )
+ created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp)),
+ deleted: entry(audit.createdTimestamp, renderDelta(audit.createdTimestamp))
},
hidden: {
guild: emoji.guild.id
diff --git a/src/events/emojiUpdate.ts b/src/events/emojiUpdate.ts
index 34b16de..66227d4 100644
--- a/src/events/emojiUpdate.ts
+++ b/src/events/emojiUpdate.ts
@@ -1,15 +1,7 @@
export const event = "emojiUpdate";
export async function callback(client, oe, ne) {
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderDelta,
- renderUser,
- renderEmoji
- } = client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderEmoji } = client.logger;
if (oe.name === ne.name) return;
const auditLog = await getAuditLog(ne.guild, "EMOJI_UPDATE");
@@ -20,10 +12,7 @@
emojiId: entry(ne.id, `\`${ne.id}\``),
emoji: entry(ne.id, renderEmoji(ne)),
edited: entry(ne.createdTimestamp, renderDelta(ne.createdTimestamp)),
- editedBy: entry(
- audit.executor.id,
- renderUser((await ne.guild.members.fetch(audit.executor.id)).user)
- ),
+ editedBy: entry(audit.executor.id, renderUser((await ne.guild.members.fetch(audit.executor.id)).user)),
name: entry([oe.name, ne.name], `\`:${oe.name}:\` -> \`:${ne.name}:\``)
};
const data = {
diff --git a/src/events/guildBanAdd.ts b/src/events/guildBanAdd.ts
index dd723d3..17c4595 100644
--- a/src/events/guildBanAdd.ts
+++ b/src/events/guildBanAdd.ts
@@ -6,20 +6,11 @@
export async function callback(client, ban) {
await statsChannelRemove(client, ban.user);
purgeByUser(ban.user.id, ban.guild);
- const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } =
- ban.user.client.logger;
+ const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = ban.user.client.logger;
const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_ADD");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === ban.user.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === ban.user.id).first();
if (audit.executor.id === client.user.id) return;
- await client.database.history.create(
- "ban",
- ban.guild.id,
- ban.user,
- audit.executor,
- audit.reason
- );
+ await client.database.history.create("ban", ban.guild.id, ban.user, audit.executor, audit.reason);
const data = {
meta: {
type: "memberBan",
@@ -32,19 +23,10 @@
list: {
memberId: entry(ban.user.id, `\`${ban.user.id}\``),
name: entry(ban.user.id, renderUser(ban.user)),
- banned: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- ),
+ banned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
bannedBy: entry(audit.executor.id, renderUser(audit.executor)),
- reason: entry(
- audit.reason,
- audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"
- ),
- accountCreated: entry(
- ban.user.createdAt,
- renderDelta(ban.user.createdAt)
- ),
+ reason: entry(audit.reason, audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"),
+ accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt)),
serverMemberCount: ban.guild.memberCount
},
hidden: {
diff --git a/src/events/guildBanRemove.ts b/src/events/guildBanRemove.ts
index 4c2263d..74b7c4e 100644
--- a/src/events/guildBanRemove.ts
+++ b/src/events/guildBanRemove.ts
@@ -6,20 +6,11 @@
export async function callback(client, ban) {
await statsChannelRemove(client, ban.user);
purgeByUser(ban.user.id, ban.guild);
- const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } =
- ban.user.client.logger;
+ const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = ban.user.client.logger;
const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_REMOVE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === ban.user.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === ban.user.id).first();
if (audit.executor.id === client.user.id) return;
- await client.database.history.create(
- "unban",
- ban.guild.id,
- ban.user,
- audit.executor,
- audit.reason
- );
+ await client.database.history.create("unban", ban.guild.id, ban.user, audit.executor, audit.reason);
const data = {
meta: {
type: "memberUnban",
@@ -32,15 +23,9 @@
list: {
memberId: entry(ban.user.id, `\`${ban.user.id}\``),
name: entry(ban.user.id, renderUser(ban.user)),
- unbanned: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- ),
+ unbanned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
unbannedBy: entry(audit.executor.id, renderUser(audit.executor)),
- accountCreated: entry(
- ban.user.createdAt,
- renderDelta(ban.user.createdAt)
- )
+ accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt))
},
hidden: {
guild: ban.guild.id
diff --git a/src/events/guildMemberUpdate.ts b/src/events/guildMemberUpdate.ts
index 4cffe69..08730f2 100644
--- a/src/events/guildMemberUpdate.ts
+++ b/src/events/guildMemberUpdate.ts
@@ -2,18 +2,9 @@
export async function callback(client, before, after) {
try {
- const {
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- getAuditLog
- } = after.client.logger;
+ const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = after.client.logger;
const auditLog = await getAuditLog(after.guild, "MEMBER_UPDATE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === after.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === after.id).first();
if (audit.executor.id === client.user.id) return;
if (before.nickname !== after.nickname) {
await client.database.history.create(
@@ -37,22 +28,10 @@
list: {
memberId: entry(after.id, `\`${after.id}\``),
name: entry(after.user.id, renderUser(after.user)),
- before: entry(
- before.nickname,
- before.nickname ? before.nickname : "*None*"
- ),
- after: entry(
- after.nickname,
- after.nickname ? after.nickname : "*None*"
- ),
- changed: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- ),
- changedBy: entry(
- audit.executor.id,
- renderUser(audit.executor)
- )
+ before: entry(before.nickname, before.nickname ? before.nickname : "*None*"),
+ after: entry(after.nickname, after.nickname ? after.nickname : "*None*"),
+ changed: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ changedBy: entry(audit.executor.id, renderUser(audit.executor))
},
hidden: {
guild: after.guild.id
@@ -89,33 +68,20 @@
after.communicationDisabledUntilTimestamp,
renderDelta(after.communicationDisabledUntilTimestamp)
),
- muted: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- ),
- mutedBy: entry(
- audit.executor.id,
- renderUser(audit.executor)
- ),
- reason: entry(
- audit.reason,
- audit.reason ? audit.reason : "\n> *No reason provided*"
- )
+ muted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ mutedBy: entry(audit.executor.id, renderUser(audit.executor)),
+ reason: entry(audit.reason, audit.reason ? audit.reason : "\n> *No reason provided*")
},
hidden: {
guild: after.guild.id
}
};
log(data);
- client.database.eventScheduler.schedule(
- "naturalUnmute",
- after.communicationDisabledUntil,
- {
- guild: after.guild.id,
- user: after.id,
- expires: after.communicationDisabledUntilTimestamp
- }
- );
+ client.database.eventScheduler.schedule("naturalUnmute", after.communicationDisabledUntil, {
+ guild: after.guild.id,
+ user: after.id,
+ expires: after.communicationDisabledUntilTimestamp
+ });
} else if (
after.communicationDisabledUntil === null &&
before.communicationDisabledUntilTimestamp !== null &&
@@ -143,14 +109,8 @@
list: {
memberId: entry(after.id, `\`${after.id}\``),
name: entry(after.user.id, renderUser(after.user)),
- unmuted: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- ),
- unmutedBy: entry(
- audit.executor.id,
- renderUser(audit.executor)
- )
+ unmuted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ unmutedBy: entry(audit.executor.id, renderUser(audit.executor))
},
hidden: {
guild: after.guild.id
diff --git a/src/events/guildUpdate.ts b/src/events/guildUpdate.ts
index 2c87807..a165770 100644
--- a/src/events/guildUpdate.ts
+++ b/src/events/guildUpdate.ts
@@ -4,12 +4,9 @@
export async function callback(client, before, after) {
await statsChannelUpdate(client, after.me);
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } =
- after.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = after.client.logger;
const auditLog = await getAuditLog(after, "GUILD_UPDATE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === after.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === after.id).first();
if (audit.executor.id === client.user.id) return;
const list = {};
@@ -32,16 +29,9 @@
ELEVATED: "Enabled"
};
- if (before.name !== after.name)
- list.name = entry(
- [before.name, after.name],
- `${before.name} -> ${after.name}`
- );
+ if (before.name !== after.name) list.name = entry([before.name, after.name], `${before.name} -> ${after.name}`);
if (before.icon !== after.icon)
- list.icon = entry(
- [before.icon, after.icon],
- `[Before](${before.iconURL()}) -> [After](${after.iconURL()})`
- );
+ list.icon = entry([before.icon, after.icon], `[Before](${before.iconURL()}) -> [After](${after.iconURL()})`);
if (before.splash !== after.splash)
list.splash = entry(
[before.splash, after.splash],
@@ -55,19 +45,12 @@
if (before.owner !== after.owner)
list.owner = entry(
[before.owner, after.owner],
- `${renderUser(before.owner.user)} -> ${renderUser(
- after.owner.user
- )}`
+ `${renderUser(before.owner.user)} -> ${renderUser(after.owner.user)}`
);
if (before.verificationLevel !== after.verificationLevel)
list.verificationLevel = entry(
- [
- verificationLevels[before.verificationLevel],
- verificationLevels[after.verificationLevel]
- ],
- `${verificationLevels[before.verificationLevel]} -> ${
- verificationLevels[after.verificationLevel]
- }`
+ [verificationLevels[before.verificationLevel], verificationLevels[after.verificationLevel]],
+ `${verificationLevels[before.verificationLevel]} -> ${verificationLevels[after.verificationLevel]}`
);
if (before.explicitContentFilter !== after.explicitContentFilter)
list.explicitContentFilter = entry(
@@ -86,10 +69,7 @@
);
if (!Object.keys(list).length) return;
- list.updated = entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- );
+ list.updated = entry(new Date().getTime(), renderDelta(new Date().getTime()));
list.updatedBy = entry(audit.executor.id, renderUser(audit.executor));
const data = {
meta: {
diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts
index 60b90e3..5b0aff1 100644
--- a/src/events/interactionCreate.ts
+++ b/src/events/interactionCreate.ts
@@ -20,25 +20,16 @@
findAllMatches: true,
minMatchCharLength: 0
}).search(typed);
- return fuse
- .slice(0, 25)
- .map((option) => ({ name: option.item, value: option.item }));
+ return fuse.slice(0, 25).map((option) => ({ name: option.item, value: option.item }));
}
function generateStatsChannelAutocomplete(typed) {
- const validReplacements = [
- "serverName",
- "memberCount",
- "memberCount:bots",
- "memberCount:humans"
- ];
+ const validReplacements = ["serverName", "memberCount", "memberCount:bots", "memberCount:humans"];
const autocompletions = [];
const beforeLastOpenBracket = typed.match(/(.*){[^{}]{0,15}$/);
if (beforeLastOpenBracket !== null) {
for (const replacement of validReplacements) {
- autocompletions.push(
- `${beforeLastOpenBracket[1]} {${replacement}}`
- );
+ autocompletions.push(`${beforeLastOpenBracket[1]} {${replacement}}`);
}
} else {
for (const replacement of validReplacements) {
@@ -60,9 +51,7 @@
const beforeLastOpenBracket = typed.match(/(.*){[^{}]{0,15}$/);
if (beforeLastOpenBracket !== null) {
for (const replacement of validReplacements) {
- autocompletions.push(
- `${beforeLastOpenBracket[1]} {${replacement}}`
- );
+ autocompletions.push(`${beforeLastOpenBracket[1]} {${replacement}}`);
}
} else {
for (const replacement of validReplacements) {
@@ -93,32 +82,21 @@
}
} else if (interaction.type === "APPLICATION_COMMAND_AUTOCOMPLETE") {
switch (
- `${
- interaction.commandName
- } ${interaction.options.getSubcommandGroup(
+ `${interaction.commandName} ${interaction.options.getSubcommandGroup(
false
)} ${interaction.options.getSubcommand(false)}`
) {
case "tag null null": {
return interaction.respond(
- getAutocomplete(
- interaction.options.getString("tag"),
- await tagAutocomplete(interaction)
- )
+ getAutocomplete(interaction.options.getString("tag"), await tagAutocomplete(interaction))
);
}
case "settings null stats": {
- return interaction.respond(
- generateStatsChannelAutocomplete(
- interaction.options.getString("name")
- )
- );
+ return interaction.respond(generateStatsChannelAutocomplete(interaction.options.getString("name")));
}
case "settings null welcome": {
return interaction.respond(
- generateWelcomeMessageAutocomplete(
- interaction.options.getString("message")
- )
+ generateWelcomeMessageAutocomplete(interaction.options.getString("message"))
);
}
}
diff --git a/src/events/inviteCreate.ts b/src/events/inviteCreate.ts
index 5461307..7b23bb2 100644
--- a/src/events/inviteCreate.ts
+++ b/src/events/inviteCreate.ts
@@ -2,19 +2,9 @@
export const event = "inviteCreate";
export async function callback(client, invite) {
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderChannel
- } = invite.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = invite.client.logger;
const auditLog = await getAuditLog(invite.guild, "INVITE_CREATE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === invite.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === invite.id).first();
if (audit.executor.id === client.user.id) return;
const data = {
meta: {
@@ -28,15 +18,9 @@
list: {
channel: entry(invite.channel.id, renderChannel(invite.channel)),
link: entry(invite.url, invite.url),
- expires: entry(
- invite.maxAge,
- invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"
- ),
+ expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"),
createdBy: entry(audit.executor.id, renderUser(audit.executor)),
- created: entry(
- invite.createdTimestamp,
- renderDelta(invite.createdTimestamp)
- )
+ created: entry(invite.createdTimestamp, renderDelta(invite.createdTimestamp))
},
hidden: {
guild: invite.guild.id
diff --git a/src/events/inviteDelete.ts b/src/events/inviteDelete.ts
index e5bf241..2cd3bc5 100644
--- a/src/events/inviteDelete.ts
+++ b/src/events/inviteDelete.ts
@@ -2,19 +2,9 @@
export const event = "inviteDelete";
export async function callback(client, invite) {
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderChannel
- } = invite.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = invite.client.logger;
const auditLog = await getAuditLog(invite.guild, "INVITE_DELETE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === invite.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === invite.id).first();
if (audit.executor.id === client.user.id) return;
const data = {
meta: {
@@ -28,15 +18,9 @@
list: {
channel: entry(invite.channel.id, renderChannel(invite.channel)),
link: entry(invite.url, invite.url),
- expires: entry(
- invite.maxAge,
- invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"
- ),
+ expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"),
deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
- deleted: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- )
+ deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
},
hidden: {
guild: invite.guild.id
diff --git a/src/events/memberJoin.ts b/src/events/memberJoin.ts
index ea0b24d..ebc2934 100644
--- a/src/events/memberJoin.ts
+++ b/src/events/memberJoin.ts
@@ -7,15 +7,8 @@
export async function callback(_, member) {
welcome(_, member);
statsChannelAdd(_, member);
- const { log, NucleusColors, entry, renderUser, renderDelta } =
- member.client.logger;
- await client.database.history.create(
- "join",
- member.guild.id,
- member.user,
- null,
- null
- );
+ const { log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger;
+ await client.database.history.create("join", member.guild.id, member.user, null, null);
const data = {
meta: {
type: "memberJoin",
@@ -29,10 +22,7 @@
memberId: entry(member.id, `\`${member.id}\``),
name: entry(member.id, renderUser(member.user)),
joined: entry(member.joinedAt, renderDelta(member.joinedAt)),
- accountCreated: entry(
- member.user.createdAt,
- renderDelta(member.user.createdAt)
- ),
+ accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
serverMemberCount: member.guild.memberCount
},
hidden: {
diff --git a/src/events/memberLeave.ts b/src/events/memberLeave.ts
index d170396..00f6d84 100644
--- a/src/events/memberLeave.ts
+++ b/src/events/memberLeave.ts
@@ -6,12 +6,9 @@
export async function callback(client, member) {
purgeByUser(member.id, member.guild);
await statsChannelRemove(client, member);
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } =
- member.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger;
const auditLog = await getAuditLog(member.guild, "MEMBER_KICK");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === member.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === member.id).first();
let type = "leave";
if (audit) {
if (audit.executor.id === client.user.id) return;
@@ -21,13 +18,7 @@
}
let data;
if (type === "kick") {
- await client.database.history.create(
- "kick",
- member.guild.id,
- member.user,
- audit.executor,
- audit.reason
- );
+ await client.database.history.create("kick", member.guild.id, member.user, audit.executor, audit.reason);
data = {
meta: {
type: "memberKick",
@@ -41,21 +32,10 @@
memberId: entry(member.id, `\`${member.id}\``),
name: entry(member.id, renderUser(member.user)),
joined: entry(member.joinedAt, renderDelta(member.joinedAt)),
- kicked: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- ),
+ kicked: entry(new Date().getTime(), renderDelta(new Date().getTime())),
kickedBy: entry(audit.executor.id, renderUser(audit.executor)),
- reason: entry(
- audit.reason,
- audit.reason
- ? `\n> ${audit.reason}`
- : "*No reason provided.*"
- ),
- accountCreated: entry(
- member.user.createdAt,
- renderDelta(member.user.createdAt)
- ),
+ reason: entry(audit.reason, audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"),
+ accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
serverMemberCount: member.guild.memberCount
},
hidden: {
@@ -63,13 +43,7 @@
}
};
} else {
- await client.database.history.create(
- "leave",
- member.guild.id,
- member.user,
- null,
- null
- );
+ await client.database.history.create("leave", member.guild.id, member.user, null, null);
data = {
meta: {
type: "memberLeave",
@@ -82,18 +56,9 @@
list: {
memberId: entry(member.id, `\`${member.id}\``),
name: entry(member.id, renderUser(member.user)),
- joined: entry(
- member.joinedTimestamp,
- renderDelta(member.joinedAt)
- ),
- left: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- ),
- accountCreated: entry(
- member.user.createdAt,
- renderDelta(member.user.createdAt)
- ),
+ joined: entry(member.joinedTimestamp, renderDelta(member.joinedAt)),
+ left: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
serverMemberCount: member.guild.memberCount
},
hidden: {
diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts
index 7e4a52f..f690885 100644
--- a/src/events/messageCreate.ts
+++ b/src/events/messageCreate.ts
@@ -1,13 +1,6 @@
// @ts-expect-error
import { HaikuClient } from "jshaiku";
-import {
- LinkCheck,
- MalwareCheck,
- NSFWCheck,
- SizeCheck,
- TestString,
- TestImage
-} from "../reflex/scanners.js";
+import { LinkCheck, MalwareCheck, NSFWCheck, SizeCheck, TestString, TestImage } from "../reflex/scanners.js";
import logAttachment from "../premium/attachmentLogs.js";
import createLogException from "../utils/createLogException.js";
import getEmojiByName from "../utils/getEmojiByName.js";
@@ -27,14 +20,7 @@
console.log(e);
}
- const {
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderChannel
- } = client.logger;
+ const { log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
const fileNames = await logAttachment(message);
@@ -43,9 +29,7 @@
const filter = getEmojiByName("ICONS.FILTER");
let attachmentJump = "";
if (config.logging.attachments.saved[message.channel.id + message.id]) {
- attachmentJump = ` [[View attachments]](${
- config.logging.attachments.saved[message.channel.id + message.id]
- })`;
+ attachmentJump = ` [[View attachments]](${config.logging.attachments.saved[message.channel.id + message.id]})`;
}
const list = {
messageId: entry(message.id, `\`${message.id}\``),
@@ -53,10 +37,7 @@
sentIn: entry(message.channel.id, renderChannel(message.channel)),
deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
mentions: message.mentions.users.size,
- attachments: entry(
- message.attachments.size,
- message.attachments.size + attachmentJump
- ),
+ attachments: entry(message.attachments.size, message.attachments.size + attachmentJump),
repliedTo: entry(
message.reference ? message.reference.messageId : null,
message.reference
@@ -66,25 +47,14 @@
};
if (config.filters.invite.enabled) {
- if (
- !config.filters.invite.allowed.channels.includes(message.channel.id)
- ) {
- if (
- /(?:https?:\/\/)?discord(?:app)?\.(?:com\/invite|gg)\/[a-zA-Z0-9]+\/?/.test(
- content
- )
- ) {
- createLogException(
- message.guild.id,
- message.channel.id,
- message.id
- );
+ if (!config.filters.invite.allowed.channels.includes(message.channel.id)) {
+ if (/(?:https?:\/\/)?discord(?:app)?\.(?:com\/invite|gg)\/[a-zA-Z0-9]+\/?/.test(content)) {
+ createLogException(message.guild.id, message.channel.id, message.id);
message.delete();
const data = {
meta: {
type: "messageDelete",
- displayName:
- "Message Deleted (Automated, Contained Invite)",
+ displayName: "Message Deleted (Automated, Contained Invite)",
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
@@ -94,9 +64,7 @@
start:
filter +
" Contained invite\n\n" +
- (content
- ? `**Message:**\n\`\`\`${content}\`\`\``
- : "**Message:** *Message had no content*")
+ (content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*")
},
list: list,
hidden: {
@@ -111,21 +79,13 @@
if (fileNames.files.length > 0) {
for (const element of fileNames.files) {
const url = element.url ? element.url : element.local;
- if (
- /\.(jpg|jpeg|png|gif|gifv|webm|webp|mp4|wav|mp3|ogg)$/.test(url)
- ) {
+ if (/\.(jpg|jpeg|png|gif|gifv|webm|webp|mp4|wav|mp3|ogg)$/.test(url)) {
if (
config.filters.images.NSFW &&
- !(message.channel instanceof ThreadChannel
- ? message.channel.parent?.nsfw
- : message.channel.nsfw)
+ !(message.channel instanceof ThreadChannel ? message.channel.parent?.nsfw : message.channel.nsfw)
) {
if (await NSFWCheck(url)) {
- createLogException(
- message.guild.id,
- message.channel.id,
- message.id
- );
+ createLogException(message.guild.id, message.channel.id, message.id);
await message.delete();
const data = {
meta: {
@@ -160,11 +120,7 @@
config.filters.wordFilter.words.strict
);
if (check !== null) {
- createLogException(
- message.guild.id,
- message.channel.id,
- message.id
- );
+ createLogException(message.guild.id, message.channel.id, message.id);
await message.delete();
const data = {
meta: {
@@ -194,11 +150,7 @@
if (config.filters.images.size) {
if (url.match(/\.+(webp|png|jpg)$/gi)) {
if (!(await SizeCheck(element))) {
- createLogException(
- message.guild.id,
- message.channel.id,
- message.id
- );
+ createLogException(message.guild.id, message.channel.id, message.id);
await message.delete();
const data = {
meta: {
@@ -229,11 +181,7 @@
}
if (config.filters.malware) {
if (!(await MalwareCheck(url))) {
- createLogException(
- message.guild.id,
- message.channel.id,
- message.id
- );
+ createLogException(message.guild.id, message.channel.id, message.id);
await message.delete();
const data = {
meta: {
@@ -280,9 +228,7 @@
start:
filter +
` Link filtered as ${linkDetectionTypes[0]?.toLowerCase()}\n\n` +
- (content
- ? `**Message:**\n\`\`\`${content}\`\`\``
- : "**Message:** *Message had no content*")
+ (content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*")
},
list: list,
hidden: {
@@ -299,11 +245,7 @@
config.filters.wordFilter.words.strict
);
if (check !== null) {
- createLogException(
- message.guild.id,
- message.channel.id,
- message.id
- );
+ createLogException(message.guild.id, message.channel.id, message.id);
await message.delete();
const data = {
meta: {
@@ -318,9 +260,7 @@
start:
filter +
" Message contained filtered word\n\n" +
- (content
- ? `**Message:**\n\`\`\`${content}\`\`\``
- : "**Message:** *Message had no content*")
+ (content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*")
},
list: list,
hidden: {
@@ -342,9 +282,7 @@
timestamp: new Date().getTime()
},
separate: {
- start: content
- ? `**Message:**\n\`\`\`${content}\`\`\``
- : "**Message:** *Message had no content*"
+ start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
},
list: list,
hidden: {
@@ -356,11 +294,7 @@
if (config.filters.pings.roles) {
for (const roleId in message.mentions.roles) {
if (!config.filters.pings.allowed.roles.includes(roleId)) {
- createLogException(
- message.guild.id,
- message.channel.id,
- message.id
- );
+ createLogException(message.guild.id, message.channel.id, message.id);
await message.delete();
const data = {
meta: {
@@ -385,10 +319,7 @@
}
}
}
- if (
- message.mentions.users.size >= config.filters.pings.mass &&
- config.filters.pings.mass
- ) {
+ if (message.mentions.users.size >= config.filters.pings.mass && config.filters.pings.mass) {
createLogException(message.guild.id, message.channel.id, message.id);
await message.delete();
const data = {
@@ -401,9 +332,7 @@
timestamp: new Date().getTime()
},
separate: {
- start: content
- ? `**Message:**\n\`\`\`${content}\`\`\``
- : "**Message:** *Message had no content*"
+ start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
},
list: list,
hidden: {
diff --git a/src/events/messageDelete.ts b/src/events/messageDelete.ts
index 4cdbdb2..3a72876 100644
--- a/src/events/messageDelete.ts
+++ b/src/events/messageDelete.ts
@@ -3,25 +3,11 @@
export async function callback(client, message) {
try {
if (message.author.id === client.user.id) return;
- if (
- client.noLog.includes(
- `${message.guild.id}/${message.channel.id}/${message.id}`
- )
- )
- return;
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderChannel
- } = message.channel.client.logger;
+ if (client.noLog.includes(`${message.guild.id}/${message.channel.id}/${message.id}`)) return;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } =
+ message.channel.client.logger;
const auditLog = await getAuditLog(message.guild, "MEMBER_BAN_ADD");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === message.author.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === message.author.id).first();
if (audit) {
if (audit.createdAt - 100 < new Date().getTime()) return;
}
@@ -37,8 +23,9 @@
) ?? []
).length;
let attachmentJump = "";
- const config = (await client.database.guilds.read(message.guild.id))
- .logging.attachments.saved[message.channel.id + message.id];
+ const config = (await client.database.guilds.read(message.guild.id)).logging.attachments.saved[
+ message.channel.id + message.id
+ ];
if (config) {
attachmentJump = ` [[View attachments]](${config})`;
}
@@ -52,21 +39,13 @@
timestamp: new Date().getTime()
},
separate: {
- start: content
- ? `**Message:**\n\`\`\`${content}\`\`\``
- : "**Message:** *Message had no content*"
+ start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
},
list: {
messageId: entry(message.id, `\`${message.id}\``),
sentBy: entry(message.author.id, renderUser(message.author)),
- sentIn: entry(
- message.channel.id,
- renderChannel(message.channel)
- ),
- deleted: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- ),
+ sentIn: entry(message.channel.id, renderChannel(message.channel)),
+ deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
mentions: message.mentions.users.size,
attachments: entry(attachments, attachments + attachmentJump),
repliedTo: entry(
diff --git a/src/events/messageEdit.ts b/src/events/messageEdit.ts
index c83512c..1470832 100644
--- a/src/events/messageEdit.ts
+++ b/src/events/messageEdit.ts
@@ -2,29 +2,20 @@
export async function callback(client, oldMessage, newMessage) {
if (newMessage.author.id === client.user.id) return;
- const {
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderNumberDelta,
- renderChannel
- } = newMessage.channel.client.logger;
+ const { log, NucleusColors, entry, renderUser, renderDelta, renderNumberDelta, renderChannel } =
+ newMessage.channel.client.logger;
newMessage.reference = newMessage.reference || {};
let newContent = newMessage.cleanContent.replaceAll("`", "‘");
let oldContent = oldMessage.cleanContent.replaceAll("`", "‘");
let attachmentJump = "";
- const config = (await client.database.guilds.read(newMessage.guild.id))
- .logging.attachments.saved[newMessage.channel.id + newMessage.id];
+ const config = (await client.database.guilds.read(newMessage.guild.id)).logging.attachments.saved[
+ newMessage.channel.id + newMessage.id
+ ];
if (config) {
attachmentJump = ` [[View attachments]](${config})`;
}
if (newContent === oldContent) {
- if (
- !oldMessage.flags.has("CROSSPOSTED") &&
- newMessage.flags.has("CROSSPOSTED")
- ) {
+ if (!oldMessage.flags.has("CROSSPOSTED") && newMessage.flags.has("CROSSPOSTED")) {
const data = {
meta: {
type: "messageAnnounce",
@@ -39,14 +30,8 @@
},
list: {
messageId: entry(newMessage.id, `\`${newMessage.id}\``),
- sentBy: entry(
- newMessage.author.id,
- renderUser(newMessage.author)
- ),
- sentIn: entry(
- newMessage.channel.id,
- renderChannel(newMessage.channel)
- ),
+ sentBy: entry(newMessage.author.id, renderUser(newMessage.author)),
+ sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)),
sent: entry(
new Date(newMessage.createdTimestamp),
renderDelta(new Date(newMessage.createdTimestamp))
@@ -55,19 +40,10 @@
new Date(newMessage.editedTimestamp),
renderDelta(new Date(newMessage.editedTimestamp))
),
- mentions: renderNumberDelta(
- oldMessage.mentions.users.size,
- newMessage.mentions.users.size
- ),
+ mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size),
attachments: entry(
- renderNumberDelta(
- oldMessage.attachments.size,
- newMessage.attachments.size
- ),
- renderNumberDelta(
- oldMessage.attachments.size,
- newMessage.attachments.size
- ) + attachmentJump
+ renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size),
+ renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump
)
},
hidden: {
@@ -80,10 +56,8 @@
if (!newMessage.editedTimestamp) {
return;
}
- if (newContent.length > 256)
- newContent = newContent.substring(0, 253) + "...";
- if (oldContent.length > 256)
- oldContent = oldContent.substring(0, 253) + "...";
+ if (newContent.length > 256) newContent = newContent.substring(0, 253) + "...";
+ if (oldContent.length > 256) oldContent = oldContent.substring(0, 253) + "...";
const data = {
meta: {
type: "messageUpdate",
@@ -98,39 +72,19 @@
(oldContent
? `**Before:**\n\`\`\`\n${oldContent}\n\`\`\`\n`
: "**Before:** *Message had no content*\n") +
- (newContent
- ? `**After:**\n\`\`\`\n${newContent}\n\`\`\``
- : "**After:** *Message had no content*"),
+ (newContent ? `**After:**\n\`\`\`\n${newContent}\n\`\`\`` : "**After:** *Message had no content*"),
end: `[[Jump to message]](${newMessage.url})`
},
list: {
messageId: entry(newMessage.id, `\`${newMessage.id}\``),
sentBy: entry(newMessage.author.id, renderUser(newMessage.author)),
- sentIn: entry(
- newMessage.channel.id,
- renderChannel(newMessage.channel)
- ),
- sent: entry(
- new Date(newMessage.createdTimestamp),
- renderDelta(new Date(newMessage.createdTimestamp))
- ),
- edited: entry(
- new Date(newMessage.editedTimestamp),
- renderDelta(new Date(newMessage.editedTimestamp))
- ),
- mentions: renderNumberDelta(
- oldMessage.mentions.users.size,
- newMessage.mentions.users.size
- ),
+ sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)),
+ sent: entry(new Date(newMessage.createdTimestamp), renderDelta(new Date(newMessage.createdTimestamp))),
+ edited: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))),
+ mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size),
attachments: entry(
- renderNumberDelta(
- oldMessage.attachments.size,
- newMessage.attachments.size
- ),
- renderNumberDelta(
- oldMessage.attachments.size,
- newMessage.attachments.size
- ) + attachmentJump
+ renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size),
+ renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump
),
repliedTo: entry(
newMessage.reference.messageId || null,
diff --git a/src/events/roleCreate.ts b/src/events/roleCreate.ts
index f0051a0..f1b0a91 100644
--- a/src/events/roleCreate.ts
+++ b/src/events/roleCreate.ts
@@ -1,20 +1,10 @@
export const event = "roleCreate";
export async function callback(client, role) {
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderRole
- } = role.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderRole } = role.client.logger;
if (role.managed) return;
const auditLog = await getAuditLog(role.guild, "ROLE_CREATE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === role.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === role.id).first();
if (audit.executor.id === client.user.id) return;
const data = {
meta: {
@@ -29,10 +19,7 @@
roleId: entry(role.id, `\`${role.id}\``),
role: entry(role.name, renderRole(role)),
createdBy: entry(audit.executor.id, renderUser(audit.executor)),
- created: entry(
- role.createdTimestamp,
- renderDelta(role.createdTimestamp)
- )
+ created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp))
},
hidden: {
guild: role.guild.id
diff --git a/src/events/roleDelete.ts b/src/events/roleDelete.ts
index 185ea8e..4807e7d 100644
--- a/src/events/roleDelete.ts
+++ b/src/events/roleDelete.ts
@@ -3,13 +3,10 @@
export const event = "roleDelete";
export async function callback(client, role) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } =
- role.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = role.client.logger;
if (role.managed) return;
const auditLog = await getAuditLog(role.guild, "ROLE_DELETE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === role.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === role.id).first();
if (audit.executor.id === client.user.id) return;
const data = {
meta: {
@@ -26,26 +23,16 @@
color: entry(role.hexColor, `\`${role.hexColor}\``),
showInMemberList: entry(
role.hoist,
- role.hoist
- ? `${getEmojiByName("CONTROL.TICK")} Yes`
- : `${getEmojiByName("CONTROL.CROSS")} No`
+ role.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
),
mentionable: entry(
role.mentionable,
- role.mentionable
- ? `${getEmojiByName("CONTROL.TICK")} Yes`
- : `${getEmojiByName("CONTROL.CROSS")} No`
+ role.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
),
members: entry(role.members.size, `${role.members.size}`),
deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
- created: entry(
- role.createdTimestamp,
- renderDelta(role.createdTimestamp)
- ),
- deleted: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- )
+ created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)),
+ deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
},
hidden: {
guild: role.guild.id
diff --git a/src/events/roleUpdate.ts b/src/events/roleUpdate.ts
index be276e5..53bbdee 100644
--- a/src/events/roleUpdate.ts
+++ b/src/events/roleUpdate.ts
@@ -3,15 +3,7 @@
export const event = "roleUpdate";
export async function callback(client, or, nr) {
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderDelta,
- renderUser,
- renderRole
- } = client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderRole } = client.logger;
const auditLog = await getAuditLog(nr.guild, "ROLE_UPDATE");
const audit = auditLog.entries.first();
@@ -21,47 +13,22 @@
roleId: entry(nr.id, `\`${nr.id}\``),
role: entry(nr.id, renderRole(nr)),
edited: entry(new Date().getTime(), renderDelta(new Date().getTime())),
- editedBy: entry(
- audit.executor.id,
- renderUser((await nr.guild.members.fetch(audit.executor.id)).user)
- )
+ editedBy: entry(audit.executor.id, renderUser((await nr.guild.members.fetch(audit.executor.id)).user))
};
const mentionable = ["", ""];
const hoist = ["", ""];
- mentionable[0] = or.mentionable
- ? `${getEmojiByName("CONTROL.TICK")} Yes`
- : `${getEmojiByName("CONTROL.CROSS")} No`;
- mentionable[1] = nr.mentionable
- ? `${getEmojiByName("CONTROL.TICK")} Yes`
- : `${getEmojiByName("CONTROL.CROSS")} No`;
- hoist[0] = or.hoist
- ? `${getEmojiByName("CONTROL.TICK")} Yes`
- : `${getEmojiByName("CONTROL.CROSS")} No`;
- hoist[1] = nr.hoist
- ? `${getEmojiByName("CONTROL.TICK")} Yes`
- : `${getEmojiByName("CONTROL.CROSS")} No`;
- if (or.name !== nr.name)
- changes.name = entry([or.name, nr.name], `${or.name} -> ${nr.name}`);
+ mentionable[0] = or.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+ mentionable[1] = nr.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+ hoist[0] = or.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+ hoist[1] = nr.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+ if (or.name !== nr.name) changes.name = entry([or.name, nr.name], `${or.name} -> ${nr.name}`);
if (or.position !== nr.position)
- changes.position = entry(
- [or.position, nr.position],
- `${or.position} -> ${nr.position}`
- );
- if (or.hoist !== nr.hoist)
- changes.showInMemberList = entry(
- [or.hoist, nr.hoist],
- `${hoist[0]} -> ${hoist[1]}`
- );
+ changes.position = entry([or.position, nr.position], `${or.position} -> ${nr.position}`);
+ if (or.hoist !== nr.hoist) changes.showInMemberList = entry([or.hoist, nr.hoist], `${hoist[0]} -> ${hoist[1]}`);
if (or.mentionable !== nr.mentionable)
- changes.mentionable = entry(
- [or.mentionable, nr.mentionable],
- `${mentionable[0]} -> ${mentionable[1]}`
- );
+ changes.mentionable = entry([or.mentionable, nr.mentionable], `${mentionable[0]} -> ${mentionable[1]}`);
if (or.hexColor !== nr.hexColor)
- changes.color = entry(
- [or.hexColor, nr.hexColor],
- `\`${or.hexColor}\` -> \`${nr.hexColor}\``
- );
+ changes.color = entry([or.hexColor, nr.hexColor], `\`${or.hexColor}\` -> \`${nr.hexColor}\``);
if (Object.keys(changes).length === 4) return;
diff --git a/src/events/stickerCreate.ts b/src/events/stickerCreate.ts
index 54de270..c538bde 100644
--- a/src/events/stickerCreate.ts
+++ b/src/events/stickerCreate.ts
@@ -1,12 +1,9 @@
export const event = "stickerCreate";
export async function callback(client, emoji) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } =
- emoji.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = emoji.client.logger;
const auditLog = await getAuditLog(emoji.guild, "STICKER_CREATE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === emoji.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === emoji.id).first();
if (audit.executor.id === client.user.id) return;
const data = {
meta: {
@@ -21,10 +18,7 @@
stickerId: entry(emoji.id, `\`${emoji.id}\``),
emoji: entry(emoji.name, `\`:${emoji.name}:\``),
createdBy: entry(audit.executor.id, renderUser(audit.executor)),
- created: entry(
- emoji.createdTimestamp,
- renderDelta(emoji.createdTimestamp)
- )
+ created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp))
},
hidden: {
guild: emoji.guild.id
diff --git a/src/events/stickerDelete.ts b/src/events/stickerDelete.ts
index f390b5c..7ac17ce 100644
--- a/src/events/stickerDelete.ts
+++ b/src/events/stickerDelete.ts
@@ -1,12 +1,9 @@
export const event = "stickerDelete";
export async function callback(client, emoji) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } =
- emoji.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = emoji.client.logger;
const auditLog = await getAuditLog(emoji.guild, "STICKER_DELETE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === emoji.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === emoji.id).first();
if (audit.executor.id === client.user.id) return;
const data = {
meta: {
@@ -21,14 +18,8 @@
stickerId: entry(emoji.id, `\`${emoji.id}\``),
sticker: entry(emoji.name, `\`${emoji.name}\``),
deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
- created: entry(
- emoji.createdTimestamp,
- renderDelta(emoji.createdTimestamp)
- ),
- deleted: entry(
- audit.createdTimestamp,
- renderDelta(audit.createdTimestamp)
- )
+ created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp)),
+ deleted: entry(audit.createdTimestamp, renderDelta(audit.createdTimestamp))
},
hidden: {
guild: emoji.guild.id
diff --git a/src/events/stickerUpdate.ts b/src/events/stickerUpdate.ts
index 46c4d17..662f981 100644
--- a/src/events/stickerUpdate.ts
+++ b/src/events/stickerUpdate.ts
@@ -1,8 +1,7 @@
export const event = "stickerUpdate";
export async function callback(client, oe, ne) {
- const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } =
- client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = client.logger;
if (oe.name === ne.name) return;
const auditLog = await getAuditLog(ne.guild, "EMOJI_UPDATE");
@@ -12,10 +11,7 @@
const changes = {
stickerId: entry(ne.id, `\`${ne.id}\``),
edited: entry(ne.createdTimestamp, renderDelta(ne.createdTimestamp)),
- editedBy: entry(
- audit.executor.id,
- renderUser((await ne.guild.members.fetch(audit.executor.id)).user)
- ),
+ editedBy: entry(audit.executor.id, renderUser((await ne.guild.members.fetch(audit.executor.id)).user)),
name: entry([oe.name, ne.name], `\`:${oe.name}:\` -> \`:${ne.name}:\``)
};
const data = {
diff --git a/src/events/threadCreate.ts b/src/events/threadCreate.ts
index 4fdedcb..da3cbae 100644
--- a/src/events/threadCreate.ts
+++ b/src/events/threadCreate.ts
@@ -2,19 +2,9 @@
export const event = "threadCreate";
export async function callback(client, thread) {
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderChannel
- } = thread.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = thread.client.logger;
const auditLog = await getAuditLog(thread.guild, "THREAD_CREATE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === thread.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === thread.id).first();
if (audit.executor.id === client.user.id) return;
const data = {
meta: {
@@ -31,9 +21,7 @@
parentChannel: entry(thread.parentId, renderChannel(thread.parent)),
category: entry(
thread.parent.parent ? thread.parent.parent.name : "None",
- thread.parent.parent
- ? renderChannel(thread.parent.parent)
- : "None"
+ thread.parent.parent ? renderChannel(thread.parent.parent) : "None"
),
autoArchiveDuration: entry(
thread.autoArchiveDuration,
@@ -42,10 +30,7 @@
})
),
createdBy: entry(audit.executor.id, renderUser(audit.executor)),
- created: entry(
- thread.createdTimestamp,
- renderDelta(thread.createdTimestamp)
- )
+ created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp))
},
hidden: {
guild: thread.guild.id
diff --git a/src/events/threadDelete.ts b/src/events/threadDelete.ts
index 0077eff..bfae11a 100644
--- a/src/events/threadDelete.ts
+++ b/src/events/threadDelete.ts
@@ -2,19 +2,9 @@
export const event = "threadDelete";
export async function callback(client, thread) {
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderChannel
- } = thread.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = thread.client.logger;
const auditLog = await getAuditLog(thread.guild, "THREAD_UPDATE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === thread.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === thread.id).first();
if (audit.executor.id === client.user.id) return;
const data = {
meta: {
@@ -31,9 +21,7 @@
parentChannel: entry(thread.parentId, renderChannel(thread.parent)),
category: entry(
thread.parent.parent ? thread.parent.parent.name : "None",
- thread.parent.parent
- ? renderChannel(thread.parent.parent)
- : "None"
+ thread.parent.parent ? renderChannel(thread.parent.parent) : "None"
),
autoArchiveDuration: entry(
thread.autoArchiveDuration,
@@ -43,14 +31,8 @@
),
membersInThread: entry(thread.memberCount, thread.memberCount),
deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
- created: entry(
- thread.createdTimestamp,
- renderDelta(thread.createdTimestamp)
- ),
- deleted: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- )
+ created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp)),
+ deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
},
hidden: {
guild: thread.guild.id
diff --git a/src/events/threadUpdate.ts b/src/events/threadUpdate.ts
index ff36ce0..144dc84 100644
--- a/src/events/threadUpdate.ts
+++ b/src/events/threadUpdate.ts
@@ -2,19 +2,9 @@
export const event = "threadUpdate";
export async function callback(client, before, after) {
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderChannel
- } = after.client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = after.client.logger;
const auditLog = await getAuditLog(after.guild, "THREAD_UPDATE");
- const audit = auditLog.entries
- .filter((entry) => entry.target.id === after.id)
- .first();
+ const audit = auditLog.entries.filter((entry) => entry.target.id === after.id).first();
if (audit.executor.id === client.user.id) return;
const list = {
threadId: entry(after.id, `\`${after.id}\``),
@@ -22,10 +12,7 @@
parentChannel: entry(after.parentId, renderChannel(after.parent))
};
if (before.name !== after.name) {
- list.name = entry(
- [before.name, after.name],
- `${before.name} -> ${after.name}`
- );
+ list.name = entry([before.name, after.name], `${before.name} -> ${after.name}`);
}
if (before.autoArchiveDuration !== after.autoArchiveDuration) {
list.autoArchiveDuration = entry(
@@ -40,16 +27,11 @@
if (before.rateLimitPerUser !== after.rateLimitPerUser) {
list.slowmode = entry(
[before.rateLimitPerUser, after.rateLimitPerUser],
- `${humanizeDuration(
- before.rateLimitPerUser * 1000
- )} -> ${humanizeDuration(after.rateLimitPerUser * 1000)}`
+ `${humanizeDuration(before.rateLimitPerUser * 1000)} -> ${humanizeDuration(after.rateLimitPerUser * 1000)}`
);
}
if (!(Object.keys(list).length - 3)) return;
- list.updated = entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- );
+ list.updated = entry(new Date().getTime(), renderDelta(new Date().getTime()));
list.updatedBy = entry(audit.executor.id, renderUser(audit.executor));
const data = {
meta: {
diff --git a/src/events/webhookUpdate.ts b/src/events/webhookUpdate.ts
index ae88cac..2e95c4b 100644
--- a/src/events/webhookUpdate.ts
+++ b/src/events/webhookUpdate.ts
@@ -3,20 +3,9 @@
import type { HaikuClient } from "jshaiku";
export const event = "webhookUpdate";
-export async function callback(
- client: HaikuClient,
- channel: Discord.GuildChannel
-) {
+export async function callback(client: HaikuClient, channel: Discord.GuildChannel) {
try {
- const {
- getAuditLog,
- log,
- NucleusColors,
- entry,
- renderUser,
- renderChannel,
- renderDelta
- } = client.logger;
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger;
let auditLogCreate = getAuditLog(channel.guild, "WEBHOOK_CREATE");
let auditLogUpdate = getAuditLog(channel.guild, "WEBHOOK_UPDATE");
let auditLogDelete = getAuditLog(channel.guild, "WEBHOOK_DELETE");
@@ -25,15 +14,9 @@
auditLogUpdate,
auditLogDelete
]);
- const auditCreate = auditLogCreate.entries
- .filter((entry) => entry.target.channelId === channel.id)
- .first();
- const auditUpdate = auditLogUpdate.entries
- .filter((entry) => entry.target.channelId === channel.id)
- .first();
- const auditDelete = auditLogDelete.entries
- .filter((entry) => entry.target.channelId === channel.id)
- .first();
+ const auditCreate = auditLogCreate.entries.filter((entry) => entry.target.channelId === channel.id).first();
+ const auditUpdate = auditLogUpdate.entries.filter((entry) => entry.target.channelId === channel.id).first();
+ const auditDelete = auditLogDelete.entries.filter((entry) => entry.target.channelId === channel.id).first();
if (!auditCreate && !auditUpdate && !auditDelete) return;
let audit = auditCreate;
let action = "Create";
@@ -42,10 +25,7 @@
updated: { value: string; displayValue: string };
deleted: { value: string; displayValue: string };
};
- if (
- auditUpdate &&
- auditUpdate.createdTimestamp > audit.createdTimestamp
- ) {
+ if (auditUpdate && auditUpdate.createdTimestamp > audit.createdTimestamp) {
const { before, after } = auditUpdate.changes.reduce(
(acc, change) => {
acc.before[change.key] = change.old;
@@ -55,40 +35,21 @@
{ before: {}, after: {} }
);
if (before.name !== after.name)
- list.name = entry(
- [before.name, after.name],
- `${before.name} -> ${after.name}`
- );
+ list.name = entry([before.name, after.name], `${before.name} -> ${after.name}`);
if (before.channel_id !== after.channel_id)
list.channel = entry(
[before.channel_id, after.channel_id],
- renderChannel(
- await client.channels.fetch(before.channel_id)
- ) +
+ renderChannel(await client.channels.fetch(before.channel_id)) +
" -> " +
- renderChannel(
- await client.channels.fetch(after.channel_id)
- )
+ renderChannel(await client.channels.fetch(after.channel_id))
);
if (!Object.keys(list).length) return;
- list.created = entry(
- auditUpdate.target.createdTimestamp,
- renderDelta(auditUpdate.target.createdTimestamp)
- );
- list.edited = entry(
- after.editedTimestamp,
- renderDelta(new Date().getTime())
- );
- list.editedBy = entry(
- auditUpdate.executor.id,
- renderUser(auditUpdate.executor)
- );
+ list.created = entry(auditUpdate.target.createdTimestamp, renderDelta(auditUpdate.target.createdTimestamp));
+ list.edited = entry(after.editedTimestamp, renderDelta(new Date().getTime()));
+ list.editedBy = entry(auditUpdate.executor.id, renderUser(auditUpdate.executor));
audit = auditUpdate;
action = "Update";
- } else if (
- auditDelete &&
- auditDelete.createdTimestamp > audit.createdTimestamp
- ) {
+ } else if (auditDelete && auditDelete.createdTimestamp > audit.createdTimestamp) {
const { before } = auditDelete.changes.reduce(
(acc, change) => {
acc.before[change.key] = change.old;
@@ -99,29 +60,12 @@
);
list = {
name: entry(before.name, `${before.name}`),
- channel: entry(
- before.channel_id,
- renderChannel(
- await client.channels.fetch(before.channel_id)
- )
- ),
- created: entry(
- auditDelete.target.createdTimestamp,
- renderDelta(auditDelete.target.createdTimestamp)
- ),
- deleted: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- ),
+ channel: entry(before.channel_id, renderChannel(await client.channels.fetch(before.channel_id))),
+ created: entry(auditDelete.target.createdTimestamp, renderDelta(auditDelete.target.createdTimestamp)),
+ deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
deletedBy: entry(
auditDelete.executor.id,
- renderUser(
- (
- await channel.guild.members.fetch(
- auditDelete.executor.id
- )
- ).user
- )
+ renderUser((await channel.guild.members.fetch(auditDelete.executor.id)).user)
)
};
audit = auditDelete;
@@ -137,26 +81,12 @@
);
list = {
name: entry(before.name, `${before.name}`),
- channel: entry(
- before.channel_id,
- renderChannel(
- await client.channels.fetch(before.channel_id)
- )
- ),
+ channel: entry(before.channel_id, renderChannel(await client.channels.fetch(before.channel_id))),
createdBy: entry(
auditCreate.executor.id,
- renderUser(
- (
- await channel.guild.members.fetch(
- auditCreate.executor.id
- )
- ).user
- )
+ renderUser((await channel.guild.members.fetch(auditCreate.executor.id)).user)
),
- created: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- )
+ created: entry(new Date().getTime(), renderDelta(new Date().getTime()))
};
}
const cols = {