styling fixes and some typing
diff --git a/src/events/channelDelete.ts b/src/events/channelDelete.ts
index d42a12a..e92676d 100644
--- a/src/events/channelDelete.ts
+++ b/src/events/channelDelete.ts
@@ -48,15 +48,15 @@
}
}
const list: {
- channelId: { value: string; displayValue: string };
- name: { value: string; displayValue: string };
- topic?: { value: string; displayValue: string } | null;
- type: { value: string; displayValue: string };
- category: { value: string; displayValue: string };
- nsfw?: { value: string; displayValue: string } | null;
- created: { value: string; displayValue: string };
- deleted: { value: string; displayValue: string };
- deletedBy: { value: string; displayValue: string };
+ channelId: ReturnType<typeof entry>;
+ name: ReturnType<typeof entry>;
+ topic?: ReturnType<typeof entry> | null;
+ type: ReturnType<typeof entry>;
+ category: ReturnType<typeof entry>;
+ nsfw?: ReturnType<typeof entry> | null;
+ created: ReturnType<typeof entry>;
+ deleted: ReturnType<typeof entry>;
+ deletedBy: ReturnType<typeof entry>;
} = {
channelId: entry(channel.id, `\`${channel.id}\``),
name: entry(channel.id, `${channel.name}`),
diff --git a/src/events/threadUpdate.ts b/src/events/threadUpdate.ts
index 144dc84..4df2587 100644
--- a/src/events/threadUpdate.ts
+++ b/src/events/threadUpdate.ts
@@ -1,38 +1,43 @@
+import type { GuildAuditLogsEntry, ThreadChannel } from "discord.js";
+// @ts-expect-error
import humanizeDuration from "humanize-duration";
+// @ts-expect-error
+import type { HaikuClient } from "jshaiku";
+
export const event = "threadUpdate";
-export async function callback(client, before, after) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = after.client.logger;
+export async function callback(client: HaikuClient, before: ThreadChannel, after: ThreadChannel) {
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = 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: GuildAuditLogsEntry) => entry.target!.id === after.id).first();
if (audit.executor.id === client.user.id) return;
- const list = {
+ const list: Record<string, ReturnType<typeof entry>> = {
threadId: entry(after.id, `\`${after.id}\``),
thread: entry(after.name, renderChannel(after)),
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(
+ list["autoArchiveDuration"] = entry(
[before.autoArchiveDuration, after.autoArchiveDuration],
- `${humanizeDuration(before.autoArchiveDuration * 60 * 1000, {
+ `${humanizeDuration((before.autoArchiveDuration ?? 0) * 60 * 1000, {
round: true
- })} -> ${humanizeDuration(after.autoArchiveDuration * 60 * 1000, {
+ })} -> ${humanizeDuration((after.autoArchiveDuration ?? 0) * 60 * 1000, {
round: true
})}`
);
}
if (before.rateLimitPerUser !== after.rateLimitPerUser) {
- list.slowmode = entry(
+ list["slowmode"] = entry(
[before.rateLimitPerUser, after.rateLimitPerUser],
- `${humanizeDuration(before.rateLimitPerUser * 1000)} -> ${humanizeDuration(after.rateLimitPerUser * 1000)}`
+ `${humanizeDuration((before.rateLimitPerUser ?? 0) * 1000)} -> ${humanizeDuration((after.rateLimitPerUser ?? 0) * 1000)}`
);
}
if (!(Object.keys(list).length - 3)) return;
- list.updated = entry(new Date().getTime(), renderDelta(new Date().getTime()));
- list.updatedBy = entry(audit.executor.id, renderUser(audit.executor));
+ list["updated"] = entry(new Date().getTime(), renderDelta(new Date().getTime()));
+ list["updatedBy"] = entry(audit.executor.id, renderUser(audit.executor));
const data = {
meta: {
type: "channelUpdate",
diff --git a/src/events/webhookUpdate.ts b/src/events/webhookUpdate.ts
index 2e95c4b..c58a340 100644
--- a/src/events/webhookUpdate.ts
+++ b/src/events/webhookUpdate.ts
@@ -1,3 +1,4 @@
+import type { GuildAuditLogsEntry, Webhook } from "discord.js";
import type Discord from "discord.js";
// @ts-expect-error
import type { HaikuClient } from "jshaiku";
@@ -14,20 +15,25 @@
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: GuildAuditLogsEntry | null) => {
+ if (entry === null) return false
+ return (entry.target! as Webhook).channelId === channel.id}
+ ).first();
+ const auditUpdate = auditLogUpdate.entries.filter((entry: GuildAuditLogsEntry | null) => {
+ if (entry === null) return false
+ return (entry.target! as Webhook).channelId === channel.id}
+ ).first();
+ const auditDelete = auditLogDelete.entries.filter((entry: GuildAuditLogsEntry | null) => {
+ if (entry === null) return false
+ return (entry.target! as Webhook).channelId === channel.id}
+ ).first();
if (!auditCreate && !auditUpdate && !auditDelete) return;
let audit = auditCreate;
- let action = "Create";
- let list = {} as {
- created: { value: string; displayValue: string };
- updated: { value: string; displayValue: string };
- deleted: { value: string; displayValue: string };
- };
+ let action: "Create" | "Update" | "Delete" = "Create";
+ let list: Record<string, ReturnType<typeof entry> | string> = {};
if (auditUpdate && auditUpdate.createdTimestamp > audit.createdTimestamp) {
const { before, after } = auditUpdate.changes.reduce(
- (acc, change) => {
+ (acc: {before: Record<string, string>, after: Record<string, string>}, change: {key: string, new: string, old: string}) => {
acc.before[change.key] = change.old;
acc.after[change.key] = change.new;
return acc;
@@ -35,23 +41,23 @@
{ 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(
+ list["channel"] = entry(
[before.channel_id, after.channel_id],
renderChannel(await client.channels.fetch(before.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) {
const { before } = auditDelete.changes.reduce(
- (acc, change) => {
+ (acc: {before: Record<string, string>, after: Record<string, string>}, change: {key: string, new: string, old: string}) => {
acc.before[change.key] = change.old;
acc.after[change.key] = change.new;
return acc;
@@ -72,7 +78,7 @@
action = "Delete";
} else {
const { before } = auditDelete.changes.reduce(
- (acc, change) => {
+ (acc: {before: Record<string, string>, after: Record<string, string>}, change: {key: string, new: string, old: string}) => {
acc.before[change.key] = change.old;
acc.after[change.key] = change.new;
return acc;