Still got errors and warnings, mostly the same and easy to fix
diff --git a/src/utils/calculate.ts b/src/utils/calculate.ts
index 8badc58..9bdef3b 100644
--- a/src/utils/calculate.ts
+++ b/src/utils/calculate.ts
@@ -19,7 +19,7 @@
"autoModeratorDeleted",
"nucleusSettingsUpdated",
"ticketUpdate"
-]
+];
const tickets = [
"support",
@@ -28,7 +28,7 @@
"issue",
"suggestion",
"other"
-]
+];
const toHexInteger = (permissions, array?) => {
if (!array) {
@@ -36,29 +36,29 @@
}
let int = 0n;
- for(let perm of permissions) {
+ for(const perm of permissions) {
int += BigInt(2 ** array.indexOf(perm));
}
- return int.toString(16)
-}
+ return int.toString(16);
+};
const toHexArray = (permissionsHex, array?) => {
if (!array) {
array = logs;
}
- let permissions = [];
- let int = (BigInt("0x" + permissionsHex)).toString(2).split('').reverse();
- for (let index in int) {
+ const permissions = [];
+ const int = (BigInt("0x" + permissionsHex)).toString(2).split("").reverse();
+ for (const index in int) {
if (int[index] === "1" && array.length > index) {
permissions.push(array[index]);
}
}
return permissions;
-}
+};
export {
toHexInteger,
toHexArray,
tickets,
logs
-}
\ No newline at end of file
+};
\ No newline at end of file
diff --git a/src/utils/client.ts b/src/utils/client.ts
index 3f4a8a1..a343bcb 100644
--- a/src/utils/client.ts
+++ b/src/utils/client.ts
@@ -1,9 +1,9 @@
-import { HaikuClient } from 'jshaiku';
-import { Intents } from 'discord.js';
-import config from '../config/main.json' assert {type: 'json'};
+import { HaikuClient } from "jshaiku";
+import { Intents } from "discord.js";
+import config from "../config/main.json" assert {type: "json"};
const client = new HaikuClient({
- intents: new Intents(32767).bitfield, // This is a way of specifying all intents w/o having to type them out
+ intents: new Intents(32767).bitfield // This is a way of specifying all intents w/o having to type them out
}, config);
export default client;
\ No newline at end of file
diff --git a/src/utils/confirmationMessage.ts b/src/utils/confirmationMessage.ts
index dfdc3fb..a615fae 100644
--- a/src/utils/confirmationMessage.ts
+++ b/src/utils/confirmationMessage.ts
@@ -1,6 +1,6 @@
import Discord, { CommandInteraction, MessageActionRow, Message, MessageButton, TextInputComponent } from "discord.js";
import { modalInteractionCollector } from "./dualCollector.js";
-import EmojiEmbed from "./generateEmojiEmbed.js"
+import EmojiEmbed from "./generateEmojiEmbed.js";
import getEmojiByName from "./getEmojiByName.js";
@@ -8,7 +8,7 @@
title: string;
disabled: boolean;
value: string | null;
- emoji: string | null;
+ emoji: string | undefined;
active: boolean;
onClick: () => Promise<T>;
response: T | null;
@@ -16,33 +16,33 @@
class confirmationMessage {
interaction: CommandInteraction;
- title: string = "";
- emoji: string = "";
- description: string = "";
- color: string = "";
+ title = "";
+ emoji = "";
+ description = "";
+ color = "";
customButtons: {[index:string]: CustomBoolean<unknown>} = {};
- inverted: boolean = false;
+ inverted = false;
reason: string | null = null;
constructor(interaction: CommandInteraction) {
this.interaction = interaction;
}
- setTitle(title: string) { this.title = title; return this }
- setEmoji(emoji: string) { this.emoji = emoji; return this }
- setDescription(description: string) { this.description = description; return this }
- setColor(color: string) { this.color = color; return this }
- setInverted(inverted: boolean) { this.inverted = inverted; return this }
+ setTitle(title: string) { this.title = title; return this; }
+ setEmoji(emoji: string) { this.emoji = emoji; return this; }
+ setDescription(description: string) { this.description = description; return this; }
+ setColor(color: string) { this.color = color; return this; }
+ setInverted(inverted: boolean) { this.inverted = inverted; return this; }
addCustomBoolean(customId: string, title: string, disabled: boolean, callback: () => Promise<unknown> | null, callbackClicked: string | null, emoji?: string, initial?: boolean) { this.customButtons[customId] = {
- title: title,
- disabled: disabled,
- value: callbackClicked,
- emoji: emoji,
- active: initial ?? false,
- onClick: callback ?? (() => null),
- response: null,
- }
- return this;
+ title: title,
+ disabled: disabled,
+ value: callbackClicked,
+ emoji: emoji,
+ active: initial ?? false,
+ onClick: callback ?? (() => null),
+ response: null
+ };
+ return this;
}
addReasonButton(reason: string) {
this.reason = reason;
@@ -50,7 +50,7 @@
}
async send(editOnly?: boolean) {
while (true) {
- let fullComponents = [
+ const fullComponents = [
new Discord.MessageButton()
.setCustomId("yes")
.setLabel("Confirm")
@@ -61,27 +61,27 @@
.setLabel("Cancel")
.setStyle("SECONDARY")
.setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
- ]
+ ];
Object.entries(this.customButtons).forEach(([k, v]) => {
fullComponents.push(new Discord.MessageButton()
.setCustomId(k)
.setLabel(v.title)
.setStyle(v.active ? "SUCCESS" : "PRIMARY")
.setEmoji(getEmojiByName(v.emoji, "id"))
- .setDisabled(v.disabled))
- })
+ .setDisabled(v.disabled));
+ });
if (this.reason !== null) fullComponents.push(new Discord.MessageButton()
.setCustomId("reason")
- .setLabel(`Edit Reason`)
+ .setLabel("Edit Reason")
.setStyle("PRIMARY")
.setEmoji(getEmojiByName("ICONS.EDIT", "id"))
.setDisabled(false)
- )
- let components = []
+ );
+ const components = [];
for (let i = 0; i < fullComponents.length; i += 5) {
components.push(new MessageActionRow().addComponents(fullComponents.slice(i, i + 5)));
}
- let object = {
+ const object = {
embeds: [
new EmojiEmbed()
.setEmoji(this.emoji)
@@ -95,15 +95,15 @@
components: components,
ephemeral: true,
fetchReply: true
- }
+ };
let m;
try {
if ( editOnly ) {
m = await this.interaction.editReply(object);
} else {
- m = await this.interaction.reply(object)
+ m = await this.interaction.reply(object);
}
- } catch { return { cancelled: true } }
+ } catch { return { cancelled: true }; }
let component;
try {
component = await (m as Message).awaitMessageComponent({filter: (m) => m.user.id === this.interaction.user.id, time: 300000});
@@ -112,17 +112,17 @@
}
if (component.customId === "yes") {
component.deferUpdate();
- for (let [k, v] of Object.entries(this.customButtons)) {
- if (!v.active) continue
+ for (const v of Object.values(this.customButtons)) {
+ if (!v.active) continue;
try { v.response = await v.onClick(); }
- catch (e) { console.log(e) }
- };
+ catch (e) { console.log(e); }
+ }
return { success: true, components: this.customButtons };
} else if (component.customId === "no") {
component.deferUpdate();
return { success: false, components: this.customButtons };
} else if (component.customId === "reason") {
- await component.showModal(new Discord.Modal().setCustomId("modal").setTitle(`Editing reason`).addComponents(
+ await component.showModal(new Discord.Modal().setCustomId("modal").setTitle("Editing reason").addComponents(
new MessageActionRow<TextInputComponent>().addComponents(new TextInputComponent()
.setCustomId("reason")
.setLabel("Reason")
@@ -132,7 +132,7 @@
.setPlaceholder("Spammed in #general")
.setValue(this.reason ? this.reason : "")
)
- ))
+ ));
await this.interaction.editReply({
embeds: [new EmojiEmbed()
.setTitle(this.title)
@@ -148,10 +148,10 @@
});
let out;
try {
- out = await modalInteractionCollector(m, (m) => m.channel.id === this.interaction.channel.id, (m) => m.customId === "reason")
- } catch (e) { return {} }
+ out = await modalInteractionCollector(m, (m) => m.channel.id === this.interaction.channel.id, (m) => m.customId === "reason");
+ } catch (e) { return {}; }
if (out.fields) { return { newReason: out.fields.getTextInputValue("reason") ?? "" }; }
- else { return { newReason: this.reason } }
+ else { return { newReason: this.reason }; }
} else {
component.deferUpdate();
this.customButtons[component.customId].active = !this.customButtons[component.customId].active;
diff --git a/src/utils/convertCurlyBracketString.ts b/src/utils/convertCurlyBracketString.ts
index 6ffdc8f..f05076e 100644
--- a/src/utils/convertCurlyBracketString.ts
+++ b/src/utils/convertCurlyBracketString.ts
@@ -1,6 +1,6 @@
async function convertCurlyBracketString(str, memberID, memberName, serverName, members): Promise<string> {
- let memberCount = (await members.fetch()).size
- let bots = (await members.fetch()).filter(m => m.user.bot).size
+ const memberCount = (await members.fetch()).size;
+ const bots = (await members.fetch()).filter(m => m.user.bot).size;
str = str
.replace("{member:mention}", memberID ? `<@${memberID}>` : "{member:mention}")
.replace("{member:name}", memberName ? `${memberName}` : "{member:name}")
@@ -9,7 +9,7 @@
.replace("{memberCount:bots}", bots ? `${bots}` : "{memberCount:bots}")
.replace("{memberCount:humans}", (memberCount && bots) ? `${memberCount - bots}` : "{memberCount:humans}");
- return str
+ return str;
}
export default convertCurlyBracketString;
diff --git a/src/utils/createLogException.ts b/src/utils/createLogException.ts
index 0223d2f..c62a824 100644
--- a/src/utils/createLogException.ts
+++ b/src/utils/createLogException.ts
@@ -3,6 +3,6 @@
export default function (guild: string, channel: string, message: string) {
client.noLog.push(`${guild}/${channel}/${message}`);
setTimeout(() => {
- client.noLog = client.noLog.filter((i) => {return i !== `${guild}/${channel}/${message}`});
+ client.noLog = client.noLog.filter((i) => {return i !== `${guild}/${channel}/${message}`;});
}, 500);
}
\ No newline at end of file
diff --git a/src/utils/database.ts b/src/utils/database.ts
index 8a5ca6f..cffdf04 100644
--- a/src/utils/database.ts
+++ b/src/utils/database.ts
@@ -1,57 +1,68 @@
-import Discord from 'discord.js';
-import { Collection, MongoClient } from 'mongodb';
-import structuredClone from '@ungap/structured-clone';
-import config from '../config/main.json' assert {type: 'json'};
+import type Discord from "discord.js";
+import { Collection, MongoClient } from "mongodb";
+// eslint-disable-next-line @typescript-eslint/ban-ts-comment
+// @ts-ignore
+import structuredClone from "@ungap/structured-clone";
+import config from "../config/main.json" assert {type: "json"};
const mongoClient = new MongoClient(config.mongoUrl);
-await mongoClient.connect()
+await mongoClient.connect();
const database = mongoClient.db("Nucleus");
-
-export const Entry = data => {
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+export const Entry = (data: any) => {
data = data ?? {};
- data.getKey = key => data[key]
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ data.getKey = (key: any) => data[key];
return {
- get(target, prop, receiver) {
- let dataToReturn = data[prop]
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ get(target: Record<string, any>, prop: string, receiver: any) {
+ let dataToReturn = data[prop];
if (dataToReturn === null ) return Reflect.get(target, prop, receiver);
if (typeof dataToReturn === "object" && !Array.isArray(dataToReturn)) dataToReturn = new Proxy(
Reflect.get(target, prop, receiver),
- Entry(dataToReturn),
- )
+ Entry(dataToReturn)
+ );
return dataToReturn ?? Reflect.get(target, prop, receiver);
}
- }
-}
+ };
+};
export class Guilds {
guilds: Collection<GuildConfig>;
- defaultData: GuildConfig;
- async setup() {
+ defaultData: GuildConfig | null;
+
+ constructor() {
this.guilds = database.collection<GuildConfig>("guilds");
- this.defaultData = (await import("../config/default.json", { assert: { type: "json" }})).default as unknown as GuildConfig;
+ this.defaultData = null;
return this;
}
+ async setup() {
+ this.defaultData = (await import("../config/default.json", { assert: { type: "json" }})).default as unknown as GuildConfig;
+ }
+
async read(guild: string) {
- let entry = await this.guilds.findOne({ id: guild });
- return new Proxy(structuredClone(this.defaultData), Entry(entry)) as unknown as GuildConfig
+ const entry = await this.guilds.findOne({ id: guild });
+ return new Proxy(structuredClone(this.defaultData), Entry(entry)) as unknown as GuildConfig;
}
async write(guild: string, set: object | null, unset: string[] | string = []) {
- let uo = {}
- if (!Array.isArray(unset)) unset = [unset]
- for (let key of unset) {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const uo: Record<string, any> = {};
+ if (!Array.isArray(unset)) unset = [unset];
+ for (const key of unset) {
uo[key] = null;
}
- let out = {$set: {}, $unset: {}}
+ const out = {$set: {}, $unset: {}};
if (set) out["$set"] = set;
if (unset.length) out["$unset"] = uo;
await this.guilds.updateOne({ id: guild }, out, { upsert: true });
}
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
async append(guild: string, key: string, value: any) {
if (Array.isArray(value)) {
await this.guilds.updateOne({ id: guild }, {
@@ -64,8 +75,9 @@
}
}
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
async remove(guild: string, key: string, value: any, innerKey?: string | null) {
- console.log(Array.isArray(value))
+ console.log(Array.isArray(value));
if (innerKey) {
await this.guilds.updateOne({ id: guild }, {
$pull: { [key]: { [innerKey]: { $eq: value } } }
@@ -111,7 +123,7 @@
}
async read(guild: string, user: string, year: number) {
- let entry = (await this.histories.find({
+ const entry = (await this.histories.find({
guild: guild,
user: user,
occurredAt: {
@@ -141,7 +153,7 @@
}
async read(guild: string, user: string) {
- let entry = await this.modNotes.findOne({ guild: guild, user: user });
+ const entry = await this.modNotes.findOne({ guild: guild, user: user });
return entry?.note ?? null;
}
}
@@ -155,7 +167,7 @@
}
async hasPremium(guild: string) {
- let entry = await this.premium.findOne({ appliesTo: { $in: [guild] } });
+ const entry = await this.premium.findOne({ appliesTo: { $in: [guild] } });
return entry !== null;
}
}
@@ -186,11 +198,7 @@
},
invite: {
enabled: boolean,
- allowed: {
- users: string[],
- channels: string[],
- roles: string[]
- }
+ channels: string[]
},
pings: {
mass: number,
@@ -215,7 +223,7 @@
channel: string | null,
message: string | null,
}
- stats: {}
+ stats: Record<string, {name: string, enabled: boolean}>
logging: {
logs: {
enabled: boolean,
@@ -227,7 +235,7 @@
},
attachments: {
channel: string | null,
- saved: {} // {channelID+messageID: log url (string)}
+ saved: Record<string, string>
}
}
verify: {
@@ -292,8 +300,8 @@
}[]
}[]
}
- tags: {}
-};
+ tags: Record<string, string>
+}
export interface HistorySchema {
type: string,
diff --git a/src/utils/defaultEmbeds.ts b/src/utils/defaultEmbeds.ts
index e799307..ce6edc1 100644
--- a/src/utils/defaultEmbeds.ts
+++ b/src/utils/defaultEmbeds.ts
@@ -1,9 +1,9 @@
-import EmojiEmbed from "./generateEmojiEmbed.js"
+import EmojiEmbed from "./generateEmojiEmbed.js";
export const LoadingEmbed = [new EmojiEmbed()
.setTitle("Loading")
.setDescription("One moment...")
.setStatus("Danger")
.setEmoji("NUCLEUS.LOADING")
-]
+];
diff --git a/src/utils/dualCollector.ts b/src/utils/dualCollector.ts
index 67cef5c..c785d0a 100644
--- a/src/utils/dualCollector.ts
+++ b/src/utils/dualCollector.ts
@@ -1,21 +1,19 @@
-import Discord from 'discord.js';
-import client from './client.js';
-import EmojiEmbed from "./generateEmojiEmbed.js";
+import Discord from "discord.js";
+import client from "./client.js";
export default async function (m, interactionFilter, messageFilter) {
let out;
try {
- out = await new Promise((resolve, reject) => {
- let mes, int;
- mes = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 300000})
- .on("collect", (m) => { resolve(m); })
- int = m.channel.createMessageCollector({filter: (m) => messageFilter(m), time: 300000})
- .then("collect", (m) => { try {m.delete();} catch {}; resolve(m); })
- mes.on("end", () => { int.stop(); })
- int.on("end", () => { mes.stop(); })
- })
+ out = await new Promise((resolve, _reject) => {
+ const mes = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 300000})
+ .on("collect", (m) => { resolve(m); });
+ const int = m.channel.createMessageCollector({filter: (m) => messageFilter(m), time: 300000})
+ .then("collect", (m) => { try {m.delete();} catch (e) { client._error(e); } resolve(m); });
+ mes.on("end", () => { int.stop(); });
+ int.on("end", () => { mes.stop(); });
+ });
} catch(e) {
- console.log(e)
+ console.log(e);
return null;
}
@@ -25,24 +23,23 @@
export async function modalInteractionCollector(m, modalFilter, interactionFilter) {
let out;
try {
- out = await new Promise((resolve, reject) => {
- let mod, int;
- int = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 300000})
- .on("collect", (m) => { resolve(m); })
- mod = new Discord.InteractionCollector(
+ out = await new Promise((resolve, _reject) => {
+ const int = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 300000})
+ .on("collect", (m) => { resolve(m); });
+ const mod = new Discord.InteractionCollector(
client, {
filter: (m) => modalFilter(m),
time: 300000
})
.on("collect", async (m) => {
int.stop();
- (m as Discord.ModalSubmitInteraction).deferUpdate()
- resolve((m as Discord.ModalSubmitInteraction)); })
- int.on("end", () => { mod.stop(); })
- mod.on("end", () => { int.stop(); })
- })
+ (m as Discord.ModalSubmitInteraction).deferUpdate();
+ resolve((m as Discord.ModalSubmitInteraction)); });
+ int.on("end", () => { mod.stop(); });
+ mod.on("end", () => { int.stop(); });
+ });
} catch(e) {
- console.log(e)
+ console.log(e);
return null;
}
return out;
diff --git a/src/utils/eventScheduler.ts b/src/utils/eventScheduler.ts
index 396b202..cde178f 100644
--- a/src/utils/eventScheduler.ts
+++ b/src/utils/eventScheduler.ts
@@ -1,39 +1,39 @@
import { Agenda } from "agenda/es.js";
-import client from './client.js';
-import * as fs from 'fs';
-import * as path from 'path';
-import config from '../config/main.json' assert {type: 'json'};
+import client from "./client.js";
+import * as fs from "fs";
+import * as path from "path";
+import config from "../config/main.json" assert {type: "json"};
class EventScheduler {
private agenda: Agenda;
constructor() {
- this.agenda = new Agenda({db: {address: config.mongoUrl + "Nucleus", collection: 'eventScheduler'}})
+ this.agenda = new Agenda({db: {address: config.mongoUrl + "Nucleus", collection: "eventScheduler"}});
this.agenda.define("unmuteRole", async (job: Agenda.job) => {
- let guild = await client.guilds.fetch(job.attrs.data.guild);
- let user = await guild.members.fetch(job.attrs.data.user);
- let role = await guild.roles.fetch(job.attrs.data.role);
+ 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) => {
- fs.rm(path.resolve("dist/utils/temp", job.attrs.data.fileName), (err) => {})
+ fs.rm(path.resolve("dist/utils/temp", job.attrs.data.fileName), client._error);
await job.remove();
- })
+ });
this.agenda.define("naturalUnmute", async (job: Agenda.job) => {
- const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger
- let guild = await client.guilds.fetch(job.attrs.data.guild);
- let user = await guild.members.fetch(job.attrs.data.user);
- if (user.communicationDisabledUntil === null) return
+ 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);
+ if (user.communicationDisabledUntil === null) return;
try { await client.database.history.create(
"unmute", user.guild.id, user.user, null, null, null, null
- )} catch {}
- let data = {
+ );} catch (e) { client._error(e); }
+ const data = {
meta: {
- type: 'memberUnmute',
- displayName: 'Unmuted',
- calculateType: 'guildMemberPunish',
+ type: "memberUnmute",
+ displayName: "Unmuted",
+ calculateType: "guildMemberPunish",
color: NucleusColors.green,
emoji: "PUNISH.MUTE.GREEN",
timestamp: new Date().getTime()
@@ -47,23 +47,25 @@
hidden: {
guild: guild.id
}
- }
+ };
log(data);
- })
+ });
}
async start() {
- await new Promise(resolve => this.agenda.once('ready', resolve));
- this.agenda.start()
- return this
+ await new Promise(resolve => this.agenda.once("ready", resolve));
+ this.agenda.start();
+ return this;
}
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
async schedule(name: string, time: string, data: any) {
- await this.agenda.schedule(time, name, data)
+ await this.agenda.schedule(time, name, data);
}
- cancel(name: string, data: Object) {
- this.agenda.cancel({name, data})
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ cancel(name: string, data: any) {
+ this.agenda.cancel({name, data});
}
}
diff --git a/src/utils/generateEmojiEmbed.ts b/src/utils/generateEmojiEmbed.ts
index 8fe594b..7587db7 100644
--- a/src/utils/generateEmojiEmbed.ts
+++ b/src/utils/generateEmojiEmbed.ts
@@ -1,16 +1,17 @@
-import Discord, { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js";
+import { MessageEmbed } from "discord.js";
import getEmojiByName from "./getEmojiByName.js";
const colors = {
"Danger": 0xF27878,
"Warning": 0xF2D478,
"Success": 0x68D49E
-}
+};
class EmojiEmbed extends MessageEmbed {
_title: string;
_emoji: string;
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// This *is* meant to be an accessor rather than a property
get title() {
@@ -21,9 +22,9 @@
this._title = title;
}
- 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 }
+ 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; }
}
export default EmojiEmbed;
\ No newline at end of file
diff --git a/src/utils/generateKeyValueList.ts b/src/utils/generateKeyValueList.ts
index 1a76fa7..ecb9780 100644
--- a/src/utils/generateKeyValueList.ts
+++ b/src/utils/generateKeyValueList.ts
@@ -2,17 +2,17 @@
"ID",
"NSFW",
"URL"
-]
+];
export function capitalize(s: string) {
- s = s.replace(/([A-Z])/g, ' $1');
+ s = s.replace(/([A-Z])/g, " $1");
s = s.split(" ").map(word => {
return forceCaps.includes(word.toUpperCase()) ? word.toUpperCase() : word[0]
.toUpperCase() + word.slice(1)
.toLowerCase()
- .replace("discord", "Discord")
+ .replace("discord", "Discord");
}).join(" ");
- return s
+ return s;
}
export function toCapitals(s: string) {
@@ -22,8 +22,8 @@
function keyValueList(data) {
let out = "";
Object.entries(data).map(([key, value]) => {
- out += `**${capitalize(key)}:** ${value}\n`
- })
+ out += `**${capitalize(key)}:** ${value}\n`;
+ });
return out;
}
diff --git a/src/utils/getEmojiByName.ts b/src/utils/getEmojiByName.ts
index 80410df..63b2042 100644
--- a/src/utils/getEmojiByName.ts
+++ b/src/utils/getEmojiByName.ts
@@ -1,8 +1,8 @@
-import emojis from '../config/emojis.json' assert {type: 'json'};
+import emojis from "../config/emojis.json" assert {type: "json"};
function getEmojiByName(name: string, format?: string): string {
- let split = name.split(".");
- let id = emojis
+ const split = name.split(".");
+ let id = emojis;
split.forEach(part => {
id = id[part];
});
@@ -11,9 +11,9 @@
return id.toString();
}
if (id === undefined) {
- return `<a:_:946346549271732234>`
+ return "<a:_:946346549271732234>";
} else if (id.toString().startsWith("a")) {
- return `<a:_:${id.toString().slice(1, id.toString().length)}>`
+ return `<a:_:${id.toString().slice(1, id.toString().length)}>`;
}
return `<:_:${id}>`;
}
diff --git a/src/utils/log.ts b/src/utils/log.ts
index 0c6aa89..34b24c6 100644
--- a/src/utils/log.ts
+++ b/src/utils/log.ts
@@ -1,33 +1,32 @@
-import * as fs from 'fs';
-import * as Discord from 'discord.js';
-import getEmojiByName from './getEmojiByName.js';
-import { toHexArray } from './calculate.js';
-import { promisify } from 'util';
-import generateKeyValueList from './generateKeyValueList.js';
-import client from './client.js';
+import * as Discord from "discord.js";
+import getEmojiByName from "./getEmojiByName.js";
+import { toHexArray } from "./calculate.js";
+import { promisify } from "util";
+import generateKeyValueList from "./generateKeyValueList.js";
+import client from "./client.js";
const wait = promisify(setTimeout);
export class Logger {
renderUser(user: Discord.User | string) {
- if (typeof user === 'string') return `${user} [<@${user}>]`;
+ if (typeof user === "string") return `${user} [<@${user}>]`;
return `${user.username} [<@${user.id}>]`;
}
renderTime(t: number) {
- t = Math.floor(t /= 1000)
+ t = Math.floor(t /= 1000);
return `<t:${t}:D> at <t:${t}:T>`;
}
renderDelta(t: number) {
- t = Math.floor(t /= 1000)
+ t = Math.floor(t /= 1000);
return `<t:${t}:R> (<t:${t}:D> at <t:${t}:T>)`;
}
renderNumberDelta(num1, num2) {
- let delta = num2 - num1;
- return `${num1} -> ${num2} (${delta > 0 ? '+' : ''}${delta})`;
+ const delta = num2 - num1;
+ return `${num1} -> ${num2} (${delta > 0 ? "+" : ""}${delta})`;
}
entry(value, displayValue) {
- return { value: value, displayValue: displayValue }
+ return { value: value, displayValue: displayValue };
}
renderChannel(channel: Discord.GuildChannel | Discord.ThreadChannel) {
return `${channel.name} [<#${channel.id}>]`;
@@ -36,43 +35,45 @@
return `${role.name} [<@&${role.id}>]`;
}
renderEmoji(emoji: Discord.GuildEmoji) {
- return `<${emoji.animated ? 'a' : ''}:${emoji.name}:${emoji.id}> [\`:${emoji.name}:\`]`;
+ return `<${emoji.animated ? "a" : ""}:${emoji.name}:${emoji.id}> [\`:${emoji.name}:\`]`;
}
public readonly NucleusColors = {
red: 0xF27878,
yellow: 0xF2D478,
- green: 0x68D49E,
+ green: 0x68D49E
- }
+ };
async getAuditLog(guild: Discord.Guild, event): Promise<Discord.GuildAuditLogsEntry[]>{
- await wait(250)
- let auditLog = await guild.fetchAuditLogs({type: event});
+ await wait(250);
+ const auditLog = await guild.fetchAuditLogs({type: event});
return auditLog as unknown as Discord.GuildAuditLogsEntry[];
}
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
async log(log: any): Promise<void> {
- let config = await client.database.guilds.read(log.hidden.guild);
+ const config = await client.database.guilds.read(log.hidden.guild);
if (!config.logging.logs.enabled) return;
if (!(log.meta.calculateType === true)) {
- if(!toHexArray(config.logging.logs.toLog).includes(log.meta.calculateType)) return console.log('Not logging this type of event');
+ if(!toHexArray(config.logging.logs.toLog).includes(log.meta.calculateType)) return console.log("Not logging this type of event");
}
if (config.logging.logs.channel) {
- let channel = await client.channels.fetch(config.logging.logs.channel) as Discord.TextChannel;
- let description = {};
+ const channel = await client.channels.fetch(config.logging.logs.channel) as Discord.TextChannel;
+ const description = {};
Object.entries(log.list).map(entry => {
- let key = entry[0];
- let value:any = entry[1];
+ const key = entry[0];
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const value: any = entry[1];
if(value.displayValue) {
description[key] = value.displayValue;
} else {
description[key] = value;
}
- })
+ });
if (channel) {
log.separate = log.separate || {};
- let embed = new Discord.MessageEmbed()
+ const embed = new Discord.MessageEmbed()
.setTitle(`${getEmojiByName(log.meta.emoji)} ${log.meta.displayName}`)
.setDescription(
(log.separate.start ? log.separate.start + "\n" : "") +
@@ -88,4 +89,4 @@
}
-export default {}
+export default {};
diff --git a/src/utils/memory.ts b/src/utils/memory.ts
index a06705b..070bd7f 100644
--- a/src/utils/memory.ts
+++ b/src/utils/memory.ts
@@ -1,29 +1,30 @@
import client from "./client.js";
class Memory {
- memory: {};
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ memory: Record<string, any>;
constructor() {
this.memory = {};
setInterval(() => {
- for (let guild in this.memory) {
+ for (const guild in this.memory) {
if (this.memory[guild].updated + 15 * 60 * 1000 < Date.now()) {
delete this.memory[guild];
}
}
- }, 1000 * 60 * 30)
+ }, 1000 * 60 * 30);
}
async readGuildInfo(guild: string): Promise<object> {
if (!this.memory[guild]) {
- let guildData = await client.database.guilds.read(guild);
+ const guildData = await client.database.guilds.read(guild);
this.memory[guild] = {
lastUpdated: Date.now(),
filters: guildData.filters,
logging: guildData.logging,
- tickets: guildData.tickets,
+ tickets: guildData.tickets
};
- };
+ }
return this.memory[guild];
}
}
diff --git a/src/utils/plurals.ts b/src/utils/plurals.ts
index 48b889c..619ced2 100644
--- a/src/utils/plurals.ts
+++ b/src/utils/plurals.ts
@@ -1,7 +1,7 @@
-function addPlural(amount: any, unit: string) {
+function addPlural(amount: number | string, unit: string) {
amount = amount.toString();
- if (amount === '1') return `${amount} ${unit}`
- return `${amount} ${unit}s`
+ if (amount === "1") return `${amount} ${unit}`;
+ return `${amount} ${unit}s`;
}
export default addPlural;
\ No newline at end of file
diff --git a/src/utils/singleNotify.ts b/src/utils/singleNotify.ts
index f29d775..44bb2d0 100644
--- a/src/utils/singleNotify.ts
+++ b/src/utils/singleNotify.ts
@@ -1,29 +1,29 @@
-import client from './client.js';
+import client from "./client.js";
import EmojiEmbed from "./generateEmojiEmbed.js";
-let severities = {
+const severities = {
"Critical": "Danger",
"Warning": "Warning",
"Info": "Success"
-}
+};
export default async function(type: string, guild: string, message: string | true, severity?: string) {
- let data = await client.database.guilds.read(guild);
+ const data = await client.database.guilds.read(guild);
if (message === true) {
return await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: false});
}
if (data.singleEventNotifications[type]) return;
await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: true});
try {
- let channel = await client.channels.fetch(data.logging.staff.channel);
+ const channel = await client.channels.fetch(data.logging.staff.channel);
if (!channel) return;
await channel.send({embeds: [new EmojiEmbed()
.setTitle(`${severity} notification`)
.setDescription(message)
.setStatus(severities[severity])
.setEmoji("CONTROL.BLOCKCROSS")
- ]})
+ ]});
} catch (err) {
- console.error(err)
+ console.error(err);
}
}
diff --git a/src/utils/temp/generateFileName.ts b/src/utils/temp/generateFileName.ts
index f9662ad..8a219b7 100644
--- a/src/utils/temp/generateFileName.ts
+++ b/src/utils/temp/generateFileName.ts
@@ -1,17 +1,17 @@
-import * as fs from 'fs';
-import * as crypto from 'crypto';
-import client from '../client.js';
-import * as path from 'path'
-import {fileURLToPath} from 'url';
+import * as fs from "fs";
+import * as crypto from "crypto";
+import client from "../client.js";
+import * as path from "path";
+import {fileURLToPath} from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default function generateFileName(ending: string): string {
- let fileName = crypto.randomBytes(35).toString('hex');
- fileName = fileName.replace(/([a-zA-Z0-9]{8})/g, '$1-');
+ let fileName = crypto.randomBytes(35).toString("hex");
+ fileName = fileName.replace(/([a-zA-Z0-9]{8})/g, "$1-");
if (fs.existsSync(`./${fileName}`)) {
fileName = generateFileName(ending);
}
client.database.eventScheduler.schedule("deleteFile", new Date().getTime() + (60 * 1000), {fileName: `${fileName}.${ending}`});
- return path.join(__dirname, fileName + '.' + ending);
+ return path.join(__dirname, fileName + "." + ending);
}