No typescript errors
diff --git a/src/events/webhookUpdate.ts b/src/events/webhookUpdate.ts
index 21fec73..e5f07dd 100644
--- a/src/events/webhookUpdate.ts
+++ b/src/events/webhookUpdate.ts
@@ -12,17 +12,19 @@
try {
const { getAuditLog, log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger;
const auditCreate = (await getAuditLog(channel.guild, AuditLogEvent.WebhookCreate))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as Webhook)!.id === channel.id)[0] as GuildAuditLogsEntry;
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as Webhook)!.id === channel.id)[0]!;
const auditDelete = (await getAuditLog(channel.guild, AuditLogEvent.WebhookDelete))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as Webhook)!.id === channel.id)[0] as GuildAuditLogsEntry;
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as Webhook)!.id === channel.id)[0];
const auditUpdate = (await getAuditLog(channel.guild, AuditLogEvent.WebhookUpdate))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as Webhook)!.id === channel.id)[0] as GuildAuditLogsEntry;
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as Webhook)!.id === channel.id)[0];
- if (!auditCreate && !auditUpdate && !auditDelete) return;
- let audit = auditCreate;
+ if (!auditUpdate && !auditDelete) return;
let action: "Create" | "Update" | "Delete" = "Create";
let list: Record<string, ReturnType<typeof entry> | string> = {};
- if (auditUpdate && auditUpdate.createdTimestamp > audit.createdTimestamp) {
+ const createTimestamp = auditCreate.createdTimestamp;
+ const deleteTimestamp = auditDelete ? auditDelete.createdTimestamp : 0;
+ const updateTimestamp = auditUpdate ? auditUpdate.createdTimestamp : 0;
+ if (updateTimestamp > createTimestamp && updateTimestamp > deleteTimestamp && auditUpdate) {
const { before, after } = auditUpdate.changes.reduce((acc: accType, change) => {
acc.before[change.key] = change.old?.toString()!;
acc.after[change.key] = change.new?.toString()!;
@@ -46,9 +48,8 @@
);
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 (deleteTimestamp > createTimestamp && deleteTimestamp > updateTimestamp && auditDelete) {
const { before } = auditDelete.changes.reduce((acc: accType, change) => {
acc.before[change.key] = change.old?.toString()!;
acc.after[change.key] = change.new?.toString()!;
@@ -59,17 +60,16 @@
list = {
name: entry(before["name"]!, `${before["name"]}`),
channel: entry(before["channel_id"]!, renderChannel((await client.channels.fetch(before["channel_id"]!)) as GuildChannel)),
- created: entry((auditUpdate.target! as Extract<GuildAuditLogsEntry, {createdTimestamp: number}>).createdTimestamp, renderDelta((auditUpdate.target! as Extract<GuildAuditLogsEntry, {createdTimestamp: number}>).createdTimestamp)),
+ created: entry((auditDelete.target! as Extract<GuildAuditLogsEntry, {createdTimestamp: number}>).createdTimestamp, renderDelta((auditDelete.target! as Extract<GuildAuditLogsEntry, {createdTimestamp: number}>).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)
)
};
- audit = auditDelete;
action = "Delete";
} else {
- const { before } = auditDelete.changes.reduce((acc: accType, change) => {
+ const { before } = auditDelete!.changes.reduce((acc: accType, change) => {
acc.before[change.key] = change.old?.toString()!;
acc.after[change.key] = change.new?.toString()!;
return acc;
@@ -96,7 +96,7 @@
type: "webhook" + action,
displayName: `Webhook ${action}d`,
calculateType: "webhookUpdate",
- color: (NucleusColors as any)[cols[action]],
+ color: NucleusColors[cols[action] as keyof typeof NucleusColors],
emoji: "WEBHOOK." + action.toUpperCase(),
timestamp: new Date().getTime()
},