No typescript errors
diff --git a/src/events/channelUpdate.ts b/src/events/channelUpdate.ts
index 9730e17..405734e 100644
--- a/src/events/channelUpdate.ts
+++ b/src/events/channelUpdate.ts
@@ -92,9 +92,9 @@
if ((oldChannel as TextChannel).topic !== (newChannel as TextChannel).topic)
changes.description = entry([(oldChannel as TextChannel).topic ?? "", (newChannel as TextChannel).topic ?? ""], `\nBefore: ${oldTopic}\nAfter: ${newTopic}`);
if ((oldChannel as TextChannel).nsfw !== (newChannel as TextChannel).nsfw) changes.nsfw = entry([(oldChannel as TextChannel).nsfw ? "On" : "Off", (newChannel as TextChannel).nsfw ? "On" : "Off"], `${nsfw[0]} -> ${nsfw[1]}`);
- if ((oldChannel as TextChannel).rateLimitPerUser !== (newChannel as TextChannel).rateLimitPerUser && (oldChannel as TextChannel).rateLimitPerUser !== undefined)
+ if ((oldChannel as TextChannel).rateLimitPerUser !== (newChannel as TextChannel).rateLimitPerUser && (oldChannel as TextChannel).rateLimitPerUser !== 0)
changes.rateLimitPerUser = entry(
- [((oldChannel as TextChannel).rateLimitPerUser ?? 0).toString(), ((newChannel as TextChannel).rateLimitPerUser ?? 0).toString()],
+ [((oldChannel as TextChannel).rateLimitPerUser).toString(), ((newChannel as TextChannel).rateLimitPerUser).toString()],
`${humanizeDuration((oldChannel as TextChannel).rateLimitPerUser * 1000)} -> ${humanizeDuration((newChannel as TextChannel).rateLimitPerUser * 1000)}`
);
@@ -103,7 +103,7 @@
case ChannelType.GuildAnnouncement: {
emoji = "CHANNEL.TEXT.EDIT";
readableType = "Announcement";
- displayName = "Announcment Channel";
+ displayName = "Announcement Channel";
let oldTopic = (oldChannel as TextChannel).topic,
newTopic = (newChannel as TextChannel).topic;
if (oldTopic) {
@@ -138,7 +138,7 @@
if ((oldChannel as VoiceChannel).rtcRegion !== (newChannel as VoiceChannel).rtcRegion)
changes.region = entry(
[(oldChannel as VoiceChannel).rtcRegion ?? "Automatic", (newChannel as VoiceChannel).rtcRegion ?? "Automatic"],
- `${(oldChannel as VoiceChannel).rtcRegion?.toUpperCase() || "Automatic"} -> ${(newChannel as VoiceChannel).rtcRegion?.toUpperCase() || "Automatic"}`
+ `${(oldChannel as VoiceChannel).rtcRegion?.toUpperCase() ?? "Automatic"} -> ${(newChannel as VoiceChannel).rtcRegion?.toUpperCase() ?? "Automatic"}`
);
break;
}
@@ -172,7 +172,7 @@
if ((oldChannel as StageChannel).rtcRegion !== (newChannel as StageChannel).rtcRegion)
changes.region = entry(
[(oldChannel as StageChannel).rtcRegion ?? "Automatic", (newChannel as StageChannel).rtcRegion ?? "Automatic"],
- `${(oldChannel as StageChannel).rtcRegion?.toUpperCase() || "Automatic"} -> ${(newChannel as StageChannel).rtcRegion?.toUpperCase() || "Automatic"}`
+ `${(oldChannel as StageChannel).rtcRegion?.toUpperCase() ?? "Automatic"} -> ${(newChannel as StageChannel).rtcRegion?.toUpperCase() ?? "Automatic"}`
);
break;
}
@@ -188,7 +188,7 @@
displayName = "Channel";
}
}
- let ocType = channelTypeEmoji[oldChannel.type],
+ const ocType = channelTypeEmoji[oldChannel.type],
ncType = channelTypeEmoji[newChannel.type];
if (oldChannel.type !== newChannel.type)
changes.type = entry([ocType!, ncType!], `${ocType!} -> ${readableType}`);
diff --git a/src/events/memberLeave.ts b/src/events/memberLeave.ts
index 936f8c2..e70fb3c 100644
--- a/src/events/memberLeave.ts
+++ b/src/events/memberLeave.ts
@@ -11,7 +11,7 @@
await statsChannelRemove(client, member);
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
const auditLog = (await getAuditLog(member.guild as Guild, AuditLogEvent.MemberKick))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildMember)!.id === member.id)[0]!;
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildMember)!.id === member.id)[0];
let type = "leave";
if (auditLog) {
if (auditLog.executor!.id === client.user!.id) return;
@@ -21,6 +21,7 @@
}
let data;
if (type === "kick") {
+ if (!auditLog) return;
await client.database.history.create("kick", member.guild.id, member.user, auditLog.executor, auditLog.reason);
data = {
meta: {
diff --git a/src/events/stickerCreate.ts b/src/events/stickerCreate.ts
index 7dcaf5a..b341ae9 100644
--- a/src/events/stickerCreate.ts
+++ b/src/events/stickerCreate.ts
@@ -6,7 +6,7 @@
export async function callback(client: NucleusClient, sticker: Sticker) {
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
const auditLog = (await getAuditLog(sticker.guild!, AuditLogEvent.EmojiCreate))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === sticker.id)[0] as GuildAuditLogsEntry;
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === sticker.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
const data = {
meta: {
diff --git a/src/events/stickerDelete.ts b/src/events/stickerDelete.ts
index 3f1b741..ce26a85 100644
--- a/src/events/stickerDelete.ts
+++ b/src/events/stickerDelete.ts
@@ -6,7 +6,7 @@
export async function callback(client: NucleusClient, sticker: Sticker) {
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
const auditLog = (await getAuditLog(sticker.guild!, AuditLogEvent.StickerDelete))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === sticker.id)[0] as GuildAuditLogsEntry;
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === sticker.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
const data = {
meta: {
diff --git a/src/events/stickerUpdate.ts b/src/events/stickerUpdate.ts
index cc11726..ed01b71 100644
--- a/src/events/stickerUpdate.ts
+++ b/src/events/stickerUpdate.ts
@@ -8,7 +8,7 @@
if (oldSticker.name === newSticker.name) return;
const auditLog = (await getAuditLog(newSticker.guild!, AuditLogEvent.StickerUpdate))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === newSticker.id)[0] as GuildAuditLogsEntry;
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === newSticker.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
const changes = {
diff --git a/src/events/threadCreate.ts b/src/events/threadCreate.ts
index 14516b3..6d3225c 100644
--- a/src/events/threadCreate.ts
+++ b/src/events/threadCreate.ts
@@ -7,7 +7,7 @@
export async function callback(client: NucleusClient, thread: ThreadChannel) {
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
const auditLog = (await getAuditLog(thread.guild, AuditLogEvent.ThreadCreate))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === thread.id)[0] as GuildAuditLogsEntry;
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === thread.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
const category = thread.parent
? entry(
diff --git a/src/events/threadDelete.ts b/src/events/threadDelete.ts
index 1957e80..429f63a 100644
--- a/src/events/threadDelete.ts
+++ b/src/events/threadDelete.ts
@@ -7,7 +7,7 @@
export async function callback(client: NucleusClient, thread: ThreadChannel) {
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
const auditLog = (await getAuditLog(thread.guild, AuditLogEvent.ThreadDelete))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === thread.id)[0] as GuildAuditLogsEntry;
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === thread.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
const category = thread.parent
? entry(
diff --git a/src/events/threadUpdate.ts b/src/events/threadUpdate.ts
index bcf73fa..555b17f 100644
--- a/src/events/threadUpdate.ts
+++ b/src/events/threadUpdate.ts
@@ -8,7 +8,7 @@
export async function callback(client: NucleusClient, oldThread: ThreadChannel, newThread: ThreadChannel) {
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
const auditLog = (await getAuditLog(newThread.guild, AuditLogEvent.ThreadUpdate))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === newThread.id)[0] as GuildAuditLogsEntry;
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === newThread.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
const list: Record<string, ReturnType<typeof entry>> = {
threadId: entry(newThread.id, `\`${newThread.id}\``),
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()
},