No typescript errors
diff --git a/src/actions/roleMenu.ts b/src/actions/roleMenu.ts
index 3a01c46..7056fe6 100644
--- a/src/actions/roleMenu.ts
+++ b/src/actions/roleMenu.ts
@@ -1,6 +1,5 @@
import { unknownServerIcon } from './../utils/defaults.js';
import {
- Interaction,
ButtonBuilder,
CommandInteraction,
ButtonStyle,
@@ -8,7 +7,8 @@
StringSelectMenuOptionBuilder,
StringSelectMenuBuilder,
GuildMemberRoleManager,
- Role
+ Role,
+ ContextMenuCommandInteraction
} from "discord.js";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
import { ActionRowBuilder } from "discord.js";
@@ -27,7 +27,7 @@
user: string;
username: string;
data: GuildConfig["roleMenu"]["options"];
- interaction: Interaction;
+ interaction: CommandInteraction | ButtonInteraction | ContextMenuCommandInteraction;
}
export async function callback(interaction: CommandInteraction | ButtonInteraction) {
@@ -95,7 +95,7 @@
user: interaction.member!.user.id,
username: interaction.member!.user.username,
data: config.roleMenu.options,
- interaction: interaction as Interaction
+ interaction: interaction as CommandInteraction | ButtonInteraction
};
}
await interaction.editReply({
diff --git a/src/api/index.ts b/src/api/index.ts
index d0df639..d6d2a5a 100644
--- a/src/api/index.ts
+++ b/src/api/index.ts
@@ -1,3 +1,4 @@
+import type { Guild, GuildMember } from 'discord.js';
import type { NucleusClient } from '../utils/client.js';
//@ts-expect-error
import express from "express";
@@ -12,19 +13,19 @@
const port = 10000;
const runServer = (client: NucleusClient) => {
- app.get("/", (req, res) => {
+ app.get("/", (_req: express.Request, res: express.Response) => {
res.status(200).send(client.ws.ping);
});
- app.post("/verify/:code", jsonParser, async function (req, res) {
+ app.post("/verify/:code", jsonParser, async function (req: express.Request, res: express.Response) {
const code = req.params.code;
const secret = req.body.secret;
if (secret === client.config.verifySecret) {
- const guild = await client.guilds.fetch(client.verify[code]!.gID);
+ const guild = await client.guilds.fetch(client.verify[code]!.gID) as Guild | null;
if (!guild) {
return res.status(404);
}
- const member = await guild.members.fetch(client.verify[code]!.uID);
+ const member = await guild.members.fetch(client.verify[code]!.uID) as GuildMember | null;
if (!member) {
return res.status(404);
}
@@ -34,19 +35,21 @@
await member.roles.add(client.verify[code]!.rID);
const interaction = client.verify[code]!.interaction;
- if (interaction) {
- interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setTitle("Verify")
- .setDescription("Verification complete")
- .setStatus("Success")
- .setEmoji("MEMBER.JOIN")
- ],
- components: []
- });
- }
- client.verify = client.verify.filter((v) => v.code !== code);
+ interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle("Verify")
+ .setDescription("Verification complete")
+ .setStatus("Success")
+ .setEmoji("MEMBER.JOIN")
+ ],
+ components: []
+ });
+ // client.verify.filter((v: VerifySchema) => v.code !== code);
+ // delete the key by creating a new object without the key
+ client.verify = Object.keys(client.verify)
+ .filter((k) => k !== code)
+ .reduce((obj, key) => {return { ...obj, [key]: client.verify[key]}}, {});
const { log, NucleusColors, entry, renderUser } = client.logger;
try {
const data = {
@@ -76,24 +79,22 @@
}
});
- app.get("/verify/:code", jsonParser, function (req, res) {
+ app.get("/verify/:code", jsonParser, function (req: express.Request, res: express.Response) {
const code = req.params.code;
if (client.verify[code]) {
try {
const interaction = client.verify[code]!.interaction;
- if (interaction) {
- interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setTitle("Verify")
- .setDescription(
- "Verify was opened in another tab or window, please complete the CAPTCHA there to continue"
- )
- .setStatus("Success")
- .setEmoji("MEMBER.JOIN")
- ]
- });
- }
+ interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle("Verify")
+ .setDescription(
+ "Verify was opened in another tab or window, please complete the CAPTCHA there to continue"
+ )
+ .setStatus("Success")
+ .setEmoji("MEMBER.JOIN")
+ ]
+ });
} catch {
return res.sendStatus(410);
}
@@ -104,15 +105,15 @@
return res.sendStatus(404);
});
- app.post("/rolemenu/:code", jsonParser, async function (req, res) {
+ app.post("/rolemenu/:code", jsonParser, async function (req: express.Request, res: express.Response) {
const code = req.params.code;
const secret = req.body.secret;
if (secret === client.config.verifySecret) {
- const guild = await client.guilds.fetch(client.roleMenu[code]!.guild);
+ const guild = await client.guilds.fetch(client.roleMenu[code]!.guild) as Guild | null;
if (!guild) {
return res.status(404);
}
- const member = await guild.members.fetch(client.roleMenu[code]!.user);
+ const member = await guild.members.fetch(client.roleMenu[code]!.user) as GuildMember | null;
if (!member) {
return res.status(404);
}
@@ -122,25 +123,23 @@
}
});
- app.get("/rolemenu/:code", jsonParser, function (req, res) {
+ app.get("/rolemenu/:code", jsonParser, function (req: express.Request, res: express.Response) {
const code = req.params.code;
if (client.roleMenu[code] !== undefined) {
try {
const interaction = client.roleMenu[code]!.interaction;
- if (interaction) {
- interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setTitle("Roles")
- .setDescription(
- "The role menu was opened in another tab or window, please select your roles there to continue"
- )
- .setStatus("Success")
- .setEmoji("GUILD.GREEN")
- ],
- components: []
- });
- }
+ interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle("Roles")
+ .setDescription(
+ "The role menu was opened in another tab or window, please select your roles there to continue"
+ )
+ .setStatus("Success")
+ .setEmoji("GUILD.GREEN")
+ ],
+ components: []
+ });
} catch {
return res.sendStatus(410);
}
diff --git a/src/commands/mod/viewas.ts b/src/commands/mod/viewas.ts
index 9c163a7..b176dd4 100644
--- a/src/commands/mod/viewas.ts
+++ b/src/commands/mod/viewas.ts
@@ -91,7 +91,7 @@
const rulesChannel = interaction.guild!.rulesChannel?.id;
async function nameFromChannel(channel: GuildBasedChannel): Promise<string> {
- let channelType = channel.type;
+ let channelType: Discord.ChannelType | 99 = channel.type;
if (channelType === Discord.ChannelType.GuildCategory) return "";
if (channel.id === rulesChannel) channelType = 99
let threads: Discord.ThreadChannel[] = [];
diff --git a/src/commands/settings/logs/events.ts b/src/commands/settings/logs/events.ts
index 6d823b2..fbe79fa 100644
--- a/src/commands/settings/logs/events.ts
+++ b/src/commands/settings/logs/events.ts
@@ -1,11 +1,11 @@
import { LoadingEmbed } from "../../../utils/defaults.js";
import Discord, { CommandInteraction, Message, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, EmbedBuilder, StringSelectMenuInteraction } from "discord.js";
-import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { SlashCommandSubcommandBuilder, StringSelectMenuOptionBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
import client from "../../../utils/client.js";
import { toHexArray, toHexInteger } from "../../../utils/calculate.js";
-const logs = {
+const logs: Record<string, string> = {
channelUpdate: "Channels created, deleted or modified",
emojiUpdate: "Server emojis modified",
stickerUpdate: "Server stickers modified",
@@ -42,6 +42,18 @@
do {
const config = await client.database.guilds.read(interaction.guild!.id);
const converted = toHexArray(config.logging.logs.toLog);
+ const selectPane = new StringSelectMenuBuilder()
+ .setPlaceholder("Set events to log")
+ .setMaxValues(Object.keys(logs).length)
+ .setCustomId("logs")
+ .setMinValues(0)
+ Object.keys(logs).map((e, i) => {
+ selectPane.addOptions(new StringSelectMenuOptionBuilder()
+ .setLabel(logs[e]!)
+ .setValue(i.toString())
+ .setDefault(converted.includes(e))
+ )
+ });
m = (await interaction.editReply({
embeds: [
new EmojiEmbed()
@@ -53,20 +65,7 @@
.setEmoji("CHANNEL.TEXT.CREATE")
],
components: [
- new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
- new StringSelectMenuBuilder()
- .setPlaceholder("Set events to log")
- .setMaxValues(Object.keys(logs).length)
- .setCustomId("logs")
- .setMinValues(0)
- .setOptions(
- Object.keys(logs).map((e, i) => ({
- label: (logs as any)[e],
- value: i.toString(),
- default: converted.includes(e)
- }))
- )
- ]),
+ new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(selectPane),
new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder().setLabel("Select all").setStyle(ButtonStyle.Primary).setCustomId("all"),
new ButtonBuilder().setLabel("Select none").setStyle(ButtonStyle.Danger).setCustomId("none")
diff --git a/src/commands/settings/tickets.ts b/src/commands/settings/tickets.ts
index ff545aa..892a420 100644
--- a/src/commands/settings/tickets.ts
+++ b/src/commands/settings/tickets.ts
@@ -7,7 +7,6 @@
GuildChannel,
Message,
ActionRowBuilder,
- Component,
ButtonBuilder,
MessageComponentInteraction,
StringSelectMenuBuilder,
@@ -74,9 +73,9 @@
})) as Message;
const options = {
enabled: (interaction.options.get("enabled")?.value as string).startsWith("yes") as boolean | null,
- category: interaction.options.get("category")?.channel,
- maxtickets: interaction.options.get("maxticketsperuser")?.value as number,
- supportping: interaction.options.get("supportrole")?.role as Role
+ category: interaction.options.get("category")?.channel as Discord.CategoryChannel | null,
+ maxtickets: interaction.options.get("maxticketsperuser")?.value as number | null,
+ supportping: interaction.options.get("supportrole")?.role as Role | null
};
if (options.enabled !== null || options.category || options.maxtickets || options.supportping) {
if (options.category) {
@@ -94,7 +93,6 @@
]
});
}
- if (!channel) return;
channel = channel as Discord.CategoryChannel;
if (channel.guild.id !== interaction.guild.id)
return interaction.editReply({
@@ -202,20 +200,20 @@
});
}
}
- let data = await client.database.guilds.read(interaction.guild.id);
- data.tickets.customTypes = (data.tickets.customTypes || []).filter(
+ const data = await client.database.guilds.read(interaction.guild.id);
+ data.tickets.customTypes = (data.tickets.customTypes ?? []).filter(
(value: string, index: number, array: string[]) => array.indexOf(value) === index
);
let lastClicked = "";
- let embed: EmojiEmbed = new EmojiEmbed();
- let compiledData = {
+ const embed: EmojiEmbed = new EmojiEmbed();
+ const compiledData = {
enabled: data.tickets.enabled,
category: data.tickets.category,
maxTickets: data.tickets.maxTickets,
supportRole: data.tickets.supportRole,
useCustom: data.tickets.useCustom,
types: data.tickets.types,
- customTypes: data.tickets.customTypes
+ customTypes: data.tickets.customTypes as string[] | null
};
let timedOut = false;
while (!timedOut) {
@@ -485,29 +483,27 @@
continue;
}
out = out as ModalSubmitInteraction;
- if (out.fields) {
- const title = out.fields.getTextInputValue("title");
- const description = out.fields.getTextInputValue("description");
- await interaction.channel!.send({
- embeds: [
- new EmojiEmbed()
- .setTitle(title)
- .setDescription(description)
- .setStatus("Success")
- .setEmoji("GUILD.TICKET.OPEN")
- ],
- components: [
- new ActionRowBuilder<ButtonBuilder>().addComponents([
- new ButtonBuilder()
- .setLabel("Create Ticket")
- .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id"))
- .setStyle(ButtonStyle.Success)
- .setCustomId("createticket")
- ])
- ]
- });
- templateSelected = true;
- }
+ const title = out.fields.getTextInputValue("title");
+ const description = out.fields.getTextInputValue("description");
+ await interaction.channel!.send({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle(title)
+ .setDescription(description)
+ .setStatus("Success")
+ .setEmoji("GUILD.TICKET.OPEN")
+ ],
+ components: [
+ new ActionRowBuilder<ButtonBuilder>().addComponents([
+ new ButtonBuilder()
+ .setLabel("Create Ticket")
+ .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id"))
+ .setStyle(ButtonStyle.Success)
+ .setCustomId("createticket")
+ ])
+ ]
+ });
+ templateSelected = true;
}
}
} else if ((i.component as ButtonComponent).customId === "enabled") {
@@ -516,7 +512,7 @@
});
compiledData.enabled = !compiledData.enabled;
} else if ((i.component as ButtonComponent).customId === "manageTypes") {
- data = await manageTypes(interaction, data, m as Message); //TODO: Fix this
+ data.tickets = await manageTypes(interaction, data.tickets, m as Message);
}
}
await interaction.editReply({
@@ -713,24 +709,20 @@
continue;
}
out = out as ModalSubmitInteraction;
- if (out.fields) {
- let toAdd = out.fields.getTextInputValue("type");
- if (!toAdd) {
- continue;
- }
- toAdd = toAdd.substring(0, 80);
- try {
- await client.database.guilds.append(interaction.guild!.id, "tickets.customTypes", toAdd);
- } catch {
- continue;
- }
- data.customTypes = data.customTypes ?? [];
- if (!data.customTypes.includes(toAdd)) {
- data.customTypes.push(toAdd);
- }
- } else {
+ let toAdd = out.fields.getTextInputValue("type");
+ if (!toAdd) {
continue;
}
+ toAdd = toAdd.substring(0, 80);
+ try {
+ await client.database.guilds.append(interaction.guild!.id, "tickets.customTypes", toAdd);
+ } catch {
+ continue;
+ }
+ data.customTypes = data.customTypes ?? [];
+ if (!data.customTypes.includes(toAdd)) {
+ data.customTypes.push(toAdd);
+ }
} else if ((i.component as ButtonComponent).customId === "switchToDefault") {
i.deferUpdate();
await client.database.guilds.write(interaction.guild!.id, { "tickets.useCustom": false }, []);
diff --git a/src/commands/user/track.ts b/src/commands/user/track.ts
index 983b82f..0814cfa 100644
--- a/src/commands/user/track.ts
+++ b/src/commands/user/track.ts
@@ -1,5 +1,5 @@
import { LoadingEmbed } from "../../utils/defaults.js";
-import Discord, { CommandInteraction, GuildMember, Message, ActionRowBuilder, ButtonBuilder, ButtonStyle, SelectMenuOptionBuilder, APIMessageComponentEmoji, StringSelectMenuBuilder, MessageComponentInteraction, StringSelectMenuInteraction, Role } from "discord.js";
+import Discord, { CommandInteraction, GuildMember, Message, ActionRowBuilder, ButtonBuilder, ButtonStyle, SelectMenuOptionBuilder, APIMessageComponentEmoji, StringSelectMenuBuilder, MessageComponentInteraction, StringSelectMenuInteraction } from "discord.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import getEmojiByName from "../../utils/getEmojiByName.js";
@@ -36,7 +36,7 @@
let timedOut = false;
while (!timedOut) {
const data = config.tracks[track]!;
- if (data.manageableBy !== undefined)
+ if (data.manageableBy.length)
managed = data.manageableBy.some((element: string) => {
return memberRoles.cache.has(element);
});
@@ -94,7 +94,7 @@
}
const conflict = data.retainPrevious ? false : selected.length > 1;
let conflictDropdown: StringSelectMenuBuilder[] = [];
- let conflictDropdownOptions: SelectMenuOptionBuilder[] = [];
+ const conflictDropdownOptions: SelectMenuOptionBuilder[] = [];
let currentRoleIndex: number = -1;
if (conflict) {
generated += `\n\n${getEmojiByName(`PUNISH.WARN.${managed ? "YELLOW" : "RED"}`)} This user has ${
@@ -202,7 +202,7 @@
}
}
} else if (component.customId === "select") {
- track = (component as StringSelectMenuInteraction).values[0];
+ track = parseInt((component as StringSelectMenuInteraction).values[0]!);
}
}
};
@@ -215,9 +215,10 @@
if (member.id === interaction.guild!.ownerId) return true;
// Check if the user can manage any of the tracks
let managed = false;
+ const memberRoles = member.roles.cache.map((r) => r.id)
for (const element of tracks) {
- if (!element.track.manageableBy) continue;
- if (!element.track.manageableBy.some((role: Role) => member.roles.cache.has(role.id))) continue;
+ if (!element.manageableBy.length) continue;
+ if (!element.manageableBy.some((role: string) => memberRoles.includes(role))) continue;
managed = true;
break;
}
diff --git a/src/config/format.ts b/src/config/format.ts
index 9cd5211..53aba72 100644
--- a/src/config/format.ts
+++ b/src/config/format.ts
@@ -1,4 +1,5 @@
import fs from "fs";
+// @ts-expect-error
import * as readLine from "node:readline/promises";
const defaultDict: Record<string, string | string[] | boolean> = {
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()
},
diff --git a/src/utils/commandRegistration/register.ts b/src/utils/commandRegistration/register.ts
index fdae167..281be18 100644
--- a/src/utils/commandRegistration/register.ts
+++ b/src/utils/commandRegistration/register.ts
@@ -42,7 +42,7 @@
i++;
console.log(`${last.replace("└", " ").replace("├", "│")} └─ ${colours.green}Loaded ${file.name} [${i} / ${files.length}]${colours.none}`)
}
- console.log(`Loaded ${commands.length} commands, processing...`)
+ console.log(`${colours.yellow}Loaded ${commands.length} commands, processing...`)
const processed = []
for (const subcommand of commands) {
@@ -53,7 +53,7 @@
}
}
- console.log(`Processed ${processed.length} commands`)
+ console.log(`${colours.green}Processed ${processed.length} commands`)
return processed;
};