diff --git a/src/commands/help.ts b/src/commands/help.ts index a040358..e34500f 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -87,8 +87,8 @@ const callback = async (interaction: CommandInteraction): Promise => { `Select a command to get started${(interaction.member?.permissions as PermissionsBitField).has("ManageGuild") ? `, or run ${getCommandMentionByName("nucleus/guide")} for commands to set up your server` : ``}` // FIXME ) } else { - let currentData = getCommandByName(currentPath.filter(value => value !== "" && value !== "none").join('/')); - let current = commands.find((command) => command.name === currentPath[0])!; + const currentData = getCommandByName(currentPath.filter(value => value !== "" && value !== "none").join('/')); + const current = commands.find((command) => command.name === currentPath[0])!; let optionString = `` let options: (ApplicationCommandOption & { @@ -97,16 +97,16 @@ const callback = async (interaction: CommandInteraction): Promise => { })[] = []; //options if(currentPath[1] !== "" && currentPath[1] !== "none" && currentPath[2] !== "" && currentPath[2] !== "none") { - let Op = current.options.find(option => option.name === currentPath[1])! as ApplicationCommandSubGroup - let Op2 = Op.options!.find(option => option.name === currentPath[2])! - options = Op2.options || [] + const Op = current.options.find(option => option.name === currentPath[1])! as ApplicationCommandSubGroup + const Op2 = Op.options!.find(option => option.name === currentPath[2])! + options = Op2.options ?? [] } else if(currentPath[1] !== "" && currentPath[1] !== "none") { let Op = current.options.find(option => option.name === currentPath[1])! if(Op.type === ApplicationCommandOptionType.SubcommandGroup) { options = [] } else { Op = Op as ApplicationCommandSubCommand - options = Op.options || [] + options = Op.options ?? [] } } else { options = current.options.filter(option => option.type !== ApplicationCommandOptionType.SubcommandGroup && option.type !== ApplicationCommandOptionType.Subcommand) || []; @@ -117,7 +117,7 @@ const callback = async (interaction: CommandInteraction): Promise => { const APICommand = client.commands["commands/" + currentPath.filter(value => value !== "" && value !== "none").join("/")]![0] let allowedToRun = true; if(APICommand?.check) { - APICommand?.check(interaction as Interaction, true) + allowedToRun = await APICommand.check(interaction as Interaction, true) } embed.setDescription( `${getEmojiByName(styles[currentPath[0]]!.emoji)} **${capitalize(currentData.name)}**\n> ${currentData.mention}\n\n` + @@ -136,7 +136,7 @@ const callback = async (interaction: CommandInteraction): Promise => { ...subcommandGroups.map((option) => new StringSelectMenuOptionBuilder().setLabel(capitalize(option.name)).setValue(option.name).setDefault(currentPath[1] === option.name)) ) if(subcommandGroupRow.components[0]!.options.find((option) => option.data.default && option.data.value !== "none")) { - let subsubcommands = (subcommandGroups.find((option) => option.name === currentPath[1])! as ApplicationCommandSubGroup).options?.filter((option) => option.type === ApplicationCommandOptionType.Subcommand) || []; + const subsubcommands = (subcommandGroups.find((option) => option.name === currentPath[1])! as ApplicationCommandSubGroup).options?.filter((option) => option.type === ApplicationCommandOptionType.Subcommand) ?? []; subcommandRow.components[0]! .addOptions( new StringSelectMenuOptionBuilder().setLabel("Select a subcommand").setValue("none").setDefault(currentPath[2] === "none"), @@ -152,7 +152,7 @@ const callback = async (interaction: CommandInteraction): Promise => { } } - let cmps = [commandRow]; + const cmps = [commandRow]; if(subcommandGroupRow.components[0]!.options.length > 0) cmps.push(subcommandGroupRow); if(subcommandRow.components[0]!.options.length > 0) cmps.push(subcommandRow); @@ -163,20 +163,23 @@ const callback = async (interaction: CommandInteraction): Promise => { i = await m.awaitMessageComponent({filter: (newInteraction) => interaction.user.id === newInteraction.user.id,time: 300000}) } catch (e) { closed = true; - break; + continue; } await i.deferUpdate(); - let value = i.values[0]!; + const value = i.values[0]!; switch(i.customId) { - case "commandRow": + case "commandRow": { currentPath = [value, "", ""]; break; - case "subcommandGroupRow": + } + case "subcommandGroupRow": { currentPath = [currentPath[0], value , ""]; break; - case "subcommandRow": + } + case "subcommandRow": { currentPath[2] = value; break; + } } } while (!closed); diff --git a/src/commands/nucleus/premium.ts b/src/commands/nucleus/premium.ts index 9d2c2b1..2f20d2e 100644 --- a/src/commands/nucleus/premium.ts +++ b/src/commands/nucleus/premium.ts @@ -79,39 +79,37 @@ const callback = async (interaction: CommandInteraction): Promise => { } catch (e) { return; } - if (i) { - i.deferUpdate(); - let guild = i.guild!; - if (count - appliesTo.length <= 0) { - interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setTitle("Premium") - .setDescription( - `You have already activated premium on the maximum amount of servers!` + firstDescription - ) - .setEmoji("NUCLEUS.PREMIUMACTIVATE") - .setStatus("Danger") - ], - components: [] - }); - closed = true; - } else { - client.database.premium.addPremium(interaction.user.id, guild.id); - interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setTitle("Premium") - .setDescription( - `You have activated premium on this server!` + firstDescription - ) - .setEmoji("NUCLEUS.LOGO") - .setStatus("Danger") - ], - components: [] - }); - closed = true; - } + i.deferUpdate(); + const guild = i.guild!; + if (count - appliesTo.length <= 0) { + interaction.editReply({ + embeds: [ + new EmojiEmbed() + .setTitle("Premium") + .setDescription( + `You have already activated premium on the maximum amount of servers!` + firstDescription + ) + .setEmoji("NUCLEUS.PREMIUMACTIVATE") + .setStatus("Danger") + ], + components: [] + }); + closed = true; + } else { + client.database.premium.addPremium(interaction.user.id, guild.id); + interaction.editReply({ + embeds: [ + new EmojiEmbed() + .setTitle("Premium") + .setDescription( + `You have activated premium on this server!` + firstDescription + ) + .setEmoji("NUCLEUS.LOGO") + .setStatus("Danger") + ], + components: [] + }); + closed = true; } } while (!closed); diff --git a/src/commands/settings/automod.ts b/src/commands/settings/automod.ts index 8e006b0..ab5e037 100644 --- a/src/commands/settings/automod.ts +++ b/src/commands/settings/automod.ts @@ -48,28 +48,30 @@ const listToAndMore = (list: string[], max: number) => { const toSelectMenu = async (interaction: StringSelectMenuInteraction, m: Message, ids: string[], type: "member" | "role" | "channel", title: string): Promise => { const back = new ActionRowBuilder().addComponents(new ButtonBuilder().setCustomId("back").setLabel("Back").setStyle(ButtonStyle.Secondary).setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji)); - let closed; do { let render: string[] = [] let mapped: string[] = []; let menu: UserSelectMenuBuilder | RoleSelectMenuBuilder | ChannelSelectMenuBuilder; switch(type) { - case "member": + case "member": { menu = new UserSelectMenuBuilder().setCustomId("user").setPlaceholder("Select users").setMaxValues(25); mapped = await Promise.all(ids.map(async (id) => { return (await client.users.fetch(id).then(user => user.tag)) || "Unknown User" })); render = ids.map(id => client.logger.renderUser(id)) break; - case "role": + } + case "role": { menu = new RoleSelectMenuBuilder().setCustomId("role").setPlaceholder("Select roles").setMaxValues(25); - mapped = await Promise.all(ids.map(async (id) => { return (await interaction.guild!.roles.fetch(id).then(role => role?.name)) || "Unknown Role" })); + mapped = await Promise.all(ids.map(async (id) => { return (await interaction.guild!.roles.fetch(id).then(role => role?.name ?? "Unknown Role"))})); render = ids.map(id => client.logger.renderRole(id, interaction.guild!)) break; - case "channel": + } + case "channel": { menu = new ChannelSelectMenuBuilder().setCustomId("channel").setPlaceholder("Select channels").setMaxValues(25); - mapped = await Promise.all(ids.map(async (id) => { return (await interaction.guild!.channels.fetch(id).then(channel => channel?.name)) || "Unknown Channel" })); + mapped = await Promise.all(ids.map(async (id) => { return (await interaction.guild!.channels.fetch(id).then(channel => channel?.name ?? "Unknown Role")) })); render = ids.map(id => client.logger.renderChannel(id)) break; + } } const removeOptions = new ActionRowBuilder() .addComponents( @@ -85,7 +87,7 @@ const toSelectMenu = async (interaction: StringSelectMenuInteraction, m: Message .setEmoji(getEmojiByName("GUILD.SETTINGS.GREEN")) .setDescription(`Select ${type}s:\n\nCurrent:\n` + (render.length > 0 ? render.join("\n") : "None")) .setStatus("Success"); - let components: ActionRowBuilder< + const components: ActionRowBuilder< StringSelectMenuBuilder | ButtonBuilder | ChannelSelectMenuBuilder | @@ -102,7 +104,7 @@ const toSelectMenu = async (interaction: StringSelectMenuInteraction, m: Message i = await m.awaitMessageComponent({filter: i => i.user.id === interaction.user.id, time: 300000}); } catch(e) { closed = true; - break; + continue; } if(i.isButton()) { @@ -176,15 +178,18 @@ const imageMenu = async (interaction: StringSelectMenuInteraction, m: Message, c } await i.deferUpdate(); switch(i.customId) { - case "back": + case "back": { closed = true; break; - case "nsfw": + } + case "nsfw": { current.NSFW = !current.NSFW; break; - case "size": + } + case "size": { current.size = !current.size; break; + } } } while(!closed); return current; @@ -267,16 +272,18 @@ const wordMenu = async (interaction: StringSelectMenuInteraction, m: Message, cu if(i.isButton()) { await i.deferUpdate(); switch(i.customId) { - case "back": + case "back": { closed = true; break; - case "enabled": + } + case "enabled": { current.enabled = !current.enabled; break; + } } } else { switch(i.values[0]) { - case "words": + case "words": { await interaction.editReply({embeds: [new EmojiEmbed() .setTitle("Word Filter") .setDescription("Modal opened. If you can't see it, click back and try again.") @@ -298,7 +305,7 @@ const wordMenu = async (interaction: StringSelectMenuInteraction, m: Message, cu .setCustomId("wordStrict") .setLabel("Strict Words") .setPlaceholder("Matches anywhere in the message, including surrounded by other characters") - .setValue(current.words.strict.join(", ") ?? "") + .setValue(current.words.strict.join(", ")) .setStyle(TextInputStyle.Paragraph) .setRequired(false) ), @@ -308,7 +315,7 @@ const wordMenu = async (interaction: StringSelectMenuInteraction, m: Message, cu .setCustomId("wordLoose") .setLabel("Loose Words") .setPlaceholder("Matches only if the word is by itself, surrounded by spaces or punctuation") - .setValue(current.words.loose.join(", ") ?? "") + .setValue(current.words.loose.join(", ")) .setStyle(TextInputStyle.Paragraph) .setRequired(false) ) @@ -333,18 +340,22 @@ const wordMenu = async (interaction: StringSelectMenuInteraction, m: Message, cu current.words.loose = out.fields.getTextInputValue("wordLoose") .split(",").map(s => s.trim()).filter(s => s.length > 0); break; - case "allowedUsers": + } + case "allowedUsers": { await i.deferUpdate(); current.allowed.users = await toSelectMenu(interaction, m, current.allowed.users, "member", "Word Filter"); break; - case "allowedRoles": + } + case "allowedRoles": { await i.deferUpdate(); current.allowed.roles = await toSelectMenu(interaction, m, current.allowed.roles, "role", "Word Filter"); break; - case "allowedChannels": + } + case "allowedChannels": { await i.deferUpdate(); current.allowed.channels = await toSelectMenu(interaction, m, current.allowed.channels, "channel", "Word Filter"); break; + } } } } while(!closed); @@ -420,25 +431,30 @@ const inviteMenu = async (interaction: StringSelectMenuInteraction, m: Message, if(i.isButton()) { await i.deferUpdate(); switch(i.customId) { - case "back": + case "back": { closed = true; break; - case "enabled": + } + case "enabled": { current.enabled = !current.enabled; break; + } } } else { await i.deferUpdate(); switch(i.values[0]) { - case "users": + case "users": { current.allowed.users = await toSelectMenu(interaction, m, current.allowed.users, "member", "Invite Settings"); break; - case "roles": + } + case "roles": { current.allowed.roles = await toSelectMenu(interaction, m, current.allowed.roles, "role", "Invite Settings"); break; - case "channels": + } + case "channels": { current.allowed.channels = await toSelectMenu(interaction, m, current.allowed.channels, "channel", "Invite Settings"); break; + } } } @@ -557,21 +573,24 @@ const mentionMenu = async (interaction: StringSelectMenuInteraction, m: Message, if(i.isButton()) { await i.deferUpdate(); switch (i.customId) { - case "back": + case "back": { closed = true; break; - case "everyone": + } + case "everyone": { current.everyone = !current.everyone; break; - case "roles": + } + case "roles": { current.roles = !current.roles; break; + } } } else { switch (i.customId) { - case "toEdit": + case "toEdit": { switch (i.values[0]) { - case "mass": + case "mass": { await interaction.editReply({embeds: [new EmojiEmbed() .setTitle("Word Filter") .setDescription("Modal opened. If you can't see it, click back and try again.") @@ -613,26 +632,33 @@ const mentionMenu = async (interaction: StringSelectMenuInteraction, m: Message, if(out.isButton()) break; current.mass = parseInt(out.fields.getTextInputValue("mass")); break; - case "roles": + } + case "roles": { await i.deferUpdate(); current.allowed.rolesToMention = await toSelectMenu(interaction, m, current.allowed.rolesToMention, "role", "Mention Settings"); break; + } } break; - case "allowed": + } + case "allowed": { await i.deferUpdate(); switch (i.values[0]) { - case "users": + case "users": { current.allowed.users = await toSelectMenu(interaction, m, current.allowed.users, "member", "Mention Settings"); break; - case "roles": + } + case "roles": { current.allowed.roles = await toSelectMenu(interaction, m, current.allowed.roles, "role", "Mention Settings"); break; - case "channels": + } + case "channels": { current.allowed.channels = await toSelectMenu(interaction, m, current.allowed.channels, "channel", "Mention Settings"); break; + } } break; + } } } @@ -706,34 +732,38 @@ const callback = async (interaction: CommandInteraction): Promise => { i = await m.awaitMessageComponent({filter: (i) => i.user.id === interaction.user.id && i.message.id === m.id, time: 300000}) as StringSelectMenuInteraction | ButtonInteraction; } catch (e) { closed = true; - return; + continue; } - if(!i) return; if(i.isButton()) { await i.deferUpdate(); await client.database.guilds.write(interaction.guild.id, {filters: config}); } else { switch(i.values[0]) { - case "invites": + case "invites": { await i.deferUpdate(); config.invite = await inviteMenu(i, m, config.invite); break; - case "mentions": + } + case "mentions": { await i.deferUpdate(); config.pings = await mentionMenu(i, m, config.pings); break; - case "words": + } + case "words": { await i.deferUpdate(); config.wordFilter = await wordMenu(i, m, config.wordFilter); break; - case "malware": + } + case "malware": { await i.deferUpdate(); config.malware = !config.malware; break; - case "images": - let next = await imageMenu(i, m, config.images); - if(next) config.images = next; + } + case "images": { + const next = await imageMenu(i, m, config.images); + config.images = next; break; + } } } diff --git a/src/commands/settings/rolemenu.ts b/src/commands/settings/rolemenu.ts index 90b224d..635a1fd 100644 --- a/src/commands/settings/rolemenu.ts +++ b/src/commands/settings/rolemenu.ts @@ -41,7 +41,7 @@ const defaultRolePageConfig = { } const reorderRoleMenuPages = async (interaction: CommandInteraction, m: Message, currentObj: ObjectSchema[]) => { - let reorderRow = new ActionRowBuilder() + const reorderRow = new ActionRowBuilder() .addComponents( new StringSelectMenuBuilder() .setCustomId("reorder") @@ -55,7 +55,7 @@ const reorderRoleMenuPages = async (interaction: CommandInteraction, m: Message, ) ) ); - let buttonRow = new ActionRowBuilder() + const buttonRow = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setCustomId("back") @@ -85,7 +85,6 @@ const reorderRoleMenuPages = async (interaction: CommandInteraction, m: Message, if(!out) return; out.deferUpdate(); if (out.isButton()) return; - if(!out.values) return; const values = out.values; const newOrder: ObjectSchema[] = currentObj.map((_, i) => { @@ -156,7 +155,6 @@ const editNameDescription = async (i: ButtonInteraction, interaction: StringSele } if(!out) return [name, description]; if (out.isButton()) return [name, description]; - if(!out.fields) return [name, description]; name = out.fields.fields.find((f) => f.customId === "name")?.value ?? name; description = out.fields.fields.find((f) => f.customId === "description")?.value ?? description; return [name, description] @@ -223,19 +221,22 @@ const editRoleMenuPage = async (interaction: StringSelectMenuInteraction | Butto } } else if (i.isButton()) { switch (i.customId) { - case "back": + case "back": { await i.deferUpdate(); back = true; break; - case "edit": - let [name, description] = await editNameDescription(i, interaction, m, data); + } + case "edit": { + const [name, description] = await editNameDescription(i, interaction, m, data); data.name = name ? name : data.name; data.description = description ? description : data.description; break; - case "addRole": + } + case "addRole": { await i.deferUpdate(); data.options.push(await createRoleMenuOptionPage(interaction, m)); break; + } } } @@ -247,9 +248,9 @@ const editRoleMenuPage = async (interaction: StringSelectMenuInteraction | Butto const createRoleMenuOptionPage = async (interaction: StringSelectMenuInteraction | ButtonInteraction, m: Message, data?: {name: string; description: string | null; role: string}) => { const { renderRole} = client.logger; if (!data) data = { - name: "Role Menu Option", + name: "New role Menu Option", description: null, - role: "No role set" + role: "" }; let back = false; const buttons = new ActionRowBuilder() @@ -268,11 +269,11 @@ const createRoleMenuOptionPage = async (interaction: StringSelectMenuInteraction do { const roleSelect = new RoleSelectMenuBuilder().setCustomId("role").setPlaceholder(data.role ? "Set role to" : "Set the role"); const embed = new EmojiEmbed() - .setTitle(`${data.name ?? "New Role Menu Option"}`) + .setTitle(`${data.name}`) .setStatus("Success") .setDescription( `**Description:**\n> ${data.description ?? "No description set"}\n\n` + - `**Role:** ${renderRole((await interaction.guild!.roles.fetch(data.role))!) ?? "No role set"}\n` + `**Role:** ${data.role ? renderRole((await interaction.guild!.roles.fetch(data.role))!) : "No role set"}\n` ) interaction.editReply({embeds: [embed], components: [new ActionRowBuilder().addComponents(roleSelect), buttons]}); @@ -292,16 +293,18 @@ const createRoleMenuOptionPage = async (interaction: StringSelectMenuInteraction } } else if (i.isButton()) { switch (i.customId) { - case "back": + case "back": { await i.deferUpdate(); back = true; break; - case "edit": + } + case "edit": { await i.deferUpdate(); - let [name, description] = await editNameDescription(i, interaction, m, data as {name: string; description: string}); + const [name, description] = await editNameDescription(i, interaction, m, data as {name: string; description: string}); data.name = name ? name : data.name; data.description = description ? description : data.description; break; + } } } } while (!back); @@ -409,54 +412,63 @@ const callback = async (interaction: CommandInteraction): Promise => { i = await m.awaitMessageComponent({ time: 300000, filter: (i) => i.user.id === interaction.user.id && i.message.id === m.id && i.channelId === interaction.channelId}) as ButtonInteraction | StringSelectMenuInteraction; } catch (e) { closed = true; - break; + continue; } await i.deferUpdate(); if (i.isButton()) { switch (i.customId) { - case "back": + case "back": { page--; break; - case "next": + } + case "next": { page++; break; - case "add": - let newPage = await editRoleMenuPage(i, m) + } + case "add": { + const newPage = await editRoleMenuPage(i, m) if(!newPage) break; currentObject.push(); page = currentObject.length - 1; break; - case "reorder": - let reordered = await reorderRoleMenuPages(interaction, m, currentObject); + } + case "reorder": { + const reordered = await reorderRoleMenuPages(interaction, m, currentObject); if(!reordered) break; currentObject = reordered; break; - case "save": + } + case "save": { client.database.guilds.write(interaction.guild.id, {"roleMenu.options": currentObject}); modified = false; break; + } } } else if (i.isStringSelectMenu()) { switch (i.customId) { - case "action": + case "action": { switch(i.values[0]) { - case "edit": - let edited = await editRoleMenuPage(i, m, current!); + case "edit": { + const edited = await editRoleMenuPage(i, m, current!); if(!edited) break; currentObject[page] = edited; modified = true; break; - case "delete": + } + case "delete": { if(page === 0 && currentObject.keys.length - 1 > 0) page++; else page--; currentObject.splice(page, 1); break; + } } break; - case "page": + } + case "page": { page = parseInt(i.values[0]!); break; + } } } diff --git a/src/commands/settings/stats.ts b/src/commands/settings/stats.ts index dd4027d..f8a57b7 100644 --- a/src/commands/settings/stats.ts +++ b/src/commands/settings/stats.ts @@ -136,11 +136,12 @@ const addStatsChannel = async (interaction: CommandInteraction, m: Message, curr } if (i.isButton()) { switch (i.customId) { - case "back": + case "back": { await i.deferUpdate(); closed = true; break; - case "save": + } + case "save": { await i.deferUpdate(); if (newChannel) { currentObject[newChannel] = { @@ -150,7 +151,8 @@ const addStatsChannel = async (interaction: CommandInteraction, m: Message, curr } closed = true; break; - case "editName": + } + case "editName": { await interaction.editReply({ embeds: [new EmojiEmbed() .setTitle("Stats Channel") @@ -170,20 +172,21 @@ const addStatsChannel = async (interaction: CommandInteraction, m: Message, curr }); showModal(i, {name: newChannelName, enabled: newChannelEnabled}) - const out = await modalInteractionCollector( + const out: Discord.ModalSubmitInteraction | ButtonInteraction| null = await modalInteractionCollector( m, (m) => m.channel!.id === interaction.channel!.id && m.user!.id === interaction.user!.id, (i) => i.channel!.id === interaction.channel!.id && i.user!.id === interaction.user!.id && i.message!.id === m.id - ) as Discord.ModalSubmitInteraction | null; + ); if (!out) continue; - if (!out.fields) continue; if (out.isButton()) continue; newChannelName = out.fields.getTextInputValue("text"); break; - case "toggleEnabled": + } + case "toggleEnabled": { await i.deferUpdate(); newChannelEnabled = !newChannelEnabled; break; + } } } else { await i.deferUpdate(); @@ -307,11 +310,12 @@ const callback = async (interaction: CommandInteraction) => { if(i.isStringSelectMenu()) { switch(i.customId) { - case "page": + case "page": { await i.deferUpdate(); page = Object.keys(currentObject).indexOf(i.values[0]!); break; - case "action": + } + case "action": { modified = true; switch(i.values[0]!) { case "edit": { @@ -345,7 +349,6 @@ const callback = async (interaction: CommandInteraction) => { continue; } if (!out) continue - if (!out.fields) continue if (out.isButton()) continue; currentObject[Object.keys(currentObject)[page]!]!.name = out.fields.getTextInputValue("text"); break; @@ -358,32 +361,37 @@ const callback = async (interaction: CommandInteraction) => { } case "delete": { await i.deferUpdate(); - delete currentObject[Object.keys(currentObject)[page]!]; + currentObject = Object.fromEntries(Object.entries(currentObject).filter(([k]) => k !== Object.keys(currentObject)[page]!)); page = Math.min(page, Object.keys(currentObject).length - 1); modified = true; break; } } break; + } } } else { await i.deferUpdate(); switch(i.customId) { - case "back": + case "back": { page--; break; - case "next": + } + case "next": { page++; break; - case "add": + } + case "add": { currentObject = await addStatsChannel(interaction, m, currentObject); page = Object.keys(currentObject).length - 1; break; - case "save": + } + case "save": { client.database.guilds.write(interaction.guild.id, {stats: currentObject}); singleNotify("statsChannelDeleted", interaction.guild.id, true); modified = false; break; + } } } diff --git a/src/commands/settings/tickets.ts b/src/commands/settings/tickets.ts index 3c5746c..29e6ea4 100644 --- a/src/commands/settings/tickets.ts +++ b/src/commands/settings/tickets.ts @@ -723,7 +723,7 @@ async function manageTypes(interaction: CommandInteraction, data: GuildConfig["t data.customTypes.push(toAdd); } } else if ((i.component as ButtonComponent).customId === "switchToDefault") { - await i.deferUpdate(); + await i.deferUpdate(); await client.database.guilds.write(interaction.guild!.id, { "tickets.useCustom": false }, []); data.useCustom = false; } else if ((i.component as ButtonComponent).customId === "switchToCustom") { diff --git a/src/commands/settings/tracks.ts b/src/commands/settings/tracks.ts index 354a948..4e27d68 100644 --- a/src/commands/settings/tracks.ts +++ b/src/commands/settings/tracks.ts @@ -37,7 +37,7 @@ const editName = async (i: ButtonInteraction, interaction: StringSelectMenuInter .setCustomId("name") .setPlaceholder("Name here...") // TODO: Make better placeholder .setStyle(TextInputStyle.Short) - .setValue(name ?? "") + .setValue(name) .setRequired(true) ) ) @@ -74,14 +74,13 @@ const editName = async (i: ButtonInteraction, interaction: StringSelectMenuInter } if(!out) return name; if (out.isButton()) return name; - if(!out.fields) return name; name = out.fields.fields.find((f) => f.customId === "name")?.value ?? name; return name } const reorderTracks = async (interaction: ButtonInteraction, m: Message, roles: Collection, currentObj: string[]) => { - let reorderRow = new ActionRowBuilder() + const reorderRow = new ActionRowBuilder() .addComponents( new StringSelectMenuBuilder() .setCustomId("reorder") @@ -95,7 +94,7 @@ const reorderTracks = async (interaction: ButtonInteraction, m: Message, roles: ) ) ); - let buttonRow = new ActionRowBuilder() + const buttonRow = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setCustomId("back") @@ -125,7 +124,6 @@ const reorderTracks = async (interaction: ButtonInteraction, m: Message, roles: if(!out) return; out.deferUpdate(); if (out.isButton()) return; - if(!out.values) return; const values = out.values; const newOrder: string[] = currentObj.map((_, i) => { @@ -204,7 +202,7 @@ const editTrack = async (interaction: ButtonInteraction | StringSelectMenuIntera .setEmoji(getEmojiByName("CONTROL." + (current.nullable ? "TICK" : "CROSS"), "id") as APIMessageComponentEmoji) ); - let allowed: boolean[] = []; + const allowed: boolean[] = []; for (const role of current.track) { const disabled: boolean = roles.get(role)!.position >= (interaction.member as GuildMember).roles.highest.position; @@ -241,39 +239,46 @@ const editTrack = async (interaction: ButtonInteraction | StringSelectMenuIntera if (out.isButton()) { out.deferUpdate(); switch(out.customId) { - case "back": + case "back": { closed = true; break; - case "edit": + } + case "edit": { current.name = (await editName(out, interaction, message, current.name))!; break; - case "reorder": + } + case "reorder": { current.track = (await reorderTracks(out, message, roles, current.track))!; break; - case "retainPrevious": + } + case "retainPrevious": { current.retainPrevious = !current.retainPrevious; break; - case "nullable": + } + case "nullable": { current.nullable = !current.nullable; break; + } } } else if (out.isStringSelectMenu()) { out.deferUpdate(); switch(out.customId) { - case "removeRole": + case "removeRole": { const index = current.track.findIndex(v => v === editableRoles[parseInt((out! as StringSelectMenuInteraction).values![0]!)]); current.track.splice(index, 1); break; + } } } else { switch(out.customId) { - case "addRole": + case "addRole": { const role = out.values![0]!; if(!current.track.includes(role)) { current.track.push(role); } out.reply({content: "That role is already on this track", ephemeral: true}) break; + } } } @@ -381,54 +386,61 @@ const callback = async (interaction: CommandInteraction) => { i = await m.awaitMessageComponent({ time: 300000, filter: (i) => i.user.id === interaction.user.id && i.message.id === m.id && i.channelId === interaction.channelId}) as ButtonInteraction | StringSelectMenuInteraction; } catch (e) { closed = true; - break; + continue; } await i.deferUpdate(); if (i.isButton()) { switch (i.customId) { - case "back": + case "back": { page--; break; - case "next": + } + case "next": { page++; break; - case "add": - let newPage = await editTrack(i, m, roles) + } + case "add": { + const newPage = await editTrack(i, m, roles) if(!newPage) break; tracks.push(); page = tracks.length - 1; break; - case "save": + } + case "save": { client.database.guilds.write(interaction.guild!.id, {tracks: tracks}); modified = false; break; + } } } else if (i.isStringSelectMenu()) { switch (i.customId) { - case "action": + case "action": { switch(i.values[0]) { - case "edit": - let edited = await editTrack(i, m, roles, current!); + case "edit": { + const edited = await editTrack(i, m, roles, current!); if(!edited) break; tracks[page] = edited; modified = true; break; - case "delete": + } + case "delete": { if(page === 0 && tracks.keys.length - 1 > 0) page++; else page--; tracks.splice(page, 1); break; + } } break; - case "page": + } + case "page": { page = parseInt(i.values[0]!); break; + } } } } while (!closed) - } const check = (interaction: CommandInteraction, _partial: boolean = false) => { diff --git a/src/reflex/scanners.ts b/src/reflex/scanners.ts index b929d3d..cf713e6 100644 --- a/src/reflex/scanners.ts +++ b/src/reflex/scanners.ts @@ -17,10 +17,10 @@ interface MalwareSchema { export async function testNSFW(link: string): Promise { const [p, hash] = await saveAttachment(link); - let alreadyHaveCheck = await client.database.scanCache.read(hash) + const alreadyHaveCheck = await client.database.scanCache.read(hash) if(alreadyHaveCheck) return { nsfw: alreadyHaveCheck.data }; const data = new URLSearchParams(); - let r = createReadStream(p) + const r = createReadStream(p) data.append("file", r.read(fs.statSync(p).size)); const result = await fetch("https://unscan.p.rapidapi.com/", { method: "POST", @@ -43,10 +43,10 @@ export async function testNSFW(link: string): Promise { export async function testMalware(link: string): Promise { const [p, hash] = await saveAttachment(link); - let alreadyHaveCheck = await client.database.scanCache.read(hash) + const alreadyHaveCheck = await client.database.scanCache.read(hash) if(alreadyHaveCheck) return { safe: alreadyHaveCheck.data }; const data = new URLSearchParams(); - let f = createReadStream(p); + const f = createReadStream(p); data.append("file", f.read(fs.statSync(p).size)); const result = await fetch("https://unscan.p.rapidapi.com/malware", { method: "POST", @@ -68,7 +68,7 @@ export async function testMalware(link: string): Promise { } export async function testLink(link: string): Promise<{ safe: boolean; tags: string[] }> { - let alreadyHaveCheck = await client.database.scanCache.read(link) + const alreadyHaveCheck = await client.database.scanCache.read(link) if(alreadyHaveCheck) return { safe: alreadyHaveCheck.data, tags: [] }; const scanned: { safe?: boolean; tags?: string[] } = await fetch("https://unscan.p.rapidapi.com/link", { method: "POST", diff --git a/src/utils/client.ts b/src/utils/client.ts index 41cdbca..5286814 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -33,7 +33,7 @@ class NucleusClient extends Client { check: (interaction: Interaction, partial: boolean) => Promise | boolean, autocomplete: (interaction: AutocompleteInteraction) => Promise } | undefined,{name: string, description: string}]> = {}; - fetchedCommands: Collection = new Collection(); + fetchedCommands = new Collection(); constructor(database: typeof NucleusClient.prototype.database) { super({ intents: [ GatewayIntentBits.Guilds, diff --git a/src/utils/commandRegistration/slashCommandBuilder.ts b/src/utils/commandRegistration/slashCommandBuilder.ts index b215572..ef45875 100644 --- a/src/utils/commandRegistration/slashCommandBuilder.ts +++ b/src/utils/commandRegistration/slashCommandBuilder.ts @@ -32,7 +32,7 @@ export async function group( if (descriptionLocalizations) { subcommandGroup.setDescriptionLocalizations(descriptionLocalizations) } for (const subcommand of fetched.subcommands) { - let processedCommand = subcommand.command(new SlashCommandSubcommandBuilder()); + const processedCommand = subcommand.command(new SlashCommandSubcommandBuilder()); client.commands["commands/" + path + "/" + processedCommand.name] = [subcommand, { name: processedCommand.name, description: processedCommand.description }] subcommandGroup.addSubcommand(processedCommand); }; @@ -80,7 +80,7 @@ export async function command( command.addSubcommand(fetchedCommand); } for (const group of fetched.subcommandGroups) { - let processedCommand = group.command(new SlashCommandSubcommandGroupBuilder()); + const processedCommand = group.command(new SlashCommandSubcommandGroupBuilder()); client.commands[commandString! + "/" + processedCommand.name] = [undefined, { name: processedCommand.name, description: processedCommand.description }] command.addSubcommandGroup(processedCommand); }; diff --git a/src/utils/log.ts b/src/utils/log.ts index c5c7e06..64062ac 100644 --- a/src/utils/log.ts +++ b/src/utils/log.ts @@ -10,7 +10,7 @@ const wait = promisify(setTimeout); export const Logger = { renderUser(user: Discord.User | string) { - if (typeof user === "string") user = client.users.cache.get(user) as Discord.User; + if (typeof user === "string") user = client.users.cache.get(user)!; return `${user.username} [<@${user.id}>]`; }, renderTime(t: number) { @@ -34,7 +34,7 @@ export const Logger = { return `${channel.name} [<#${channel.id}>]`; }, renderRole(role: Discord.Role | string, guild?: Discord.Guild | string) { - if (typeof role === "string") role = (typeof guild === "string" ? client.guilds.cache.get(guild) : guild)!.roles.cache.get(role) as Discord.Role; + if (typeof role === "string") role = (typeof guild === "string" ? client.guilds.cache.get(guild) : guild)!.roles.cache.get(role)!; return `${role.name} [<@&${role.id}>]`; }, renderEmoji(emoji: Discord.GuildEmoji) {