Still got errors and warnings, mostly the same and easy to fix
diff --git a/src/reflex/guide.ts b/src/reflex/guide.ts
index 517d7f4..640ec13 100644
--- a/src/reflex/guide.ts
+++ b/src/reflex/guide.ts
@@ -1,16 +1,15 @@
-import { LoadingEmbed } from './../utils/defaultEmbeds.js';
-import { SelectMenuOption } from '@discordjs/builders';
+import { LoadingEmbed } from "./../utils/defaultEmbeds.js";
+import { SelectMenuOption } from "@discordjs/builders";
import Discord, { MessageActionRow, MessageButton } from "discord.js";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
import getEmojiByName from "../utils/getEmojiByName.js";
import createPageIndicator from "../utils/createPageIndicator.js";
-import client from "../utils/client.js";
class Embed {
embed: Discord.MessageEmbed;
title: string;
- description: string = "";
- pageId: number = 0;
+ description = "";
+ pageId = 0;
setEmbed(embed: Discord.MessageEmbed) { this.embed = embed; return this; }
setTitle(title: string) { this.title = title; return this; }
setDescription(description: string) { this.description = description; return this; }
@@ -20,7 +19,7 @@
export default async (guild, interaction?) => {
let c = guild.publicUpdatesChannel ? guild.publicUpdatesChannel : guild.systemChannel;
c = c ? c : guild.channels.cache.find(ch => ch.type === "GUILD_TEXT" && ch.permissionsFor(guild.roles.everyone).has("SEND_MESSAGES") && ch.permissionsFor(guild.me).has("EMBED_LINKS"));
- let pages = [
+ const pages = [
new Embed()
.setEmbed(new EmojiEmbed()
.setTitle("Welcome to Nucleus")
@@ -62,8 +61,8 @@
`**${getEmojiByName("PUNISH.BAN.RED")} Ban:** The user is removed from the server, and they are unable to rejoin.\n` +
`**${getEmojiByName("PUNISH.BAN.GREEN")} Unban:** The user is able to rejoin the server.`
)
- .setEmoji("PUNISH.BAN.RED")
- .setStatus("Danger")
+ .setEmoji("PUNISH.BAN.RED")
+ .setStatus("Danger")
).setTitle("Moderation").setDescription("Basic moderation commands").setPageId(2),
new Embed()
.setEmbed(new EmojiEmbed()
@@ -124,53 +123,53 @@
)
.setEmoji("NUCLEUS.COMMANDS.LOCK")
.setStatus("Danger")
- ).setTitle("Premium").setDescription("Premium features").setPageId(7),
- ]
+ ).setTitle("Premium").setDescription("Premium features").setPageId(7)
+ ];
let m;
if (interaction) { m = await interaction.reply({embeds: LoadingEmbed, fetchReply: true, ephemeral: true}); }
else { m = await c.send({embeds: LoadingEmbed }); }
let page = 0;
- let f = async (component) => {
+ const f = async (component) => {
return (component.member as Discord.GuildMember).permissions.has("MANAGE_GUILD");
- }
+ };
let selectPaneOpen = false;
while (true) {
- let selectPane = []
+ let selectPane = [];
if (selectPaneOpen) {
- let options = [];
+ const options = [];
pages.forEach(embed => {
options.push(new SelectMenuOption({
label: embed.title,
value: embed.pageId.toString(),
- description: embed.description || "",
- }))
- })
+ description: embed.description || ""
+ }));
+ });
selectPane = [new MessageActionRow().addComponents([
new Discord.MessageSelectMenu()
.addOptions(options)
.setCustomId("page")
.setMaxValues(1)
.setPlaceholder("Choose a page...")
- ])]
+ ])];
}
- let components = selectPane.concat([new MessageActionRow().addComponents([
+ const components = selectPane.concat([new MessageActionRow().addComponents([
new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(page === 0),
new MessageButton().setCustomId("select").setEmoji(getEmojiByName("CONTROL.MENU", "id")).setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY").setDisabled(false),
new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(page === pages.length - 1)
- ])])
+ ])]);
if (interaction) {
- let em = new Discord.MessageEmbed(pages[page].embed)
+ const em = new Discord.MessageEmbed(pages[page].embed);
em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page));
await interaction.editReply({
embeds: [em],
components: components
});
} else {
- let em = new Discord.MessageEmbed(pages[page].embed)
+ const em = new Discord.MessageEmbed(pages[page].embed);
em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page));
await m.edit({
embeds: [em],
@@ -178,11 +177,11 @@
fetchReply: true
});
}
- let i
+ let i;
try {
- i = await m.awaitMessageComponent({filter: interaction ? () => { return true } : f, time: 300000});
- } catch(e) { break }
- i.deferUpdate()
+ i = await m.awaitMessageComponent({filter: interaction ? () => { return true; } : f, time: 300000});
+ } catch(e) { break; }
+ i.deferUpdate();
if (i.component.customId === "left") {
if (page > 0) page--;
selectPaneOpen = false;
@@ -196,9 +195,9 @@
selectPaneOpen = false;
} else {
if (interaction) {
- let em = new Discord.MessageEmbed(pages[page].embed)
+ const em = new Discord.MessageEmbed(pages[page].embed);
em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page));
- em.setFooter({text: "Message closed"})
+ em.setFooter({text: "Message closed"});
interaction.editReply({embeds: [em], components: [new MessageActionRow().addComponents([
new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(true),
new MessageButton().setCustomId("select").setEmoji(getEmojiByName("CONTROL.MENU", "id")).setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY").setDisabled(true),
@@ -211,7 +210,7 @@
}
}
if (interaction) {
- let em = new Discord.MessageEmbed(pages[page].embed)
+ const em = new Discord.MessageEmbed(pages[page].embed);
em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)).setFooter({text: "Message timed out"});
await interaction.editReply({
embeds: [em],
@@ -222,7 +221,7 @@
])]
});
} else {
- let em = new Discord.MessageEmbed(pages[page].embed)
+ const em = new Discord.MessageEmbed(pages[page].embed);
em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)).setFooter({text: "Message timed out"});
await m.edit({
embeds: [em],
@@ -233,4 +232,4 @@
])]
});
}
-}
+};
diff --git a/src/reflex/scanners.ts b/src/reflex/scanners.ts
index 3b80816..435ce4c 100644
--- a/src/reflex/scanners.ts
+++ b/src/reflex/scanners.ts
@@ -1,33 +1,36 @@
-import * as us from 'unscan'
-import fetch from 'node-fetch'
-import { writeFileSync } from 'fs'
-import generateFileName from '../utils/temp/generateFileName.js'
-import Tesseract from 'node-tesseract-ocr';
+// eslint-disable-next-line @typescript-eslint/ban-ts-comment
+// @ts-ignore
+import * as us from "unscan";
+import fetch from "node-fetch";
+import { writeFileSync } from "fs";
+import generateFileName from "../utils/temp/generateFileName.js";
+import Tesseract from "node-tesseract-ocr";
+import type Discord from "discord.js";
interface NSFWSchema { nsfw: boolean }
interface MalwareSchema { safe: boolean }
export async function testNSFW(link: string): Promise<NSFWSchema> {
- let p = await saveAttachment(link)
- let result = await us.nsfw.file(p)
- return result
+ const p = await saveAttachment(link);
+ const result = await us.nsfw.file(p);
+ return result;
}
export async function testMalware(link: string): Promise<MalwareSchema> {
- let p = await saveAttachment(link)
- let result = await us.malware.file(p)
- return result
+ const p = await saveAttachment(link);
+ const result = await us.malware.file(p);
+ return result;
}
-export async function saveAttachment(link): Promise<string> {
- const image = (await (await fetch(link)).buffer()).toString('base64')
- let fileName = generateFileName(link.split('/').pop().split('.').pop())
- writeFileSync(fileName, image, 'base64')
- return fileName
+export async function saveAttachment(link: string): Promise<string> {
+ const image = (await (await fetch(link)).buffer()).toString("base64");
+ const fileName = generateFileName((link.split("/").pop() as string).split(".").pop() as string);
+ writeFileSync(fileName, image, "base64");
+ return fileName;
}
-export async function testLink(link: string): Promise<unknown> {
- return await us.link.scan(link)
+export async function testLink(link: string): Promise<{safe: boolean, tags: string[]}> {
+ return await us.link.scan(link);
}
@@ -49,71 +52,76 @@
"SCAMS": "Sites which are designed to trick you into doing something.",
"TORRENT": "Websites that download torrent files.",
"HATE": "Websites that spread hate towards groups or individuals.",
- "JUNK": "Websites that are designed to make you waste time.",
-}
+ "JUNK": "Websites that are designed to make you waste time."
+};
export { linkTypes };
-export async function LinkCheck(message): Promise<string[]> {
- let links = message.content.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi) ?? []
- let detections = []
- const promises = links.map(async element => {
+export async function LinkCheck(message: Discord.Message): Promise<string[]> {
+ const links = message.content.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi) ?? [];
+ const detections: {tags: string[], safe: boolean}[] = [];
+ const promises: Promise<void>[] = links.map(async element => {
+ let returned;
try {
- if (element.match(/https?:\/\/[a-zA-Z]+\.?discord(app)?\.(com|net)\/?/)) return // Also matches discord.net, not enough of a bug
- element = await testLink(element)
- } catch {}
- detections.push({tags: element.tags || [], safe: element.safe})
+ if (element.match(/https?:\/\/[a-zA-Z]+\.?discord(app)?\.(com|net)\/?/)) return; // Also matches discord.net, not enough of a bug
+ returned = await testLink(element);
+ } catch {
+ detections.push({tags: [], safe: true});
+ return;
+ }
+ if (returned) { detections.push({tags: returned.tags || [], safe: returned.safe}); }
+ else { detections.push({tags: [], safe: true}); }
});
await Promise.all(promises);
- let detectionsTypes = detections.map(element => {
- let type = Object.keys(linkTypes).find(type => element.tags.includes(type))
- if (type) return type
+ const detectionsTypes = detections.map(element => {
+ const type = Object.keys(linkTypes).find(type => element.tags.includes(type));
+ if (type) return type;
// if (!element.safe) return "UNSAFE"
- return undefined
- }).filter(element => element !== undefined)
- return detectionsTypes
+ return undefined;
+ }).filter(element => element !== undefined);
+ return detectionsTypes as string[];
}
-export async function NSFWCheck(element): Promise<boolean> {
+export async function NSFWCheck(element: string): Promise<boolean> {
try {
- let test = (await testNSFW(element))
- return test.nsfw
+ const test = (await testNSFW(element));
+ return test.nsfw;
} catch {
- return false
+ return false;
}
}
-export async function SizeCheck(element): Promise<boolean> {
- if (element.height === undefined || element.width === undefined) return true
- if (element.height < 20 || element.width < 20) return false
- return true
+export async function SizeCheck(element: {height: number | null, width: number | null}): Promise<boolean> {
+ if (element.height === null || element.width === null) return true;
+ if (element.height < 20 || element.width < 20) return false;
+ return true;
}
-export async function MalwareCheck(element): Promise<boolean> {
+export async function MalwareCheck(element: string): Promise<boolean> {
try {
- return (await testMalware(element)).safe
+ return (await testMalware(element)).safe;
} catch {
- return true
+ return true;
}
}
-export function TestString(string, soft, strict): object | null {
- for(let word of strict || []) {
+export function TestString(string: string, soft: string[], strict: string[]): object | null {
+ for(const word of strict || []) {
if (string.toLowerCase().includes(word)) {
- return {word: word, type: "strict"}
+ return {word: word, type: "strict"};
}
}
- for(let word of soft) {
- for(let word2 of string.match(/[a-z]+/gi) || []) {
+ for(const word of soft) {
+ for(const word2 of string.match(/[a-z]+/gi) || []) {
if (word2 === word) {
- return {word: word, type: "strict"}
+ return {word: word, type: "strict"};
}
}
}
- return null
+ return null;
}
-export async function TestImage(url): Promise<string | null> {
- let text = await Tesseract.recognize(url, {lang: "eng", oem: 1, psm: 3})
+export async function TestImage(url: string): Promise<string | null> {
+ const text = await Tesseract.recognize(url, {lang: "eng", oem: 1, psm: 3});
return text;
}
diff --git a/src/reflex/statsChannelUpdate.ts b/src/reflex/statsChannelUpdate.ts
index b306ecc..7301a60 100644
--- a/src/reflex/statsChannelUpdate.ts
+++ b/src/reflex/statsChannelUpdate.ts
@@ -1,38 +1,38 @@
-import convertCurlyBracketString from '../utils/convertCurlyBracketString.js'
-import singleNotify from '../utils/singleNotify.js';
-import client from '../utils/client.js';
+import convertCurlyBracketString from "../utils/convertCurlyBracketString.js";
+import singleNotify from "../utils/singleNotify.js";
+import client from "../utils/client.js";
interface PropSchema { enabled: boolean, name: string }
export async function callback(_, member) {
- let guild = await client.guilds.fetch(member.guild.id)
- let config = await client.database.guilds.read(guild.id);
+ const guild = await client.guilds.fetch(member.guild.id);
+ const config = await client.database.guilds.read(guild.id);
Object.entries(config.getKey("stats")).forEach(async ([channel, props]) => {
if ((props as PropSchema).enabled) {
- let string = (props as PropSchema).name
- if (!string) return
- string = await convertCurlyBracketString(string, member.id, member.displayName, guild.name, guild.members)
+ let string = (props as PropSchema).name;
+ if (!string) return;
+ string = await convertCurlyBracketString(string, member.id, member.displayName, guild.name, guild.members);
let fetchedChannel;
try {
- fetchedChannel = await guild.channels.fetch(channel)
- } catch (e) { fetchedChannel = null }
+ fetchedChannel = await guild.channels.fetch(channel);
+ } catch (e) { fetchedChannel = null; }
if (!fetchedChannel) {
- let deleted = config.getKey("stats")[channel]
- console.log(`stats.${channel}`)
- console.log(guild.id)
- await client.database.guilds.write(guild.id, null, `stats.${channel}`)
+ const deleted = config.getKey("stats")[channel];
+ console.log(`stats.${channel}`);
+ console.log(guild.id);
+ await client.database.guilds.write(guild.id, null, `stats.${channel}`);
return singleNotify(
"statsChannelDeleted",
guild.id,
"One or more of your stats channels have been deleted. Please use `/settings stats` if you wish to add the channel again.\n" +
`The channels name was: ${deleted.name}`,
"Critical"
- )
+ );
}
try {
- await fetchedChannel.setName(string.slice(0, 100))
+ await fetchedChannel.setName(string.slice(0, 100));
} catch (e) {
- console.error(e)
+ console.error(e);
}
}
});
diff --git a/src/reflex/verify.ts b/src/reflex/verify.ts
index bc7aa4f..d9fab66 100644
--- a/src/reflex/verify.ts
+++ b/src/reflex/verify.ts
@@ -1,4 +1,4 @@
-import { LoadingEmbed } from './../utils/defaultEmbeds.js';
+import { LoadingEmbed } from "./../utils/defaultEmbeds.js";
import Discord, { GuildMember } from "discord.js";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
import fetch from "node-fetch";
@@ -11,12 +11,12 @@
}
export default async function(interaction) {
- let verify = client.verify
+ const verify = client.verify;
await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true});
- let config = await client.database.guilds.read(interaction.guild.id);
+ const config = await client.database.guilds.read(interaction.guild.id);
if ((!config.verify.enabled ) || (!config.verify.role)) return interaction.editReply({embeds: [new EmojiEmbed()
.setTitle("Verify")
- .setDescription(`Verify is not enabled on this server`)
+ .setDescription("Verify is not enabled on this server")
.setFooter({text: interaction.member.permissions.has("MANAGE_GUILD") ? "You can enable it by running /settings verify" : ""})
.setStatus("Danger")
.setEmoji("CONTROL.BLOCKCROSS")
@@ -31,16 +31,16 @@
}
await interaction.editReply({embeds: [new EmojiEmbed()
.setTitle("Verify")
- .setDescription(`Checking our servers are up` + step(0))
+ .setDescription("Checking our servers are up" + step(0))
.setStatus("Warning")
.setEmoji("NUCLEUS.LOADING")
]});
try {
- let status = await fetch(client.config.baseUrl).then(res => res.status);
+ const status = await fetch(client.config.baseUrl).then(res => res.status);
if (status !== 200) {
return await interaction.editReply({embeds: [new EmojiEmbed()
.setTitle("Verify")
- .setDescription(`Our servers appear to be down, please try again later` + step(0))
+ .setDescription("Our servers appear to be down, please try again later" + step(0))
.setStatus("Danger")
.setEmoji("CONTROL.BLOCKCROSS")
]});
@@ -48,7 +48,7 @@
} catch {
return await interaction.editReply({embeds: [new EmojiEmbed()
.setTitle("Verify")
- .setDescription(`Our servers appear to be down, please try again later` + step(0))
+ .setDescription("Our servers appear to be down, please try again later" + step(0))
.setStatus("Danger")
.setEmoji("CONTROL.BLOCKCROSS")
], components: [new Discord.MessageActionRow().addComponents([
@@ -65,14 +65,14 @@
if (config.filters.images.NSFW) {
await interaction.editReply({embeds: [new EmojiEmbed()
.setTitle("Verify")
- .setDescription(`Checking your avatar is safe for work` + step(1))
+ .setDescription("Checking your avatar is safe for work" + step(1))
.setStatus("Warning")
.setEmoji("NUCLEUS.LOADING")
]});
if (await NSFWCheck((interaction.member as GuildMember).user.avatarURL({format: "png"}))) {
return await interaction.editReply({embeds: [new EmojiEmbed()
.setTitle("Verify")
- .setDescription(`Your avatar was detected as NSFW, which we do not allow in this server.\nPlease contact one of our staff members if you believe this is a mistake` + step(1))
+ .setDescription("Your avatar was detected as NSFW, which we do not allow in this server.\nPlease contact one of our staff members if you believe this is a mistake" + step(1))
.setStatus("Danger")
.setEmoji("CONTROL.BLOCKCROSS")
]});
@@ -81,14 +81,14 @@
if (config.filters.wordFilter) {
await interaction.editReply({embeds: [new EmojiEmbed()
.setTitle("Verify")
- .setDescription(`Checking your name is allowed` + step(2))
+ .setDescription("Checking your name is allowed" + step(2))
.setStatus("Warning")
.setEmoji("NUCLEUS.LOADING")
]});
if (TestString((interaction.member as Discord.GuildMember).displayName, config.filters.wordFilter.words.loose, config.filters.wordFilter.words.strict) !== null) {
return await interaction.editReply({embeds: [new EmojiEmbed()
.setTitle("Verify")
- .setDescription(`Your name contained a word we do not allow in this server.\nPlease contact one of our staff members if you believe this is a mistake` + step(2))
+ .setDescription("Your name contained a word we do not allow in this server.\nPlease contact one of our staff members if you believe this is a mistake" + step(2))
.setStatus("Danger")
.setEmoji("CONTROL.BLOCKCROSS")
]});
@@ -96,23 +96,23 @@
}
await interaction.editReply({embeds: [new EmojiEmbed()
.setTitle("Verify")
- .setDescription(`One moment...` + step(3))
+ .setDescription("One moment..." + step(3))
.setStatus("Warning")
.setEmoji("NUCLEUS.LOADING")
]});
- let code = ""
- let length = 5
- let itt = 0
+ let code = "";
+ let length = 5;
+ let itt = 0;
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
while (true) {
- itt += 1
- code = ""
+ itt += 1;
+ code = "";
for (let i = 0; i < length; i++) { code += chars.charAt(Math.floor(Math.random() * chars.length)); }
if (code in verify) continue;
if (itt > 1000) {
- itt = 0
- length += 1
- continue
+ itt = 0;
+ length += 1;
+ continue;
}
break;
}
@@ -125,10 +125,10 @@
gName: interaction.guild.name,
gIcon: interaction.guild.iconURL({format: "png"}),
interaction: interaction
- }
+ };
await interaction.editReply({embeds: [new EmojiEmbed()
.setTitle("Verify")
- .setDescription(`Looking good!\nClick the button below to get verified` + step(4))
+ .setDescription("Looking good!\nClick the button below to get verified" + step(4))
.setStatus("Success")
.setEmoji("MEMBER.JOIN")
], components: [new Discord.MessageActionRow().addComponents([new Discord.MessageButton()
diff --git a/src/reflex/welcome.ts b/src/reflex/welcome.ts
index 9be71d5..b4bc374 100644
--- a/src/reflex/welcome.ts
+++ b/src/reflex/welcome.ts
@@ -1,39 +1,37 @@
-import convertCurlyBracketString from '../utils/convertCurlyBracketString.js'
-import client from '../utils/client.js';
-import EmojiEmbed from '../utils/generateEmojiEmbed.js';
+import convertCurlyBracketString from "../utils/convertCurlyBracketString.js";
+import client from "../utils/client.js";
+import EmojiEmbed from "../utils/generateEmojiEmbed.js";
export async function callback(_, member) {
- if (member.bot) return
- let config = await client.database.guilds.read(member.guild.id);
- if (!config.welcome.enabled) return
+ if (member.bot) return;
+ const config = await client.database.guilds.read(member.guild.id);
+ if (!config.welcome.enabled) return;
if (config.welcome.channel) {
- let string = config.welcome.message
+ let string = config.welcome.message;
if (string) {
- string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members)
- if (config.welcome.channel === 'dm') {
- try {
- await member.send({
- embeds: [new EmojiEmbed()
- .setDescription(string)
- .setStatus('Success')
- ]
- })
- } catch {}
+ string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members);
+ if (config.welcome.channel === "dm") {
+ await member.send({
+ embeds: [new EmojiEmbed()
+ .setDescription(string)
+ .setStatus("Success")
+ ]
+ });
} else {
- let channel = await member.guild.channels.fetch(config.welcome.channel)
- if (channel.guild.id !== member.guild.id) return
- if (!channel) return
+ const channel = await member.guild.channels.fetch(config.welcome.channel);
+ if (channel.guild.id !== member.guild.id) return;
+ if (!channel) return;
try {
await channel.send({
embeds: [new EmojiEmbed()
.setDescription(string)
- .setStatus('Success')
+ .setStatus("Success")
],
- content: (config.welcome.ping ? `<@${config.welcome.ping}>` : '') + `<@${member.id}>`
- })
+ content: (config.welcome.ping ? `<@${config.welcome.ping}>` : "") + `<@${member.id}>`
+ });
} catch (err) {
- console.error(err) // SEN
+ console.error(err); // TODO: SEN
}
}
}