eslint problems fixed, now theres only 850 ts ones to go
diff --git a/src/utils/confirmationMessage.ts b/src/utils/confirmationMessage.ts
index a615fae..fd58d12 100644
--- a/src/utils/confirmationMessage.ts
+++ b/src/utils/confirmationMessage.ts
@@ -1,4 +1,4 @@
-import Discord, { CommandInteraction, MessageActionRow, Message, MessageButton, TextInputComponent } from "discord.js";
+import Discord, { CommandInteraction, MessageActionRow, MessageButton, TextInputComponent } from "discord.js";
import { modalInteractionCollector } from "./dualCollector.js";
import EmojiEmbed from "./generateEmojiEmbed.js";
import getEmojiByName from "./getEmojiByName.js";
@@ -106,7 +106,7 @@
} catch { return { cancelled: true }; }
let component;
try {
- component = await (m as Message).awaitMessageComponent({filter: (m) => m.user.id === this.interaction.user.id, time: 300000});
+ component = await m.awaitMessageComponent({filter: (m) => m.user.id === this.interaction.user.id, time: 300000});
} catch (e) {
return { success: false, components: this.customButtons };
}
diff --git a/src/utils/dualCollector.ts b/src/utils/dualCollector.ts
index c785d0a..11df0ce 100644
--- a/src/utils/dualCollector.ts
+++ b/src/utils/dualCollector.ts
@@ -1,4 +1,4 @@
-import Discord from "discord.js";
+import Discord, { Interaction } from "discord.js";
import client from "./client.js";
export default async function (m, interactionFilter, messageFilter) {
@@ -24,14 +24,14 @@
let out;
try {
out = await new Promise((resolve, _reject) => {
- const int = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 300000})
- .on("collect", (m) => { resolve(m); });
+ const int = m.createMessageComponentCollector({filter: (m: Interaction) => interactionFilter(m), time: 300000})
+ .on("collect", (m: Interaction) => { resolve(m); });
const mod = new Discord.InteractionCollector(
client, {
- filter: (m) => modalFilter(m),
+ filter: (m: Interaction) => modalFilter(m),
time: 300000
})
- .on("collect", async (m) => {
+ .on("collect", async (m: Interaction) => {
int.stop();
(m as Discord.ModalSubmitInteraction).deferUpdate();
resolve((m as Discord.ModalSubmitInteraction)); });
diff --git a/src/utils/eventScheduler.ts b/src/utils/eventScheduler.ts
index cde178f..df46ca8 100644
--- a/src/utils/eventScheduler.ts
+++ b/src/utils/eventScheduler.ts
@@ -1,4 +1,4 @@
-import { Agenda } from "agenda/es.js";
+import { Agenda } from "@hokify/agenda";
import client from "./client.js";
import * as fs from "fs";
import * as path from "path";
@@ -10,18 +10,18 @@
constructor() {
this.agenda = new Agenda({db: {address: config.mongoUrl + "Nucleus", collection: "eventScheduler"}});
- this.agenda.define("unmuteRole", async (job: Agenda.job) => {
+ this.agenda.define("unmuteRole", async (job) => {
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);
await job.remove();
});
- this.agenda.define("deleteFile", async (job: Agenda.job) => {
+ this.agenda.define("deleteFile", async (job) => {
fs.rm(path.resolve("dist/utils/temp", job.attrs.data.fileName), client._error);
await job.remove();
});
- this.agenda.define("naturalUnmute", async (job: Agenda.job) => {
+ this.agenda.define("naturalUnmute", async (job) => {
const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
const guild = await client.guilds.fetch(job.attrs.data.guild);
const user = await guild.members.fetch(job.attrs.data.user);
diff --git a/src/utils/generateEmojiEmbed.ts b/src/utils/generateEmojiEmbed.ts
index 7587db7..65e11fa 100644
--- a/src/utils/generateEmojiEmbed.ts
+++ b/src/utils/generateEmojiEmbed.ts
@@ -8,23 +8,24 @@
};
class EmojiEmbed extends MessageEmbed {
- _title: string;
- _emoji: string;
+ _title = "";
+ _emoji: string | null = null;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// This *is* meant to be an accessor rather than a property
- get title() {
+ override get title() {
+ if (!this._emoji) return this._title;
return `${getEmojiByName(this._emoji)} ${this._title}`;
}
- set title(title: string) {
+ override set title(title: string) {
this._title = title;
}
- setTitle(title: string) { this._title = title; return this; }
+ override setTitle(title: string) { this._title = title; return this; }
setEmoji(emoji: string) { this._emoji = emoji; return this; }
- setStatus(color: string) { this.setColor(colors[color]); return this; }
+ setStatus(color: "Danger" | "Warning" | "Success") { this.setColor(colors[color]); return this; }
}
export default EmojiEmbed;
\ No newline at end of file
diff --git a/src/utils/generateKeyValueList.ts b/src/utils/generateKeyValueList.ts
index ecb9780..a093ab7 100644
--- a/src/utils/generateKeyValueList.ts
+++ b/src/utils/generateKeyValueList.ts
@@ -7,7 +7,7 @@
export function capitalize(s: string) {
s = s.replace(/([A-Z])/g, " $1");
s = s.split(" ").map(word => {
- return forceCaps.includes(word.toUpperCase()) ? word.toUpperCase() : word[0]
+ return forceCaps.includes(word.toUpperCase()) ? word.toUpperCase() : (word[0] ?? "")
.toUpperCase() + word.slice(1)
.toLowerCase()
.replace("discord", "Discord");
@@ -16,10 +16,11 @@
}
export function toCapitals(s: string) {
+ if (s[0] === undefined) return "";
return s[0].toUpperCase() + s.slice(1).toLowerCase();
}
-function keyValueList(data) {
+function keyValueList(data: Record<string, string>) {
let out = "";
Object.entries(data).map(([key, value]) => {
out += `**${capitalize(key)}:** ${value}\n`;
diff --git a/src/utils/getEmojiByName.ts b/src/utils/getEmojiByName.ts
index 63b2042..c0a43cb 100644
--- a/src/utils/getEmojiByName.ts
+++ b/src/utils/getEmojiByName.ts
@@ -1,10 +1,21 @@
import emojis from "../config/emojis.json" assert {type: "json"};
+interface EmojisIndex {
+ [key: string]: string | EmojisIndex | EmojisIndex[];
+}
+
function getEmojiByName(name: string, format?: string): string {
const split = name.split(".");
- let id = emojis;
+ let id: string | EmojisIndex | EmojisIndex[] | undefined = emojis;
split.forEach(part => {
- id = id[part];
+ if (typeof id === "string" || id === undefined) {
+ throw new Error(`Emoji ${name} not found`);
+ }
+ if (Array.isArray(id)) {
+ id = id[parseInt(part)];
+ } else {
+ id = id[part];
+ }
});
if ( format === "id" ) {
if (id === undefined) return "0";
diff --git a/src/utils/log.ts b/src/utils/log.ts
index 34b24c6..f9f751e 100644
--- a/src/utils/log.ts
+++ b/src/utils/log.ts
@@ -21,11 +21,11 @@
t = Math.floor(t /= 1000);
return `<t:${t}:R> (<t:${t}:D> at <t:${t}:T>)`;
}
- renderNumberDelta(num1, num2) {
+ renderNumberDelta(num1: number, num2: number) {
const delta = num2 - num1;
return `${num1} -> ${num2} (${delta > 0 ? "+" : ""}${delta})`;
}
- entry(value, displayValue) {
+ entry(value: string, displayValue: string) {
return { value: value, displayValue: displayValue };
}
renderChannel(channel: Discord.GuildChannel | Discord.ThreadChannel) {
@@ -45,7 +45,7 @@
};
- async getAuditLog(guild: Discord.Guild, event): Promise<Discord.GuildAuditLogsEntry[]>{
+ async getAuditLog(guild: Discord.Guild, event: Discord.GuildAuditLogsResolvable): Promise<Discord.GuildAuditLogsEntry[]>{
await wait(250);
const auditLog = await guild.fetchAuditLogs({type: event});
return auditLog as unknown as Discord.GuildAuditLogsEntry[];
@@ -60,9 +60,9 @@
}
if (config.logging.logs.channel) {
const channel = await client.channels.fetch(config.logging.logs.channel) as Discord.TextChannel;
- const description = {};
+ const description: Record<string, string> = {};
Object.entries(log.list).map(entry => {
- const key = entry[0];
+ const key: string = entry[0];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const value: any = entry[1];
if(value.displayValue) {
diff --git a/src/utils/singleNotify.ts b/src/utils/singleNotify.ts
index 44bb2d0..7339129 100644
--- a/src/utils/singleNotify.ts
+++ b/src/utils/singleNotify.ts
@@ -1,13 +1,15 @@
import client from "./client.js";
import EmojiEmbed from "./generateEmojiEmbed.js";
+import { Record as ImmutableRecord } from "immutable";
-const severities = {
+const severitiesType = ImmutableRecord({
"Critical": "Danger",
"Warning": "Warning",
"Info": "Success"
-};
+} as Record<string, "Danger" | "Warning" | "Success">);
+const severities = severitiesType();
-export default async function(type: string, guild: string, message: string | true, severity?: string) {
+export default async function(type: string, guild: string, message: string | true, severity: "Critical" | "Warning" | "Info" = "Info") {
const data = await client.database.guilds.read(guild);
if (message === true) {
return await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: false});
@@ -20,7 +22,7 @@
await channel.send({embeds: [new EmojiEmbed()
.setTitle(`${severity} notification`)
.setDescription(message)
- .setStatus(severities[severity])
+ .setStatus(severities.get(severity))
.setEmoji("CONTROL.BLOCKCROSS")
]});
} catch (err) {