Fixed a lot of commands, 0 typing errors on those changed
diff --git a/src/utils/client.ts b/src/utils/client.ts
index 61cf3bf..53267f2 100644
--- a/src/utils/client.ts
+++ b/src/utils/client.ts
@@ -5,6 +5,7 @@
import { Guilds, History, ModNotes, Premium } from "../utils/database.js";
import EventScheduler from "../utils/eventScheduler.js";
import type { RoleMenuSchema } from "../actions/roleMenu.js";
+// @ts-expect-error
import config from "../config/main.json" assert { type: "json" };
@@ -38,7 +39,7 @@
}
const client = new NucleusClient({
- guilds: new Guilds(),
+ guilds: await new Guilds().setup(),
history: new History(),
notes: new ModNotes(),
premium: new Premium(),
diff --git a/src/utils/commandRegistration/register.ts b/src/utils/commandRegistration/register.ts
index 1b55496..64f6e77 100644
--- a/src/utils/commandRegistration/register.ts
+++ b/src/utils/commandRegistration/register.ts
@@ -1,14 +1,16 @@
import { Interaction, SlashCommandBuilder } from 'discord.js';
+// @ts-expect-error
import config from "../../config/main.json" assert { type: "json" };
import client from "../client.js";
import fs from "fs";
-import Discord from "discord.js";
const colours = {
red: "\x1b[31m",
green: "\x1b[32m",
yellow: "\x1b[33m",
+ blue: "\x1b[34m",
+ purple: "\x1b[35m",
none: "\x1b[0m"
}
@@ -52,10 +54,10 @@
if (developmentMode) {
const guild = await client.guilds.fetch(config.developmentGuildID);
if (updateCommands) guild.commands.set(processed);
- console.log(`Commands registered in ${guild.name}`)
+ console.log(`${colours.purple}Commands registered in ${guild.name}${colours.none}`)
} else {
if (updateCommands) client.application!.commands.set(processed);
- console.log(`Commands registered globally`)
+ console.log(`${colours.blue}Commands registered globally${colours.none}`)
}
};
@@ -120,4 +122,7 @@
await registerCommandHandler();
await registerEvents();
console.log(`${colours.green}Registered commands and events${colours.none}`)
+ console.log(
+ (config.enableDevelopment ? `${colours.purple}Bot started in Development mode` :
+ `${colours.blue}Bot started in Production mode`) + colours.none)
};
diff --git a/src/utils/commandRegistration/slashCommandBuilder.ts b/src/utils/commandRegistration/slashCommandBuilder.ts
index 76ecabe..45cb8f1 100644
--- a/src/utils/commandRegistration/slashCommandBuilder.ts
+++ b/src/utils/commandRegistration/slashCommandBuilder.ts
@@ -1,5 +1,6 @@
import type { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
import type { SlashCommandBuilder } from "discord.js";
+// @ts-expect-error
import config from "../../config/main.json" assert { type: "json" };
import getSubcommandsInFolder from "./getFilesInFolder.js";
import client from "../client.js";
diff --git a/src/utils/confirmationMessage.ts b/src/utils/confirmationMessage.ts
index 18e6ea0..87724f3 100644
--- a/src/utils/confirmationMessage.ts
+++ b/src/utils/confirmationMessage.ts
@@ -1,3 +1,4 @@
+import { TextInputBuilder } from "@discordjs/builders";
import Discord, {
CommandInteraction,
Interaction,
@@ -6,8 +7,8 @@
ButtonBuilder,
MessageComponentInteraction,
ModalSubmitInteraction,
- TextInputComponent,
- ButtonStyle
+ ButtonStyle,
+ TextInputStyle
} from "discord.js";
import { modalInteractionCollector } from "./dualCollector.js";
import EmojiEmbed from "./generateEmojiEmbed.js";
@@ -65,7 +66,7 @@
customId: string,
title: string,
disabled: boolean,
- callback: () => Promise<unknown> = async () => null,
+ callback: (() => Promise<unknown>) | null = async () => null,
callbackClicked: string | null,
emoji?: string,
initial?: boolean
@@ -76,7 +77,7 @@
value: callbackClicked,
emoji: emoji,
active: initial ?? false,
- onClick: callback,
+ onClick: callback ?? (async () => null),
response: null
};
return this;
@@ -129,7 +130,10 @@
);
const components = [];
for (let i = 0; i < fullComponents.length; i += 5) {
- components.push(new ActionRowBuilder().addComponents(fullComponents.slice(i, i + 5)));
+ components.push(new ActionRowBuilder<
+ Discord.ButtonBuilder | Discord.StringSelectMenuBuilder |
+ Discord.RoleSelectMenuBuilder | Discord.UserSelectMenuBuilder
+ >().addComponents(fullComponents.slice(i, i + 5)));
}
const object = {
embeds: [
@@ -155,7 +159,7 @@
let m: Message;
try {
if (editOnly) {
- m = (await this.interaction.editReply(object)) as Message;
+ m = (await this.interaction.editReply(object)) as unknown as Message;
} else {
m = (await this.interaction.reply(object)) as unknown as Message;
}
@@ -194,17 +198,17 @@
continue;
} else if (component.customId === "reason") {
await component.showModal(
- new Discord.Modal()
+ new Discord.ModalBuilder()
.setCustomId("modal")
.setTitle("Editing reason")
.addComponents(
- new ActionRowBuilder<TextInputComponent>().addComponents(
- new TextInputComponent()
+ new ActionRowBuilder<TextInputBuilder>().addComponents(
+ new TextInputBuilder()
.setCustomId("reason")
.setLabel("Reason")
.setMaxLength(2000)
.setRequired(false)
- .setStyle("PARAGRAPH")
+ .setStyle(TextInputStyle.Paragraph)
.setPlaceholder("Spammed in #general")
.setValue(this.reason ? this.reason : "")
)
@@ -219,13 +223,13 @@
.setEmoji(this.emoji)
],
components: [
- new ActionRowBuilder().addComponents([
+ new ActionRowBuilder<Discord.ButtonBuilder>().addComponents(
new ButtonBuilder()
.setLabel("Back")
.setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
.setStyle(ButtonStyle.Primary)
.setCustomId("back")
- ])
+ )
]
});
let out;
@@ -269,7 +273,12 @@
}
if (newReason) returnValue.newReason = newReason;
- return returnValue;
+ const typedReturnValue = returnValue as {cancelled: true} |
+ { success: boolean, components: Record<string, CustomBoolean<unknown>>, newReason?: string} |
+ { newReason: string, components: Record<string, CustomBoolean<unknown>> } |
+ { components: Record<string, CustomBoolean<unknown>> };
+
+ return typedReturnValue;
}
async timeoutError(): Promise<void> {
diff --git a/src/utils/database.ts b/src/utils/database.ts
index 2ae6af9..2624fc9 100644
--- a/src/utils/database.ts
+++ b/src/utils/database.ts
@@ -1,5 +1,6 @@
import type Discord from "discord.js";
import { Collection, MongoClient } from "mongodb";
+// @ts-expect-error
import config from "../config/main.json" assert { type: "json" };
const mongoClient = new MongoClient(config.mongoUrl);
@@ -16,6 +17,7 @@
}
async setup(): Promise<Guilds> {
+ // @ts-expect-error
this.defaultData = (await import("../config/default.json", { assert: { type: "json" } }))
.default as unknown as GuildConfig;
return this;
@@ -184,9 +186,7 @@
export interface GuildConfig {
id: string;
version: number;
- singleEventNotifications: {
- statsChannelDeleted: boolean;
- };
+ singleEventNotifications: Record<string, boolean>;
filters: {
images: {
NSFW: boolean;
diff --git a/src/utils/defaultEmbeds.ts b/src/utils/defaultEmbeds.ts
index 2334504..39a6080 100644
--- a/src/utils/defaultEmbeds.ts
+++ b/src/utils/defaultEmbeds.ts
@@ -4,3 +4,8 @@
export const LoadingEmbed = [
new EmojiEmbed().setDescription(`${getEmojiByName("NUCLEUS.LOADING")} One moment...`).setStatus("Danger")
];
+
+export const LinkWarningFooter = {
+ text: "The button below will take you to a website set by the server moderators. Do not enter any passwords unless it is from a trusted website.",
+ iconURL: "https://cdn.discordapp.com/emojis/952295894370369587.webp?size=128&quality=lossless"
+}
\ No newline at end of file
diff --git a/src/utils/dualCollector.ts b/src/utils/dualCollector.ts
index abc6bb3..714a2d9 100644
--- a/src/utils/dualCollector.ts
+++ b/src/utils/dualCollector.ts
@@ -1,4 +1,4 @@
-import Discord, { Interaction, Message, MessageComponentInteraction } from "discord.js";
+import Discord, { Client, Interaction, Message, MessageComponentInteraction } from "discord.js";
import client from "./client.js";
export default async function (
@@ -26,7 +26,7 @@
try {
m.delete();
} catch (e) {
- client._error(e);
+ client.emit("error", e as Error);
}
resolve(m);
});
@@ -61,7 +61,7 @@
.on("collect", (i: Interaction) => {
resolve(i);
});
- const mod = new Discord.InteractionCollector(client, {
+ const mod = new Discord.InteractionCollector(client as Client, {
filter: (i: Interaction) => modalFilter(i),
time: 300000
}).on("collect", async (i: Interaction) => {
diff --git a/src/utils/eventScheduler.ts b/src/utils/eventScheduler.ts
index 203e05b..0a32a1e 100644
--- a/src/utils/eventScheduler.ts
+++ b/src/utils/eventScheduler.ts
@@ -2,6 +2,7 @@
import client from "./client.js";
import * as fs from "fs";
import * as path from "path";
+// @ts-expect-error
import config from "../config/main.json" assert { type: "json" };
class EventScheduler {
@@ -19,11 +20,11 @@
const guild = await client.guilds.fetch(job.attrs.data.guild);
const user = await guild.members.fetch(job.attrs.data.user);
const role = await guild.roles.fetch(job.attrs.data.role);
- await user.roles.remove(role);
+ if (role) await user.roles.remove(role);
await job.remove();
});
this.agenda.define("deleteFile", async (job) => {
- fs.rm(path.resolve("dist/utils/temp", job.attrs.data.fileName), client._error);
+ fs.rm(path.resolve("dist/utils/temp", job.attrs.data.fileName), (e) => { client.emit("error", e as Error); });
await job.remove();
});
this.agenda.define("naturalUnmute", async (job) => {
@@ -34,7 +35,7 @@
try {
await client.database.history.create("unmute", user.guild.id, user.user, null, null, null, null);
} catch (e) {
- client._error(e);
+ client.emit("error", e as Error);
}
const data = {
meta: {
@@ -48,7 +49,7 @@
list: {
memberId: entry(user.user.id, `\`${user.user.id}\``),
name: entry(user.user.id, renderUser(user.user)),
- unmuted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ unmuted: entry(new Date().getTime().toString(), renderDelta(new Date().getTime())),
unmutedBy: entry(null, "*Time out ended*")
},
hidden: {
diff --git a/src/utils/getEmojiByName.ts b/src/utils/getEmojiByName.ts
index 3fa2b53..7824982 100644
--- a/src/utils/getEmojiByName.ts
+++ b/src/utils/getEmojiByName.ts
@@ -1,3 +1,4 @@
+// @ts-expect-error
import emojis from "../config/emojis.json" assert { type: "json" };
interface EmojisIndex {
diff --git a/src/utils/log.ts b/src/utils/log.ts
index a578b69..b097798 100644
--- a/src/utils/log.ts
+++ b/src/utils/log.ts
@@ -25,7 +25,7 @@
const delta = num2 - num1;
return `${num1} -> ${num2} (${delta > 0 ? "+" : ""}${delta})`;
},
- entry(value: string, displayValue: string): { value: string; displayValue: string } {
+ entry(value: string | null, displayValue: string): { value: string | null; displayValue: string } {
return { value: value, displayValue: displayValue };
},
renderChannel(channel: Discord.GuildChannel | Discord.ThreadChannel) {
diff --git a/src/utils/singleNotify.ts b/src/utils/singleNotify.ts
index 8f011e3..e762487 100644
--- a/src/utils/singleNotify.ts
+++ b/src/utils/singleNotify.ts
@@ -16,6 +16,7 @@
severity: "Critical" | "Warning" | "Info" = "Info"
) {
const data = await client.database.guilds.read(guild);
+ if (data.logging.staff.channel === null) return;
if (message === true) {
return await client.database.guilds.write(guild, {
[`singleEventNotifications.${type}`]: false
@@ -28,6 +29,7 @@
try {
const channel = await client.channels.fetch(data.logging.staff.channel);
if (!channel) return;
+ if (!channel.isTextBased()) return;
await channel.send({
embeds: [
new EmojiEmbed()
diff --git a/src/utils/temp/generateFileName.ts b/src/utils/temp/generateFileName.ts
index 8534846..3aab64c 100644
--- a/src/utils/temp/generateFileName.ts
+++ b/src/utils/temp/generateFileName.ts
@@ -12,7 +12,7 @@
if (fs.existsSync(`./${fileName}`)) {
fileName = generateFileName(ending);
}
- client.database.eventScheduler.schedule("deleteFile", new Date().getTime() + 60 * 1000, {
+ client.database.eventScheduler.schedule("deleteFile", (new Date().getTime() + 60 * 1000).toString(), {
fileName: `${fileName}.${ending}`
});
return path.join(__dirname, fileName + "." + ending);