fixed events/* (not including webhookUpdate.ts)
diff --git a/src/events/threadUpdate.ts b/src/events/threadUpdate.ts
index 9125fcb..bcf73fa 100644
--- a/src/events/threadUpdate.ts
+++ b/src/events/threadUpdate.ts
@@ -1,44 +1,44 @@
-import type { GuildAuditLogsEntry, ThreadChannel } from "discord.js";
+import { AuditLogEvent, GuildAuditLogsEntry, ThreadChannel } from "discord.js";
// @ts-expect-error
import humanizeDuration from "humanize-duration";
import type { NucleusClient } from "../utils/client.js";
export const event = "threadUpdate";
-export async function callback(client: NucleusClient, before: ThreadChannel, after: ThreadChannel) {
+export async function callback(client: NucleusClient, oldThread: ThreadChannel, newThread: 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: GuildAuditLogsEntry) => entry.target!.id === after.id).first();
- if (audit.executor.id === client.user.id) return;
+ const auditLog = (await getAuditLog(newThread.guild, AuditLogEvent.ThreadUpdate))
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === newThread.id)[0] as GuildAuditLogsEntry;
+ if (auditLog.executor!.id === client.user!.id) return;
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))
+ threadId: entry(newThread.id, `\`${newThread.id}\``),
+ thread: entry(newThread.name, renderChannel(newThread)),
+ parentChannel: entry(newThread.parentId, renderChannel(newThread.parent!))
};
- if (before.name !== after.name) {
- list["name"] = entry([before.name, after.name], `${before.name} -> ${after.name}`);
+ if (oldThread.name !== newThread.name) {
+ list["name"] = entry([oldThread.name, newThread.name], `${oldThread.name} -> ${newThread.name}`);
}
- if (before.autoArchiveDuration !== after.autoArchiveDuration) {
+ if (oldThread.autoArchiveDuration !== newThread.autoArchiveDuration) {
list["autoArchiveDuration"] = entry(
- [before.autoArchiveDuration, after.autoArchiveDuration],
- `${humanizeDuration((before.autoArchiveDuration ?? 0) * 60 * 1000, {
+ [oldThread.autoArchiveDuration!.toString(), newThread.autoArchiveDuration!.toString()],
+ `${humanizeDuration((oldThread.autoArchiveDuration ?? 0) * 60 * 1000, {
round: true
- })} -> ${humanizeDuration((after.autoArchiveDuration ?? 0) * 60 * 1000, {
+ })} -> ${humanizeDuration((newThread.autoArchiveDuration ?? 0) * 60 * 1000, {
round: true
})}`
);
}
- if (before.rateLimitPerUser !== after.rateLimitPerUser) {
+ if (oldThread.rateLimitPerUser !== newThread.rateLimitPerUser) {
list["slowmode"] = entry(
- [before.rateLimitPerUser, after.rateLimitPerUser],
- `${humanizeDuration((before.rateLimitPerUser ?? 0) * 1000)} -> ${humanizeDuration(
- (after.rateLimitPerUser ?? 0) * 1000
+ [oldThread.rateLimitPerUser!.toString(), newThread.rateLimitPerUser!.toString()],
+ `${humanizeDuration((oldThread.rateLimitPerUser ?? 0) * 1000)} -> ${humanizeDuration(
+ (newThread.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["updatedBy"] = entry(auditLog.executor!.id, renderUser(auditLog.executor!));
const data = {
meta: {
type: "channelUpdate",
@@ -50,7 +50,7 @@
},
list: list,
hidden: {
- guild: after.guild.id
+ guild: newThread.guild.id
}
};
log(data);