From 1e462ab654c6df6416a5fbb257172a8341f29408 Mon Sep 17 00:00:00 2001 From: pineafan Date: Tue, 7 Mar 2023 21:34:06 +0000 Subject: [PATCH] Fixed typing --- src/commands/mod/ban.ts | 11 +-- src/commands/mod/kick.ts | 7 +- src/commands/mod/mute.ts | 19 +++-- src/commands/mod/nick.ts | 76 +++++++---------- src/commands/mod/purge.ts | 3 +- src/commands/mod/warn.ts | 41 ++++----- src/commands/nucleus/stats.ts | 137 ++++++++++++++++++------------ src/commands/settings/rolemenu.ts | 2 +- src/events/guildMemberUpdate.ts | 2 + src/events/interactionCreate.ts | 27 +++--- src/events/memberJoin.ts | 2 +- src/reflex/scanners.ts | 126 +++++++++++++++++---------- src/utils/confirmationMessage.ts | 34 ++++++-- src/utils/database.ts | 4 +- 14 files changed, 279 insertions(+), 212 deletions(-) diff --git a/src/commands/mod/ban.ts b/src/commands/mod/ban.ts index 88f7b39..91e074d 100644 --- a/src/commands/mod/ban.ts +++ b/src/commands/mod/ban.ts @@ -34,7 +34,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem let deleteDays; if (!interaction.isButton()) { member = interaction.options.getMember("user") as GuildMember; - deleteDays = (interaction.options.get("delete")?.value as number | null) ?? 0 + deleteDays = (interaction.options.get("delete")?.value as number | null) ?? 0; } else { deleteDays = 0; } @@ -115,12 +115,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem new ButtonBuilder() .setStyle(ButtonStyle.Link) .setLabel(config.moderation.ban.text) - .setURL( - config.moderation.ban.link.replaceAll( - "{id}", - member.id - ) - ) + .setURL(config.moderation.ban.link.replaceAll("{id}", member.id)) ) ); } @@ -204,7 +199,7 @@ const check = (interaction: CommandInteraction | ButtonInteraction, partial: boo apply = target!; } else { apply = interaction.options.getMember("user") as GuildMember; - }; + } const memberPos = member.roles.cache.size > 1 ? member.roles.highest.position : 0; const mePos = me.roles.cache.size > 1 ? me.roles.highest.position : 0; const applyPos = apply.roles.cache.size > 1 ? apply.roles.highest.position : 0; diff --git a/src/commands/mod/kick.ts b/src/commands/mod/kick.ts index 4d325a2..4ef78c8 100644 --- a/src/commands/mod/kick.ts +++ b/src/commands/mod/kick.ts @@ -103,12 +103,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem new ButtonBuilder() .setStyle(ButtonStyle.Link) .setLabel(config.moderation.kick.text) - .setURL( - config.moderation.kick.link.replaceAll( - "{id}", - member.id - ) - ) + .setURL(config.moderation.kick.link.replaceAll("{id}", member.id)) ) ); } diff --git a/src/commands/mod/mute.ts b/src/commands/mod/mute.ts index 51ffc4d..2266a1a 100644 --- a/src/commands/mod/mute.ts +++ b/src/commands/mod/mute.ts @@ -1,5 +1,12 @@ import { LinkWarningFooter, LoadingEmbed } from "../../utils/defaults.js"; -import Discord, { CommandInteraction, GuildMember, ActionRowBuilder, ButtonBuilder, ButtonStyle, ButtonInteraction } from "discord.js"; +import Discord, { + CommandInteraction, + GuildMember, + ActionRowBuilder, + ButtonBuilder, + ButtonStyle, + ButtonInteraction +} from "discord.js"; import type { SlashCommandSubcommandBuilder } from "discord.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; import getEmojiByName from "../../utils/getEmojiByName.js"; @@ -49,7 +56,10 @@ const command = (builder: SlashCommandSubcommandBuilder) => .setRequired(false) ); -const callback = async (interaction: CommandInteraction | ButtonInteraction, member?: GuildMember): Promise => { +const callback = async ( + interaction: CommandInteraction | ButtonInteraction, + member?: GuildMember +): Promise => { if (!interaction.guild) return; const { log, NucleusColors, renderUser, entry, renderDelta } = client.logger; let time: { days: number; hours: number; minutes: number; seconds: number } | null = null; @@ -62,7 +72,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem seconds: (interaction.options.get("seconds")?.value as number | null) ?? 0 }; } else { - time = {days: 0, hours: 0, minutes: 0, seconds: 0}; + time = { days: 0, hours: 0, minutes: 0, seconds: 0 }; } if (!member) return; const config = await client.database.guilds.read(interaction.guild.id); @@ -203,8 +213,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem "appeal", "Create appeal ticket", !(await areTicketsEnabled(interaction.guild.id)), - async () => - await create(interaction.guild!, member!.user, interaction.user, reason), + async () => await create(interaction.guild!, member!.user, interaction.user, reason), "An appeal ticket will be created when Confirm is clicked", null, "CONTROL.TICKET", diff --git a/src/commands/mod/nick.ts b/src/commands/mod/nick.ts index 743579b..cfdcf47 100644 --- a/src/commands/mod/nick.ts +++ b/src/commands/mod/nick.ts @@ -1,5 +1,16 @@ import { LinkWarningFooter } from "./../../utils/defaults.js"; -import { ActionRowBuilder, ButtonBuilder, CommandInteraction, GuildMember, ButtonStyle, Message, ButtonInteraction, ModalBuilder, TextInputBuilder, TextInputStyle } from "discord.js"; +import { + ActionRowBuilder, + ButtonBuilder, + CommandInteraction, + GuildMember, + ButtonStyle, + Message, + ButtonInteraction, + ModalBuilder, + TextInputBuilder, + TextInputStyle +} from "discord.js"; import type { SlashCommandSubcommandBuilder } from "discord.js"; import confirmationMessage from "../../utils/confirmationMessage.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; @@ -17,7 +28,10 @@ const command = (builder: SlashCommandSubcommandBuilder) => option.setName("name").setDescription("The name to set | Leave blank to clear").setRequired(false) ); -const callback = async (interaction: CommandInteraction | ButtonInteraction, member?: GuildMember): Promise => { +const callback = async ( + interaction: CommandInteraction | ButtonInteraction, + member?: GuildMember +): Promise => { const { log, NucleusColors, entry, renderDelta, renderUser } = client.logger; let newNickname; if (!interaction.isButton()) { @@ -39,28 +53,15 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem .setDescription( keyValueList({ user: renderUser(member.user), - "new nickname": `${ - newNickname - ? newNickname - : "*No nickname*" - }` - }) + - `Are you sure you want to ${ - newNickname ? "change" : "clear" - } <@!${member.id}>'s nickname?` + "new nickname": `${newNickname ? newNickname : "*No nickname*"}` + }) + `Are you sure you want to ${newNickname ? "change" : "clear"} <@!${member.id}>'s nickname?` ) .setColor("Danger") .addCustomBoolean( "appeal", "Create appeal ticket", !(await areTicketsEnabled(interaction.guild!.id)), - async () => - await create( - interaction.guild!, - member!.user, - interaction.user, - "Nickname changed" - ), + async () => await create(interaction.guild!, member!.user, interaction.user, "Nickname changed"), "An appeal ticket will be created", null, "CONTROL.TICKET", @@ -81,18 +82,16 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem "ICONS.EDIT", "modal", newNickname ?? "", - new ModalBuilder() - .setTitle("Editing nickname") - .addComponents( - new ActionRowBuilder().addComponents( - new TextInputBuilder() - .setCustomId("default") - .setLabel("Nickname") - .setMaxLength(32) - .setRequired(false) - .setStyle(TextInputStyle.Short) - .setValue(newNickname ? newNickname : " ") - ) + new ModalBuilder().setTitle("Editing nickname").addComponents( + new ActionRowBuilder().addComponents( + new TextInputBuilder() + .setCustomId("default") + .setLabel("Nickname") + .setMaxLength(32) + .setRequired(false) + .setStyle(TextInputStyle.Short) + .setValue(newNickname ? newNickname : " ") + ) ) ) .setFailedMessage("No changes were made", "Success", "PUNISH.NICKNAME.GREEN") @@ -104,7 +103,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem notify = confirmation.components["notify"]!.active; createAppealTicket = confirmation.components["appeal"]!.active; } - if (confirmation.modals) newNickname = confirmation.modals![0]!.value + if (confirmation.modals) newNickname = confirmation.modals![0]!.value; } while (!timedOut && !success); if (timedOut || !success) return; let dmSent = false; @@ -121,12 +120,8 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem .setEmoji("PUNISH.NICKNAME.RED") .setTitle("Nickname changed") .setDescription( - `Your nickname was ${ - newNickname ? "changed" : "cleared" - } in ${interaction.guild!.name}.` + - (newNickname - ? `\nIt is now: ${newNickname}` - : "") + + `Your nickname was ${newNickname ? "changed" : "cleared"} in ${interaction.guild!.name}.` + + (newNickname ? `\nIt is now: ${newNickname}` : "") + "\n\n" + (createAppealTicket ? `You can appeal this in the ticket created in <#${ @@ -145,12 +140,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem new ButtonBuilder() .setStyle(ButtonStyle.Link) .setLabel(config.moderation.nick.text) - .setURL( - config.moderation.nick.link.replaceAll( - "{id}", - member.id - ) - ) + .setURL(config.moderation.nick.link.replaceAll("{id}", member.id)) ) ); } diff --git a/src/commands/mod/purge.ts b/src/commands/mod/purge.ts index ff69079..dadab04 100644 --- a/src/commands/mod/purge.ts +++ b/src/commands/mod/purge.ts @@ -101,8 +101,7 @@ const callback = async (interaction: CommandInteraction): Promise => { let component; try { component = m.awaitMessageComponent({ - filter: (i) => - i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id, + filter: (i) => i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id, time: 300000 }); } catch (e) { diff --git a/src/commands/mod/warn.ts b/src/commands/mod/warn.ts index 8408303..232219b 100644 --- a/src/commands/mod/warn.ts +++ b/src/commands/mod/warn.ts @@ -1,4 +1,11 @@ -import Discord, { CommandInteraction, GuildMember, ActionRowBuilder, ButtonBuilder, ButtonStyle, ButtonInteraction } from "discord.js"; +import Discord, { + CommandInteraction, + GuildMember, + ActionRowBuilder, + ButtonBuilder, + ButtonStyle, + ButtonInteraction +} from "discord.js"; import type { SlashCommandSubcommandBuilder } from "discord.js"; import confirmationMessage from "../../utils/confirmationMessage.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; @@ -14,7 +21,10 @@ const command = (builder: SlashCommandSubcommandBuilder) => .setDescription("Warns a user") .addUserOption((option) => option.setName("user").setDescription("The user to warn").setRequired(true)); -const callback = async (interaction: CommandInteraction | ButtonInteraction, member?: GuildMember): Promise => { +const callback = async ( + interaction: CommandInteraction | ButtonInteraction, + member?: GuildMember +): Promise => { if (!interaction.guild) return; const { log, NucleusColors, renderUser, entry } = client.logger; if (!interaction.isButton()) member = interaction.options.getMember("user") as GuildMember; @@ -41,8 +51,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem "appeal", "Create appeal ticket", !(await areTicketsEnabled(interaction.guild.id)), - async () => - await create(interaction.guild!, member!.user, interaction.user, reason), + async () => await create(interaction.guild!, member!.user, interaction.user, reason), "An appeal ticket will be created", null, "CONTROL.TICKET", @@ -110,12 +119,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem new ButtonBuilder() .setStyle(ButtonStyle.Link) .setLabel(config.moderation.warn.text) - .setURL( - config.moderation.warn.link.replaceAll( - "{id}", - member.id - ) - ) + .setURL(config.moderation.warn.link.replaceAll("{id}", member.id)) ) ); } @@ -135,10 +139,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem timestamp: Date.now() }, list: { - user: entry( - member.user.id, - renderUser(member.user) - ), + user: entry(member.user.id, renderUser(member.user)), warnedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user as Discord.User)), reason: reason ? reason : "*No reason provided*" }, @@ -151,13 +152,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem guild: interaction.guild.id } }; - await client.database.history.create( - "warn", - interaction.guild.id, - member.user, - interaction.user, - reason - ); + await client.database.history.create("warn", interaction.guild.id, member.user, interaction.user, reason); log(data); const failed = !dmSent && notify; if (!failed) { @@ -179,9 +174,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem components: [] }); } else { - const canSeeChannel = member - .permissionsIn(interaction.channel as Discord.TextChannel) - .has("ViewChannel"); + const canSeeChannel = member.permissionsIn(interaction.channel as Discord.TextChannel).has("ViewChannel"); const m = (await interaction.editReply({ embeds: [ new EmojiEmbed() diff --git a/src/commands/nucleus/stats.ts b/src/commands/nucleus/stats.ts index 1eceae2..294ee27 100644 --- a/src/commands/nucleus/stats.ts +++ b/src/commands/nucleus/stats.ts @@ -1,4 +1,18 @@ -import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ChannelType, CommandInteraction, ComponentType, Guild, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } from "discord.js"; +import { + ActionRowBuilder, + AttachmentBuilder, + ButtonBuilder, + ButtonInteraction, + ButtonStyle, + ChannelType, + CommandInteraction, + ComponentType, + Guild, + ModalBuilder, + ModalSubmitInteraction, + TextInputBuilder, + TextInputStyle +} from "discord.js"; import type { SlashCommandSubcommandBuilder } from "discord.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; import client from "../../utils/client.js"; @@ -8,7 +22,7 @@ const command = (builder: SlashCommandSubcommandBuilder) => builder.setName("stats").setDescription("Gets the bot's stats"); const callback = async (interaction: CommandInteraction): Promise => { - const description = `**Servers:** ${client.guilds.cache.size}\n` + `**Ping:** \`${client.ws.ping * 2}ms\`` + const description = `**Servers:** ${client.guilds.cache.size}\n` + `**Ping:** \`${client.ws.ping * 2}ms\``; const m = await interaction.reply({ embeds: [ new EmojiEmbed() @@ -28,30 +42,39 @@ const callback = async (interaction: CommandInteraction): Promise => { .setDescription(description) .setStatus("Success") .setEmoji("SETTINGS.STATS.GREEN") - ], components: [new ActionRowBuilder().addComponents( - new ButtonBuilder().setCustomId("admin").setLabel("Admin Panel").setStyle(ButtonStyle.Primary), - new ButtonBuilder().setCustomId("mod:nickname:599498449733550102").setLabel("Testing").setStyle(ButtonStyle.Primary) - )] + ], + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder().setCustomId("admin").setLabel("Admin Panel").setStyle(ButtonStyle.Primary), + new ButtonBuilder() + .setCustomId("mod:nickname:599498449733550102") + .setLabel("Testing") + .setStyle(ButtonStyle.Primary) + ) + ] }); const modal = new ModalBuilder() .addComponents( - new ActionRowBuilder() - .addComponents( - new TextInputBuilder() - .setStyle(TextInputStyle.Short) - .setLabel("Guild ID") - .setCustomId("guildID") - .setPlaceholder("Guild ID") - .setMinLength(16) - .setMaxLength(25) - ) + new ActionRowBuilder().addComponents( + new TextInputBuilder() + .setStyle(TextInputStyle.Short) + .setLabel("Guild ID") + .setCustomId("guildID") + .setPlaceholder("Guild ID") + .setMinLength(16) + .setMaxLength(25) + ) ) .setTitle("Admin Panel") - .setCustomId("adminPanel") + .setCustomId("adminPanel"); let i1: ButtonInteraction; - const channel = await client.channels.fetch(interaction.channelId) - if(!channel || [ChannelType.GuildCategory, ChannelType.GroupDM, ChannelType.GuildStageVoice].includes(channel.type)) return; + const channel = await client.channels.fetch(interaction.channelId); + if ( + !channel || + [ChannelType.GuildCategory, ChannelType.GroupDM, ChannelType.GuildStageVoice].includes(channel.type) + ) + return; // console.log(interaction) if (!("awaitMessageComponent" in channel)) return; try { @@ -59,27 +82,28 @@ const callback = async (interaction: CommandInteraction): Promise => { filter: (i) => i.customId === "admin" && i.user.id === interaction.user.id, time: 300000 }); - } catch (e) { console.log(e); return } - await i1.showModal(modal) + } catch (e) { + console.log(e); + return; + } + await i1.showModal(modal); let out: ModalSubmitInteraction; try { out = await i1.awaitModalSubmit({ filter: (i) => i.customId === "adminPanel" && i.user.id === interaction.user.id, time: 300000 - }) - } catch { return } + }); + } catch { + return; + } out.deferUpdate(); const GuildID = out.fields.getTextInputValue("guildID"); if (!client.guilds.cache.has(GuildID)) { await interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setTitle("Admin") - .setDescription("Not in server") - .setStatus("Danger") - ], components: [] + embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")], + components: [] }); - }; + } await interaction.editReply({ embeds: [], @@ -91,24 +115,23 @@ const callback = async (interaction: CommandInteraction): Promise => { new ButtonBuilder().setCustomId("purge").setLabel("Delete data").setStyle(ButtonStyle.Danger), new ButtonBuilder().setCustomId("cache").setLabel("Reset cache").setStyle(ButtonStyle.Success) ) - ]}); + ] + }); let i; try { i = await m.awaitMessageComponent({ filter: (i) => i.user.id === interaction.user.id, time: 300000 - }) - } catch { return } + }); + } catch { + return; + } i.deferUpdate(); - const guild = await client.guilds.fetch(GuildID) as Guild | null; + const guild = (await client.guilds.fetch(GuildID)) as Guild | null; if (!guild) { await interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setTitle("Admin") - .setDescription("Not in server") - .setStatus("Danger") - ], components: [] + embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")], + components: [] }); return; } @@ -119,17 +142,17 @@ const callback = async (interaction: CommandInteraction): Promise => { .setTitle("Stats") .setDescription( `**Name:** ${guild.name}\n` + - `**ID:** \`${guild.id}\`\n` + - `**Owner:** ${client.users.cache.get(guild.ownerId)!.tag}\n` + - `**Member Count:** ${guild.memberCount}\n` + - `**Created:** \n` + - `**Added Nucleus:** \n` + - `**Nucleus' Perms:** https://discordapi.com/permissions.html#${guild.members.me!.permissions.valueOf()}\n` + `**ID:** \`${guild.id}\`\n` + + `**Owner:** ${client.users.cache.get(guild.ownerId)!.tag}\n` + + `**Member Count:** ${guild.memberCount}\n` + + `**Created:** \n` + + `**Added Nucleus:** \n` + + `**Nucleus' Perms:** https://discordapi.com/permissions.html#${guild.members.me!.permissions.valueOf()}\n` ) .setStatus("Success") .setEmoji("SETTINGS.STATS.GREEN") ] - }) + }); } else if (i.customId === "leave") { await guild.leave(); await interaction.editReply({ @@ -139,8 +162,9 @@ const callback = async (interaction: CommandInteraction): Promise => { .setDescription(`Left ${guild.name}`) .setStatus("Success") .setEmoji("SETTINGS.STATS.GREEN") - ], components: [] - }) + ], + components: [] + }); } else if (i.customId === "data") { // Get all the data and convert to a string const data = await client.database.guilds.read(guild.id); @@ -150,9 +174,10 @@ const callback = async (interaction: CommandInteraction): Promise => { await interaction.editReply({ embeds: [ new EmojiEmbed().setTitle("Data").setDescription(`Data for ${guild.name}`).setStatus("Success") - ], components: [], + ], + components: [], files: [attachment] - }) + }); } else if (i.customId === "purge") { await client.database.guilds.delete(GuildID); await client.database.history.delete(GuildID); @@ -165,8 +190,9 @@ const callback = async (interaction: CommandInteraction): Promise => { .setDescription(`Deleted data for ${guild.name}`) .setStatus("Success") .setEmoji("SETTINGS.STATS.GREEN") - ], components: [] - }) + ], + components: [] + }); } else if (i.customId === "cache") { await client.memory.forceUpdate(guild.id); await interaction.editReply({ @@ -176,8 +202,9 @@ const callback = async (interaction: CommandInteraction): Promise => { .setDescription(`Reset cache for ${guild.name}`) .setStatus("Success") .setEmoji("SETTINGS.STATS.GREEN") - ], components: [] - }) + ], + components: [] + }); } } }; diff --git a/src/commands/settings/rolemenu.ts b/src/commands/settings/rolemenu.ts index 0c174f5..e683e4f 100644 --- a/src/commands/settings/rolemenu.ts +++ b/src/commands/settings/rolemenu.ts @@ -176,7 +176,7 @@ const editRoleMenuPage = async ( m: Message, data?: ObjectSchema ): Promise => { - if (!data) data = _.cloneDeep(defaultRoleMenuData) + if (!data) data = _.cloneDeep(defaultRoleMenuData); const buttons = new ActionRowBuilder().addComponents( new ButtonBuilder() .setCustomId("back") diff --git a/src/events/guildMemberUpdate.ts b/src/events/guildMemberUpdate.ts index 41a22c1..34a52b8 100644 --- a/src/events/guildMemberUpdate.ts +++ b/src/events/guildMemberUpdate.ts @@ -2,6 +2,7 @@ import { AuditLogEvent, GuildAuditLogsEntry, GuildMember } from "discord.js"; import type { NucleusClient } from "../utils/client.js"; import type { LoggerOptions } from "../utils/log.js"; import { generalException } from "../utils/createTemporaryStorage.js"; +import { doMemberChecks } from "../reflex/scanners.js"; export const event = "guildMemberUpdate"; @@ -92,6 +93,7 @@ export async function callback(client: NucleusClient, before: GuildMember, after if (!auditLog) return; if (auditLog.executor!.id === client.user!.id) return; if (before.nickname !== after.nickname) { + doMemberChecks(after, after.guild); await client.database.history.create( "nickname", after.guild.id, diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 4a8d941..3b0cd62 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -19,10 +19,7 @@ export const event = "interactionCreate"; async function errorMessage(interaction: ButtonInteraction, message: string) { await interaction.reply({ - embeds: [new EmojiEmbed() - .setDescription(message) - .setStatus("Danger") - ], + embeds: [new EmojiEmbed().setDescription(message).setStatus("Danger")], ephemeral: true, components: [] }); @@ -60,23 +57,27 @@ async function interactionCreate(interaction: Interaction) { const member = await interaction.guild?.members.fetch(memberId!); switch (action) { case "kick": { - const check = await kickCheck(interaction, false, member) + const check = await kickCheck(interaction, false, member); if (check !== true) return await errorMessage(interaction, check!); return await kickCallback(interaction, member); - } case "ban": { - const check = await banCheck(interaction, false, member) + } + case "ban": { + const check = await banCheck(interaction, false, member); if (check !== true) return await errorMessage(interaction, check!); return await banCallback(interaction, member); - } case "mute": { - const check = await muteCheck(interaction, false, member) + } + case "mute": { + const check = await muteCheck(interaction, false, member); if (check !== true) return await errorMessage(interaction, check!); return await muteCallback(interaction, member); - } case "nickname": { - const check = await nicknameCheck(interaction, false, member) + } + case "nickname": { + const check = await nicknameCheck(interaction, false, member); if (check !== true) return await errorMessage(interaction, check || "Something went wrong"); return await nicknameCallback(interaction, member); - } case "warn": { - const check = await warnCheck(interaction, false, member) + } + case "warn": { + const check = await warnCheck(interaction, false, member); if (check !== true) return await errorMessage(interaction, check!); return await warnCallback(interaction, member); } diff --git a/src/events/memberJoin.ts b/src/events/memberJoin.ts index 191ba6b..66abe28 100644 --- a/src/events/memberJoin.ts +++ b/src/events/memberJoin.ts @@ -9,7 +9,7 @@ export const event = "guildMemberAdd"; export async function callback(client: NucleusClient, member: GuildMember) { welcome(member); statsChannelAdd(member.user, member.guild); - doMemberChecks(member, member.guild) + doMemberChecks(member, member.guild); const { log, isLogging, NucleusColors, entry, renderUser, renderDelta } = client.logger; if (!(await isLogging(member.guild.id, "guildMemberUpdate"))) return; await client.database.history.create("join", member.guild.id, member.user, null, null); diff --git a/src/reflex/scanners.ts b/src/reflex/scanners.ts index f00e82c..192be25 100644 --- a/src/reflex/scanners.ts +++ b/src/reflex/scanners.ts @@ -5,9 +5,9 @@ import Tesseract from "node-tesseract-ocr"; import type Discord from "discord.js"; import client from "../utils/client.js"; import { createHash } from "crypto"; -import * as nsfwjs from 'nsfwjs'; -import * as clamscan from 'clamscan' -import * as tf from "@tensorflow/tfjs-node"; +// import * as nsfwjs from "nsfwjs"; +// import * as clamscan from "clamscan"; +// import * as tf from "@tensorflow/tfjs-node"; import EmojiEmbed from "../utils/generateEmojiEmbed.js"; import getEmojiByName from "../utils/getEmojiByName.js"; import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js"; @@ -21,10 +21,10 @@ interface MalwareSchema { errored?: boolean; } -const model = await nsfwjs.load(); +// const model = await nsfwjs.load(); export async function testNSFW(link: string): Promise { - const [fileName, hash] = await saveAttachment(link); + const [_fileName, hash] = await saveAttachment(link); const alreadyHaveCheck = await client.database.scanCache.read(hash); if (alreadyHaveCheck) return { nsfw: alreadyHaveCheck.data }; @@ -167,7 +167,12 @@ export async function MalwareCheck(element: string): Promise { } } -export function TestString(string: string, soft: string[], strict: string[], enabled?: boolean): {word: string, type: string} | null { +export function TestString( + string: string, + soft: string[], + strict: string[], + enabled?: boolean +): { word: string; type: string } | null { if (!enabled) return null; for (const word of strict) { if (string.toLowerCase().includes(word)) { @@ -197,34 +202,56 @@ export async function doMemberChecks(member: Discord.GuildMember, guild: Discord if (member.user.bot) return; const guildData = await client.database.guilds.read(guild.id); if (!guildData.logging.staff.channel) return; - const [ loose, strict ] = [guildData.filters.wordFilter.words.loose, guildData.filters.wordFilter.words.strict]; + const [loose, strict] = [guildData.filters.wordFilter.words.loose, guildData.filters.wordFilter.words.strict]; // Does the username contain filtered words const usernameCheck = TestString(member.user.username, loose, strict, guildData.filters.wordFilter.enabled); // Does the nickname contain filtered words const nicknameCheck = TestString(member.nickname ?? "", loose, strict, guildData.filters.wordFilter.enabled); // Does the profile picture contain filtered words - const avatarTextCheck = TestString(await TestImage(member.user.displayAvatarURL({ forceStatic: true })) ?? "", loose, strict, guildData.filters.wordFilter.enabled); + const avatarTextCheck = TestString( + (await TestImage(member.user.displayAvatarURL({ forceStatic: true }))) ?? "", + loose, + strict, + guildData.filters.wordFilter.enabled + ); // Is the profile picture NSFW - const avatarCheck = guildData.filters.images.NSFW && await NSFWCheck(member.user.displayAvatarURL({ forceStatic: true })); + const avatarCheck = + guildData.filters.images.NSFW && (await NSFWCheck(member.user.displayAvatarURL({ forceStatic: true }))); // Does the username contain an invite - const inviteCheck = guildData.filters.invite.enabled && member.user.username.match(/discord\.gg\/[a-zA-Z0-9]+/gi) !== null; + const inviteCheck = + guildData.filters.invite.enabled && member.user.username.match(/discord\.gg\/[a-zA-Z0-9]+/gi) !== null; // Does the nickname contain an invite - const nicknameInviteCheck = guildData.filters.invite.enabled && member.nickname?.match(/discord\.gg\/[a-zA-Z0-9]+/gi) !== null; + const nicknameInviteCheck = + guildData.filters.invite.enabled && member.nickname?.match(/discord\.gg\/[a-zA-Z0-9]+/gi) !== null; - if (usernameCheck !== null || nicknameCheck !== null || avatarCheck || inviteCheck || nicknameInviteCheck || avatarTextCheck !== null) { + if ( + usernameCheck !== null || + nicknameCheck !== null || + avatarCheck || + inviteCheck || + nicknameInviteCheck || + avatarTextCheck !== null + ) { const infractions = []; if (usernameCheck !== null) { infractions.push(`Username contains a ${usernameCheck.type}ly filtered word (${usernameCheck.word})`); - } if (nicknameCheck !== null) { + } + if (nicknameCheck !== null) { infractions.push(`Nickname contains a ${nicknameCheck.type}ly filtered word (${nicknameCheck.word})`); - } if (avatarCheck) { + } + if (avatarCheck) { infractions.push("Profile picture is NSFW"); - } if (inviteCheck) { + } + if (inviteCheck) { infractions.push("Username contains an invite"); - } if (nicknameInviteCheck) { + } + if (nicknameInviteCheck) { infractions.push("Nickname contains an invite"); - } if (avatarTextCheck !== null) { - infractions.push(`Profile picture contains a ${avatarTextCheck.type}ly filtered word: ${avatarTextCheck.word}`); + } + if (avatarTextCheck !== null) { + infractions.push( + `Profile picture contains a ${avatarTextCheck.type}ly filtered word: ${avatarTextCheck.word}` + ); } if (infractions.length === 0) return; // This is bad - Warn in the staff notifications channel @@ -234,34 +261,43 @@ export async function doMemberChecks(member: Discord.GuildMember, guild: Discord .setTitle("Member Flagged") .setEmoji("ICONS.FLAGS.RED") .setStatus("Danger") - .setDescription(`**Member:** ${member.user.username} (<@${member.user.id}>)\n\n` + - infractions.map((element) => `${filter} ${element}`).join("\n") - ) + .setDescription( + `**Member:** ${member.user.username} (<@${member.user.id}>)\n\n` + + infractions.map((element) => `${filter} ${element}`).join("\n") + ); await channel.send({ embeds: [embed], - components: [new ActionRowBuilder().addComponents(...[ - new ButtonBuilder() - .setCustomId(`mod:warn:${member.user.id}`) - .setLabel("Warn") - .setStyle(ButtonStyle.Primary), - new ButtonBuilder() - .setCustomId(`mod:mute:${member.user.id}`) - .setLabel("Mute") - .setStyle(ButtonStyle.Primary), - new ButtonBuilder() - .setCustomId(`mod:kick:${member.user.id}`) - .setLabel("Kick") - .setStyle(ButtonStyle.Danger), - new ButtonBuilder() - .setCustomId(`mod:ban:${member.user.id}`) - .setLabel("Ban") - .setStyle(ButtonStyle.Danger), - ].concat((usernameCheck !== null || nicknameCheck !== null || avatarTextCheck !== null) ? [ - new ButtonBuilder() - .setCustomId(`mod:nickname:${member.user.id}`) - .setLabel("Change Name") - .setStyle(ButtonStyle.Primary) - ] : []))] + components: [ + new ActionRowBuilder().addComponents( + ...[ + new ButtonBuilder() + .setCustomId(`mod:warn:${member.user.id}`) + .setLabel("Warn") + .setStyle(ButtonStyle.Primary), + new ButtonBuilder() + .setCustomId(`mod:mute:${member.user.id}`) + .setLabel("Mute") + .setStyle(ButtonStyle.Primary), + new ButtonBuilder() + .setCustomId(`mod:kick:${member.user.id}`) + .setLabel("Kick") + .setStyle(ButtonStyle.Danger), + new ButtonBuilder() + .setCustomId(`mod:ban:${member.user.id}`) + .setLabel("Ban") + .setStyle(ButtonStyle.Danger) + ].concat( + usernameCheck !== null || nicknameCheck !== null || avatarTextCheck !== null + ? [ + new ButtonBuilder() + .setCustomId(`mod:nickname:${member.user.id}`) + .setLabel("Change Name") + .setStyle(ButtonStyle.Primary) + ] + : [] + ) + ) + ] }); } -} \ No newline at end of file +} diff --git a/src/utils/confirmationMessage.ts b/src/utils/confirmationMessage.ts index 5bfbfdb..7b3bd31 100644 --- a/src/utils/confirmationMessage.ts +++ b/src/utils/confirmationMessage.ts @@ -37,7 +37,13 @@ class confirmationMessage { inverted = false; reason: string | null = null; - modals: {buttonText: string, emoji: string, customId: string, modal: Discord.ModalBuilder, value: string | undefined}[] = []; + modals: { + buttonText: string; + emoji: string; + customId: string; + modal: Discord.ModalBuilder; + value: string | undefined; + }[] = []; constructor(interaction: CommandInteraction | ButtonInteraction) { this.interaction = interaction; @@ -102,7 +108,7 @@ class confirmationMessage { } addModal(buttonText: string, emoji: string, customId: string, current: string, modal: Discord.ModalBuilder) { modal.setCustomId(customId); - this.modals.push({buttonText, emoji, customId, modal, value: current}); + this.modals.push({ buttonText, emoji, customId, modal, value: current }); return this; } async send(editOnly?: boolean): Promise<{ @@ -110,7 +116,13 @@ class confirmationMessage { cancelled?: boolean; components?: Record>; newReason?: string; - modals?: {buttonText: string, emoji: string, customId: string, modal: Discord.ModalBuilder, value: string | undefined}[]; + modals?: { + buttonText: string; + emoji: string; + customId: string; + modal: Discord.ModalBuilder; + value: string | undefined; + }[]; }> { let cancelled = false; let success: boolean | undefined = undefined; @@ -212,7 +224,7 @@ class confirmationMessage { time: 300000 }); } catch (e) { - success = false + success = false; break; } if (component.customId === "yes") { @@ -291,7 +303,12 @@ class confirmationMessage { continue; } } else if (this.modals.map((m) => m.customId).includes(component.customId)) { - const chosenModal = this.modals.find((component => m => m.customId === component.customId)(component)); + const chosenModal = this.modals.find( + ( + (component) => (m) => + m.customId === component.customId + )(component) + ); await component.showModal(chosenModal!.modal); await this.interaction.editReply({ embeds: [ @@ -364,7 +381,12 @@ class confirmationMessage { const modals = this.modals; const typedReturnValue = returnValue as | { cancelled: true } - | { success: boolean; components: Record>; modals: typeof modals; newReason?: string } + | { + success: boolean; + components: Record>; + modals: typeof modals; + newReason?: string; + } | { newReason: string; components: Record>; modals: typeof modals } | { components: Record>; modals: typeof modals }; diff --git a/src/utils/database.ts b/src/utils/database.ts index 62aee7c..19aa00b 100644 --- a/src/utils/database.ts +++ b/src/utils/database.ts @@ -836,9 +836,7 @@ export class Premium { } } -export class Plugins { - -} +// export class Plugins {} export interface GuildConfig { id: string;