Bug fixes and ~~performance~~ typing improvements
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 = {