From ca29ebb481c89c4521e14ab159f162b2a689ae0d Mon Sep 17 00:00:00 2001 From: TheCodedProf Date: Fri, 10 Mar 2023 17:40:09 -0500 Subject: [PATCH] prettiered --- src/commands/help.ts | 15 ++- src/commands/mod/nick.ts | 2 +- src/commands/nucleus/stats.ts | 160 +++++++++++++++---------------- src/commands/nucleus/suggest.ts | 115 +++++++++++++--------- src/commands/privacy.ts | 4 +- src/commands/settings/automod.ts | 11 ++- src/config/format.ts | 4 +- src/events/interactionCreate.ts | 98 ++++++++++++------- src/utils/confirmationMessage.ts | 8 +- 9 files changed, 237 insertions(+), 180 deletions(-) diff --git a/src/commands/help.ts b/src/commands/help.ts index 041fb47..f95eb6e 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -22,7 +22,10 @@ import { capitalize } from "../utils/generateKeyValueList.js"; import { getCommandByName, getCommandMentionByName } from "../utils/getCommandDataByName.js"; import getEmojiByName from "../utils/getEmojiByName.js"; -const command = new SlashCommandBuilder().setName("help").setDescription("Shows help for commands").setDMPermission(true); +const command = new SlashCommandBuilder() + .setName("help") + .setDescription("Shows help for commands") + .setDMPermission(true); const styles: Record = { help: { emoji: "NUCLEUS.LOGO" }, @@ -127,9 +130,9 @@ const callback = async (interaction: CommandInteraction): Promise => { ); } for (const option of options) { - optionString += ` - \`${option.name}\` (${ApplicationCommandOptionType[option.type].replace("Integer", "Number").replace("String", "Text")}) - ${ - option.description - }\n`; + optionString += ` - \`${option.name}\` (${ApplicationCommandOptionType[option.type] + .replace("Integer", "Number") + .replace("String", "Text")}) - ${option.description}\n`; } const APICommand = client.commands[ @@ -140,7 +143,9 @@ const callback = async (interaction: CommandInteraction): Promise => { allowedToRun = await APICommand.check(interaction as Interaction, true); } embed.setDescription( - `${getEmojiByName(styles[currentPath[0]]!.emoji)} **${capitalize(currentData.name)}** | ${currentData.mention}\n\n` + + `${getEmojiByName(styles[currentPath[0]]!.emoji)} **${capitalize(currentData.name)}** | ${ + currentData.mention + }\n\n` + `${currentData.description}\n\n` + (APICommand ? `${getEmojiByName(allowedToRun ? "CONTROL.TICK" : "CONTROL.CROSS")} You ${ diff --git a/src/commands/mod/nick.ts b/src/commands/mod/nick.ts index ed14efb..178246a 100644 --- a/src/commands/mod/nick.ts +++ b/src/commands/mod/nick.ts @@ -81,7 +81,7 @@ const callback = async ( "Change nickname", "ICONS.EDIT", "modal", - {default: newNickname ?? ""}, + { default: newNickname ?? "" }, new ModalBuilder().setTitle("Editing nickname").addComponents( new ActionRowBuilder().addComponents( new TextInputBuilder() diff --git a/src/commands/nucleus/stats.ts b/src/commands/nucleus/stats.ts index c2bf9a1..9690258 100644 --- a/src/commands/nucleus/stats.ts +++ b/src/commands/nucleus/stats.ts @@ -21,7 +21,6 @@ import config from "../../config/main.js"; const command = (builder: SlashCommandSubcommandBuilder) => builder.setName("stats").setDescription("Gets the bot's stats"); - const confirm = async (interaction: CommandInteraction) => { const requiredTexts = [ "just do it", @@ -36,23 +35,23 @@ const confirm = async (interaction: CommandInteraction) => { "what's a java script", "it's a feature not a bug", "that never happened during testing" - ] + ]; const chosen = requiredTexts[Math.floor(Math.random() * (requiredTexts.length - 1))]!; const modal = new ModalBuilder() - .addComponents( - new ActionRowBuilder().addComponents( - new TextInputBuilder() - .setStyle(TextInputStyle.Short) - .setLabel(`Type "${chosen}" below`) - .setCustomId("confirm") - .setPlaceholder("Guild ID") - .setMinLength(chosen.length) - .setMaxLength(chosen.length) - ) + .addComponents( + new ActionRowBuilder().addComponents( + new TextInputBuilder() + .setStyle(TextInputStyle.Short) + .setLabel(`Type "${chosen}" below`) + .setCustomId("confirm") + .setPlaceholder("Guild ID") + .setMinLength(chosen.length) + .setMaxLength(chosen.length) ) - .setTitle("Admin Panel") - .setCustomId("adminPanel"); + ) + .setTitle("Admin Panel") + .setCustomId("adminPanel"); await interaction.showModal(modal); let out: ModalSubmitInteraction; try { @@ -65,9 +64,8 @@ const confirm = async (interaction: CommandInteraction) => { } await out.deferUpdate(); const typed = out.fields.getTextInputValue("confirm"); - return typed.toLowerCase() === chosen.toLowerCase() -} - + return typed.toLowerCase() === chosen.toLowerCase(); +}; const callback = async (interaction: CommandInteraction): Promise => { const description = `**Servers:** ${client.guilds.cache.size}\n` + `**Ping:** \`${client.ws.ping * 2}ms\``; @@ -159,7 +157,7 @@ const callback = async (interaction: CommandInteraction): Promise => { new ButtonBuilder().setCustomId("data").setLabel("Guild data").setStyle(ButtonStyle.Secondary), new ButtonBuilder().setCustomId("cache").setLabel("Reset cache").setStyle(ButtonStyle.Success), new ButtonBuilder().setCustomId("leave").setLabel("Leave").setStyle(ButtonStyle.Danger), - new ButtonBuilder().setCustomId("purge").setLabel("Delete data").setStyle(ButtonStyle.Danger), + new ButtonBuilder().setCustomId("purge").setLabel("Delete data").setStyle(ButtonStyle.Danger) ) ] }); @@ -186,87 +184,79 @@ const callback = async (interaction: CommandInteraction): Promise => { await interaction.editReply({ embeds: [ new EmojiEmbed() - .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` + .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` ) .setStatus("Success") .setEmoji("SETTINGS.STATS.GREEN") - ] - }); - } else if (i.customId === "leave") { - if (!await confirm(interaction)) { - await interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setTitle("No changes were made") - .setStatus("Danger") - ], - components: [] - }); - return; - } - await guild.leave(); + ] + }); + } else if (i.customId === "leave") { + if (!(await confirm(interaction))) { await interaction.editReply({ - embeds: [ - new EmojiEmbed() + embeds: [new EmojiEmbed().setTitle("No changes were made").setStatus("Danger")], + components: [] + }); + return; + } + await guild.leave(); + await interaction.editReply({ + embeds: [ + new EmojiEmbed() .setTitle("Left") .setDescription(`Left ${guild.name}`) .setStatus("Success") .setEmoji("SETTINGS.STATS.GREEN") - ], - components: [] - }); - } else if (i.customId === "data") { - await i.deferUpdate(); - // Get all the data and convert to a string - const data = await client.database.guilds.read(guild.id); - const stringified = JSON.stringify(data, null, 2); - const buffer = Buffer.from(stringified); - const attachment = new AttachmentBuilder(buffer).setName("data.json"); + ], + components: [] + }); + } else if (i.customId === "data") { + await i.deferUpdate(); + // Get all the data and convert to a string + const data = await client.database.guilds.read(guild.id); + const stringified = JSON.stringify(data, null, 2); + const buffer = Buffer.from(stringified); + const attachment = new AttachmentBuilder(buffer).setName("data.json"); + await interaction.editReply({ + embeds: [ + new EmojiEmbed().setTitle("Data").setDescription(`Data for ${guild.name}`).setStatus("Success") + ], + components: [], + files: [attachment] + }); + } else if (i.customId === "purge") { + if (!(await confirm(interaction))) { await interaction.editReply({ - embeds: [ - new EmojiEmbed().setTitle("Data").setDescription(`Data for ${guild.name}`).setStatus("Success") - ], - components: [], - files: [attachment] + embeds: [new EmojiEmbed().setTitle("No changes were made").setStatus("Danger")], + components: [] }); - } else if (i.customId === "purge") { - if (!await confirm(interaction)) { - await interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setTitle("No changes were made") - .setStatus("Danger") - ], - components: [] - }); - return; - } - await client.database.guilds.delete(GuildID); - await client.database.history.delete(GuildID); - await client.database.notes.delete(GuildID); - await client.database.transcripts.deleteAll(GuildID); - await interaction.editReply({ - embeds: [ - new EmojiEmbed() + return; + } + await client.database.guilds.delete(GuildID); + await client.database.history.delete(GuildID); + await client.database.notes.delete(GuildID); + await client.database.transcripts.deleteAll(GuildID); + await interaction.editReply({ + embeds: [ + new EmojiEmbed() .setTitle("Purge") .setDescription(`Deleted data for ${guild.name}`) .setStatus("Success") .setEmoji("SETTINGS.STATS.GREEN") - ], - components: [] - }); - } else if (i.customId === "cache") { - await i.deferUpdate(); - await client.memory.forceUpdate(guild.id); - await interaction.editReply({ + ], + components: [] + }); + } else if (i.customId === "cache") { + await i.deferUpdate(); + await client.memory.forceUpdate(guild.id); + await interaction.editReply({ embeds: [ new EmojiEmbed() .setTitle("Cache") diff --git a/src/commands/nucleus/suggest.ts b/src/commands/nucleus/suggest.ts index 44926c7..c1f0312 100644 --- a/src/commands/nucleus/suggest.ts +++ b/src/commands/nucleus/suggest.ts @@ -1,92 +1,107 @@ import { LoadingEmbed } from "../../utils/defaults.js"; -import Discord, { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, ModalBuilder, TextInputBuilder, TextInputStyle } from "discord.js"; +import Discord, { + ActionRowBuilder, + ButtonBuilder, + ButtonStyle, + CommandInteraction, + ModalBuilder, + TextInputBuilder, + TextInputStyle +} from "discord.js"; import type { SlashCommandSubcommandBuilder } from "discord.js"; import confirmationMessage from "../../utils/confirmationMessage.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; import client from "../../utils/client.js"; -import config from "../../config/main.js" +import config from "../../config/main.js"; import _ from "lodash"; const command = (builder: SlashCommandSubcommandBuilder) => - builder - .setName("suggest") - .setDescription("Sends a suggestion to the developers") + builder.setName("suggest").setDescription("Sends a suggestion to the developers"); const callback = async (interaction: CommandInteraction): Promise => { await interaction.guild?.members.fetch(interaction.member!.user.id); await interaction.reply({ embeds: LoadingEmbed, ephemeral: true }); let closed = false; - let suggestionTitle: string | null = null + let suggestionTitle: string | null = null; let suggestionDesc: string | null = null; do { const modal = new ModalBuilder() .setTitle("Suggestion") .setComponents( - new ActionRowBuilder() - .addComponents( - new TextInputBuilder() - .setLabel("Suggestion Title") - .setRequired(false) - .setStyle(TextInputStyle.Short) - .setCustomId("suggestionTitle") - .setPlaceholder("Summarize your suggestion in 1 sentence...") - .setMaxLength(256) - ), - new ActionRowBuilder() - .addComponents( - new TextInputBuilder() - .setLabel("Suggestion Description") - .setCustomId("suggestionDesc") - .setStyle(TextInputStyle.Paragraph) - .setRequired(true) - .setPlaceholder("Put the full details of your suggestion here...") - .setMinLength(50) - ), - ) - const o: {suggestionDesc?: string, suggestionTitle?: string} = {}; - if(suggestionTitle) { + new ActionRowBuilder().addComponents( + new TextInputBuilder() + .setLabel("Suggestion Title") + .setRequired(false) + .setStyle(TextInputStyle.Short) + .setCustomId("suggestionTitle") + .setPlaceholder("Summarize your suggestion in 1 sentence...") + .setMaxLength(256) + ), + new ActionRowBuilder().addComponents( + new TextInputBuilder() + .setLabel("Suggestion Description") + .setCustomId("suggestionDesc") + .setStyle(TextInputStyle.Paragraph) + .setRequired(true) + .setPlaceholder("Put the full details of your suggestion here...") + .setMinLength(50) + ) + ); + const o: { suggestionDesc?: string; suggestionTitle?: string } = {}; + if (suggestionTitle) { o.suggestionTitle = suggestionTitle; modal.components[0]!.components[0]!.setValue(suggestionTitle); } - if(suggestionDesc) { - o.suggestionDesc = suggestionDesc + if (suggestionDesc) { + o.suggestionDesc = suggestionDesc; modal.components[1]!.components[0]!.setValue(suggestionDesc); - }; + } const confirmation = await new confirmationMessage(interaction) .setEmoji("ICONS.ADD") .setTitle("Suggest") - .setDescription(suggestionDesc ? (`Are you sure you want to send this suggestion?\n\n**Title ${suggestionTitle ? "" : "(*Placeholder*)"}:**\n> ${suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}`}\n\n**Suggestion:**\n> ${suggestionDesc}`) : "Please enter your suggestion below.") + .setDescription( + suggestionDesc + ? `Are you sure you want to send this suggestion?\n\n**Title ${ + suggestionTitle ? "" : "(*Placeholder*)" + }:**\n> ${ + suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}` + }\n\n**Suggestion:**\n> ${suggestionDesc}` + : "Please enter your suggestion below." + ) .addModal("Edit Suggestion", "ICONS.EDIT", "editSuggestion", _.cloneDeep(o), modal) .setColor("Success") .setInverted(true) .setFailedMessage("Your suggestion was deleted", "Success", "ICONS.ADD") .send(true); - if(confirmation.modals?.[0] && !_.isEqual(confirmation.modals[0].values, o)) { + if (confirmation.modals?.[0] && !_.isEqual(confirmation.modals[0].values, o)) { suggestionTitle = confirmation.modals[0].values["suggestionTitle"] as string | null; suggestionDesc = confirmation.modals[0].values["suggestionDesc"] as string | null; continue; } - if(confirmation.cancelled || confirmation.success === false) { + if (confirmation.cancelled || confirmation.success === false) { closed = true; return; } if (confirmation.success) { closed = true; - }; + } } while (!closed); - if(!suggestionDesc) return; + if (!suggestionDesc) return; suggestionTitle = suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}`; const channel = client.channels.cache.get(config.suggestionChannel) as Discord.TextChannel; - const m = await channel.send({ embeds: LoadingEmbed}); + const m = await channel.send({ embeds: LoadingEmbed }); const issue = await client.GitHub.rest.issues.create({ owner: "ClicksMinutePer", repo: "Nucleus", title: suggestionTitle, - body: `Linked Suggestion in Private Developer Channel: [Message](${m.url})\n\n**Suggestion:**\n> ${ - suggestionDesc.replaceAll("@", "@").replaceAll("/issues", "/issues").replaceAll("/pull", "/pull") - }\n\n`, + body: `Linked Suggestion in Private Developer Channel: [Message](${ + m.url + })\n\n**Suggestion:**\n> ${suggestionDesc + .replaceAll("@", "@") + .replaceAll("/issues", "/issues") + .replaceAll("/pull", "/pull")}\n\n`, labels: ["🤖 Auto", "📝 Suggestion"] - }) + }); await m.edit({ embeds: [ new EmojiEmbed() @@ -94,22 +109,28 @@ const callback = async (interaction: CommandInteraction): Promise => { .setTitle(`Suggestion from ${interaction.user.tag} (${interaction.user.id})`) .setDescription(`**Suggestion:**\n> ${suggestionDesc}\n\n`) .setStatus("Success") - .setFooter({text: `${issue.data.number}`}) + .setFooter({ text: `${issue.data.number}` }) ], components: [ new Discord.ActionRowBuilder().addComponents( new ButtonBuilder().setCustomId("accept:Suggestion").setLabel("Accept").setStyle(ButtonStyle.Success), new ButtonBuilder().setCustomId("deny:Suggestion").setLabel("Deny").setStyle(ButtonStyle.Danger), new ButtonBuilder().setCustomId("close:Suggestion").setLabel("Close").setStyle(ButtonStyle.Secondary), - new ButtonBuilder().setCustomId("implemented:Suggestion").setLabel("Implemented").setStyle(ButtonStyle.Secondary), - new ButtonBuilder().setLabel(`Open Issue #${issue.data.number}`).setStyle(ButtonStyle.Link).setURL(`https://github.com/ClicksMinutePer/Nucleus/issues/${issue.data.number}`), + new ButtonBuilder() + .setCustomId("implemented:Suggestion") + .setLabel("Implemented") + .setStyle(ButtonStyle.Secondary), + new ButtonBuilder() + .setLabel(`Open Issue #${issue.data.number}`) + .setStyle(ButtonStyle.Link) + .setURL(`https://github.com/ClicksMinutePer/Nucleus/issues/${issue.data.number}`) ), new Discord.ActionRowBuilder().addComponents( new ButtonBuilder().setCustomId("lock:Suggestion").setLabel("Lock").setStyle(ButtonStyle.Danger), - new ButtonBuilder().setCustomId("spam:Suggestion").setLabel("Mark as Spam").setStyle(ButtonStyle.Danger), + new ButtonBuilder().setCustomId("spam:Suggestion").setLabel("Mark as Spam").setStyle(ButtonStyle.Danger) ) ] - }) + }); await interaction.editReply({ embeds: [ new EmojiEmbed() diff --git a/src/commands/privacy.ts b/src/commands/privacy.ts index 7fefa36..587a7bc 100644 --- a/src/commands/privacy.ts +++ b/src/commands/privacy.ts @@ -45,8 +45,8 @@ const callback = async (interaction: CommandInteraction): Promise => { .setDescription( "Nucleus scans content sent by users for malware and NSFW content\n" + 'Malware is detected using [ClamAV](https://clamav.net/), and the standard ClamAV database."\n' + - 'NSFW detection is provided by [NsfwJS](https://nsfwjs.com/), with a model provided by [GantMan](https://github.com/GantMan/nsfw_model/releases/tag/1.1.0)\n\n' + - 'All data is processed on our servers and is not processed by a 3rd party.' + "NSFW detection is provided by [NsfwJS](https://nsfwjs.com/), with a model provided by [GantMan](https://github.com/GantMan/nsfw_model/releases/tag/1.1.0)\n\n" + + "All data is processed on our servers and is not processed by a 3rd party." ) .setEmoji("NUCLEUS.LOGO") .setStatus("Danger") diff --git a/src/commands/settings/automod.ts b/src/commands/settings/automod.ts index 68454e4..471af80 100644 --- a/src/commands/settings/automod.ts +++ b/src/commands/settings/automod.ts @@ -718,7 +718,7 @@ const mentionMenu = async ( .setEmoji("GUILD.SETTINGS.GREEN") .setFooter({ text: unsavedChanges ? "No changes made" : "Changes not saved" - });; + }); await interaction.editReply({ embeds: [embed], components: [menu, allowedMenu, buttons] }); @@ -1047,11 +1047,14 @@ const callback = async (interaction: CommandInteraction): Promise => { let closed = false; - let current = _.cloneDeep(config); do { const button = new ActionRowBuilder().addComponents( - new ButtonBuilder().setCustomId("save").setLabel("Save").setStyle(ButtonStyle.Success).setDisabled(_.isEqual(config, current)) + new ButtonBuilder() + .setCustomId("save") + .setLabel("Save") + .setStyle(ButtonStyle.Success) + .setDisabled(_.isEqual(config, current)) ); const selectMenu = new ActionRowBuilder().addComponents( new StringSelectMenuBuilder() @@ -1116,7 +1119,7 @@ const callback = async (interaction: CommandInteraction): Promise => { continue; } await i.deferUpdate(); - if(i.isButton()) { + if (i.isButton()) { await client.database.guilds.write(interaction.guild.id, { filters: current }); await client.memory.forceUpdate(interaction.guild.id); config = current; diff --git a/src/config/format.ts b/src/config/format.ts index da1815c..042d173 100644 --- a/src/config/format.ts +++ b/src/config/format.ts @@ -131,7 +131,7 @@ export default async function (walkthrough = false) { } if (walkthrough && !(json["mongoUrl"] ?? false)) json["mongoUrl"] = "mongodb://127.0.0.1:27017"; if (!((json["baseUrl"] as string | undefined) ?? "").endsWith("/")) (json["baseUrl"] as string) += "/"; - const localhost = "127.0.0.1" + const localhost = "127.0.0.1"; json["mongoUrl"] = (json["mongoUrl"]! as string).replace("localhost", localhost); json["baseUrl"] = (json["baseUrl"]! as string).replace("localhost", localhost); json["mongoOptions"] = { @@ -145,7 +145,7 @@ export default async function (walkthrough = false) { socket: json["clamAVSocket"] as string | undefined, host: json["clamAVHost"] as string | undefined, port: json["clamAVPort"] as number | undefined - } + }; fs.writeFileSync("./src/config/main.ts", "export default " + JSON.stringify(json, null, 4) + ";"); diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index e27ee69..9d3dceb 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -4,7 +4,18 @@ import create from "../actions/tickets/create.js"; import close from "../actions/tickets/delete.js"; import createTranscript from "../premium/createTranscript.js"; -import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, Interaction, InteractionEditReplyOptions, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } from "discord.js"; +import { + ActionRowBuilder, + ButtonBuilder, + ButtonInteraction, + ButtonStyle, + Interaction, + InteractionEditReplyOptions, + ModalBuilder, + ModalSubmitInteraction, + TextInputBuilder, + TextInputStyle +} from "discord.js"; import type { NucleusClient } from "../utils/client.js"; import EmojiEmbed from "../utils/generateEmojiEmbed.js"; @@ -28,7 +39,10 @@ async function errorMessage(interaction: ButtonInteraction, message: string) { async function interactionCreate(interaction: Interaction) { if (interaction.isButton()) { if (interaction.customId.endsWith(":Suggestion")) { - const value = interaction.customId.startsWith("accept") || interaction.customId.startsWith("implement") ? true : false + const value = + interaction.customId.startsWith("accept") || interaction.customId.startsWith("implement") + ? true + : false; return await modifySuggestion(interaction, value); } switch (interaction.customId) { @@ -88,10 +102,7 @@ const getReason = async (buttonInteraction: ButtonInteraction, prompt: string) = const modal = new ModalBuilder() .addComponents( new ActionRowBuilder().addComponents( - new TextInputBuilder() - .setStyle(TextInputStyle.Paragraph) - .setLabel(prompt) - .setCustomId("typed") + new TextInputBuilder().setStyle(TextInputStyle.Paragraph).setLabel(prompt).setCustomId("typed") ) ) .setTitle("Reason") @@ -108,74 +119,95 @@ const getReason = async (buttonInteraction: ButtonInteraction, prompt: string) = } await out.deferUpdate(); return out.fields.getTextInputValue("typed"); -} +}; async function modifySuggestion(interaction: ButtonInteraction, accept: boolean) { const message = interaction.message; await message.fetch(); if (message.embeds.length === 0) return; const embed = message.embeds[0]!; - const issueNum = embed.footer!.text - if(!issueNum) return; + const issueNum = embed.footer!.text; + if (!issueNum) return; const issue = { owner: "ClicksMinutePer", repo: "Nucleus", issue_number: parseInt(issueNum) - } + }; let name = "Unknown"; const components: InteractionEditReplyOptions["components"] = []; - switch(interaction.customId) { + switch (interaction.customId) { case "accept:Suggestion": { name = "Accepted"; await interaction.deferUpdate(); - await client.GitHub.rest.issues.createComment({...issue, body: "Suggestion accepted by " + interaction.user.tag}); - components.push(new ActionRowBuilder().addComponents( - new ButtonBuilder().setCustomId("close:Suggestion").setLabel("Close").setStyle(ButtonStyle.Secondary), - new ButtonBuilder().setCustomId("implemented:Suggestion").setLabel("Implemented").setStyle(ButtonStyle.Secondary) - )) + await client.GitHub.rest.issues.createComment({ + ...issue, + body: "Suggestion accepted by " + interaction.user.tag + }); + components.push( + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("close:Suggestion") + .setLabel("Close") + .setStyle(ButtonStyle.Secondary), + new ButtonBuilder() + .setCustomId("implemented:Suggestion") + .setLabel("Implemented") + .setStyle(ButtonStyle.Secondary) + ) + ); break; } case "deny:Suggestion": { name = "Denied"; const reason = await getReason(interaction, "Reason for denial"); - await client.GitHub.rest.issues.createComment({...issue, body: "Suggestion denied by " + interaction.user.tag + " for reason:\n>" + reason}); - await client.GitHub.rest.issues.update({...issue, state: "closed", state_reason: "not_planned"}); + await client.GitHub.rest.issues.createComment({ + ...issue, + body: "Suggestion denied by " + interaction.user.tag + " for reason:\n>" + reason + }); + await client.GitHub.rest.issues.update({ ...issue, state: "closed", state_reason: "not_planned" }); // await client.GitHub.rest.issues.lock({...issue, lock_reason: "resolved"}) - components.push(new ActionRowBuilder().addComponents( - new ButtonBuilder().setCustomId("lock:Suggestion").setLabel("Lock").setStyle(ButtonStyle.Danger) - )) + components.push( + new ActionRowBuilder().addComponents( + new ButtonBuilder().setCustomId("lock:Suggestion").setLabel("Lock").setStyle(ButtonStyle.Danger) + ) + ); break; } case "close:Suggestion": { name = "Closed"; const reason = await getReason(interaction, "Reason for closing"); - await client.GitHub.rest.issues.createComment({...issue, body: "Suggestion closed by " + interaction.user.tag + " for reason:\n>" + reason}); - await client.GitHub.rest.issues.update({...issue, state: "closed"}); + await client.GitHub.rest.issues.createComment({ + ...issue, + body: "Suggestion closed by " + interaction.user.tag + " for reason:\n>" + reason + }); + await client.GitHub.rest.issues.update({ ...issue, state: "closed" }); // await client.GitHub.rest.issues.lock({...issue}) - components.push(new ActionRowBuilder().addComponents( - new ButtonBuilder().setCustomId("lock:Suggestion").setLabel("Lock").setStyle(ButtonStyle.Danger) - )) + components.push( + new ActionRowBuilder().addComponents( + new ButtonBuilder().setCustomId("lock:Suggestion").setLabel("Lock").setStyle(ButtonStyle.Danger) + ) + ); break; } case "implement:Suggestion": { name = "Implemented"; await interaction.deferUpdate(); - await client.GitHub.rest.issues.createComment({...issue, body: "Suggestion implemented"}); - await client.GitHub.rest.issues.update({...issue, state: "closed", state_reason: "completed"}); - await client.GitHub.rest.issues.lock({...issue, lock_reason: "resolved"}) + await client.GitHub.rest.issues.createComment({ ...issue, body: "Suggestion implemented" }); + await client.GitHub.rest.issues.update({ ...issue, state: "closed", state_reason: "completed" }); + await client.GitHub.rest.issues.lock({ ...issue, lock_reason: "resolved" }); break; } case "lock:Suggestion": { name = "Locked"; await interaction.deferUpdate(); - await client.GitHub.rest.issues.lock({...issue}); + await client.GitHub.rest.issues.lock({ ...issue }); break; } case "spam:Suggestion": { name = "Marked as Spam"; await interaction.deferUpdate(); - await client.GitHub.rest.issues.update({...issue, state: "closed", state_reason: "not_planned"}); - await client.GitHub.rest.issues.lock({...issue, lock_reason: "spam"}) + await client.GitHub.rest.issues.update({ ...issue, state: "closed", state_reason: "not_planned" }); + await client.GitHub.rest.issues.lock({ ...issue, lock_reason: "spam" }); break; } } @@ -189,7 +221,7 @@ async function modifySuggestion(interaction: ButtonInteraction, accept: boolean) .setDescription(embed!.description!) .setFields({ name: name + " by", - value: interaction.user.tag, + value: interaction.user.tag }) .setStatus(newcolor) .setFooter(embed!.footer); diff --git a/src/utils/confirmationMessage.ts b/src/utils/confirmationMessage.ts index f1229eb..0e4a9b4 100644 --- a/src/utils/confirmationMessage.ts +++ b/src/utils/confirmationMessage.ts @@ -106,7 +106,13 @@ class confirmationMessage { this.reason = reason; return this; } - addModal(buttonText: string, emoji: string, customId: string, current: Record, modal: Discord.ModalBuilder) { + addModal( + buttonText: string, + emoji: string, + customId: string, + current: Record, + modal: Discord.ModalBuilder + ) { modal.setCustomId(customId); this.modals.push({ buttonText, emoji, customId, modal, values: current }); return this;