Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1 | import { LoadingEmbed } from "../../utils/defaults.js"; |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 2 | import Discord, { |
| 3 | ActionRowBuilder, |
| 4 | ButtonBuilder, |
| 5 | ButtonStyle, |
| 6 | CommandInteraction, |
| 7 | ModalBuilder, |
| 8 | TextInputBuilder, |
| 9 | TextInputStyle |
| 10 | } from "discord.js"; |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 11 | import type { SlashCommandSubcommandBuilder } from "discord.js"; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 12 | import confirmationMessage from "../../utils/confirmationMessage.js"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 13 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | import client from "../../utils/client.js"; |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 15 | import config from "../../config/main.js"; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 16 | import _ from "lodash"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 17 | |
| 18 | const command = (builder: SlashCommandSubcommandBuilder) => |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 19 | builder.setName("suggest").setDescription("Sends a suggestion to the developers"); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 20 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 21 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 22 | await interaction.reply({ embeds: LoadingEmbed, ephemeral: true }); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 23 | let closed = false; |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 24 | let suggestionTitle: string | null = null; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 25 | let suggestionDesc: string | null = null; |
| 26 | do { |
| 27 | const modal = new ModalBuilder() |
| 28 | .setTitle("Suggestion") |
| 29 | .setComponents( |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 30 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 31 | new TextInputBuilder() |
| 32 | .setLabel("Suggestion Title") |
| 33 | .setRequired(false) |
| 34 | .setStyle(TextInputStyle.Short) |
| 35 | .setCustomId("suggestionTitle") |
| 36 | .setPlaceholder("Summarize your suggestion in 1 sentence...") |
| 37 | .setMaxLength(256) |
| 38 | ), |
| 39 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 40 | new TextInputBuilder() |
| 41 | .setLabel("Suggestion Description") |
| 42 | .setCustomId("suggestionDesc") |
| 43 | .setStyle(TextInputStyle.Paragraph) |
| 44 | .setRequired(true) |
| 45 | .setPlaceholder("Put the full details of your suggestion here...") |
| 46 | .setMinLength(50) |
| 47 | ) |
| 48 | ); |
| 49 | const o: { suggestionDesc?: string; suggestionTitle?: string } = {}; |
| 50 | if (suggestionTitle) { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 51 | o.suggestionTitle = suggestionTitle; |
| 52 | modal.components[0]!.components[0]!.setValue(suggestionTitle); |
| 53 | } |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 54 | if (suggestionDesc) { |
| 55 | o.suggestionDesc = suggestionDesc; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 56 | modal.components[1]!.components[0]!.setValue(suggestionDesc); |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 57 | } |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 58 | const confirmation = await new confirmationMessage(interaction) |
| 59 | .setEmoji("ICONS.ADD") |
| 60 | .setTitle("Suggest") |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 61 | .setDescription( |
| 62 | suggestionDesc |
| 63 | ? `Are you sure you want to send this suggestion?\n\n**Title ${ |
| 64 | suggestionTitle ? "" : "(*Placeholder*)" |
| 65 | }:**\n> ${ |
| 66 | suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}` |
| 67 | }\n\n**Suggestion:**\n> ${suggestionDesc}` |
| 68 | : "Please enter your suggestion below." |
| 69 | ) |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 70 | .addModal("Edit Suggestion", "ICONS.EDIT", "editSuggestion", _.cloneDeep(o), modal) |
| 71 | .setColor("Success") |
| 72 | .setInverted(true) |
| 73 | .setFailedMessage("Your suggestion was deleted", "Success", "ICONS.ADD") |
| 74 | .send(true); |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 75 | if (confirmation.modals?.[0] && !_.isEqual(confirmation.modals[0].values, o)) { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 76 | suggestionTitle = confirmation.modals[0].values["suggestionTitle"] as string | null; |
| 77 | suggestionDesc = confirmation.modals[0].values["suggestionDesc"] as string | null; |
| 78 | continue; |
| 79 | } |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 80 | if (confirmation.cancelled || confirmation.success === false) { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 81 | closed = true; |
| 82 | return; |
| 83 | } |
| 84 | if (confirmation.success) { |
| 85 | closed = true; |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 86 | } |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 87 | } while (!closed); |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 88 | if (!suggestionDesc) return; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 89 | suggestionTitle = suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}`; |
| 90 | const channel = client.channels.cache.get(config.suggestionChannel) as Discord.TextChannel; |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 91 | const m = await channel.send({ embeds: LoadingEmbed }); |
pineafan | def38a7 | 2023-05-28 12:47:36 +0100 | [diff] [blame] | 92 | let issueNumber: number | null = null; |
| 93 | try { |
| 94 | const issue = await client.GitHub.rest.issues.create({ |
| 95 | owner: "ClicksMinutePer", |
| 96 | repo: "Nucleus", |
| 97 | title: suggestionTitle, |
| 98 | body: `Linked Suggestion in Private Developer Channel: [Message](${ |
| 99 | m.url |
| 100 | })\n\n**Suggestion:**\n> ${suggestionDesc |
| 101 | .replaceAll("@", "@<!-- -->") |
| 102 | .replaceAll("/issues", "/issues<!-- -->") |
| 103 | .replaceAll("/pull", "/pull<!-- -->")}\n\n`, |
| 104 | labels: ["🤖 Auto", "📝 Suggestion"] |
| 105 | }); |
| 106 | issueNumber = issue.data.number; |
| 107 | } catch (_e) { |
| 108 | console.log("Could not connect to GitHub"); |
| 109 | } |
| 110 | const disabled = issueNumber ? false : true; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 111 | await m.edit({ |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 112 | embeds: [ |
| 113 | new EmojiEmbed() |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 114 | .setEmoji("ICONS.ADD") |
| 115 | .setTitle(`Suggestion from ${interaction.user.tag} (${interaction.user.id})`) |
| 116 | .setDescription(`**Suggestion:**\n> ${suggestionDesc}\n\n`) |
| 117 | .setStatus("Success") |
pineafan | def38a7 | 2023-05-28 12:47:36 +0100 | [diff] [blame] | 118 | .setFooter({ text: `${issueNumber ? issueNumber : "Could not connect to GitHub"}` }) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 119 | ], |
| 120 | components: [ |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 121 | new Discord.ActionRowBuilder<ButtonBuilder>().addComponents( |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 122 | new ButtonBuilder() |
| 123 | .setCustomId("accept:Suggestion") |
| 124 | .setLabel("Accept") |
| 125 | .setStyle(ButtonStyle.Success) |
| 126 | .setDisabled(disabled), |
| 127 | new ButtonBuilder() |
| 128 | .setCustomId("deny:Suggestion") |
| 129 | .setLabel("Deny") |
| 130 | .setStyle(ButtonStyle.Danger) |
| 131 | .setDisabled(disabled), |
| 132 | new ButtonBuilder() |
| 133 | .setCustomId("close:Suggestion") |
| 134 | .setLabel("Close") |
| 135 | .setStyle(ButtonStyle.Secondary) |
| 136 | .setDisabled(disabled), |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 137 | new ButtonBuilder() |
| 138 | .setCustomId("implemented:Suggestion") |
| 139 | .setLabel("Implemented") |
pineafan | def38a7 | 2023-05-28 12:47:36 +0100 | [diff] [blame] | 140 | .setStyle(ButtonStyle.Secondary) |
| 141 | .setDisabled(disabled), |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 142 | new ButtonBuilder() |
pineafan | def38a7 | 2023-05-28 12:47:36 +0100 | [diff] [blame] | 143 | .setLabel(`Open Issue #${issueNumber ? issueNumber : "0"}`) |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 144 | .setStyle(ButtonStyle.Link) |
pineafan | def38a7 | 2023-05-28 12:47:36 +0100 | [diff] [blame] | 145 | .setURL(`https://github.com/ClicksMinutePer/Nucleus/issues/${issueNumber}`) |
| 146 | .setDisabled(disabled) |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 147 | ), |
| 148 | new Discord.ActionRowBuilder<ButtonBuilder>().addComponents( |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 149 | new ButtonBuilder() |
| 150 | .setCustomId("lock:Comment") |
| 151 | .setLabel("Lock") |
| 152 | .setStyle(ButtonStyle.Danger) |
| 153 | .setDisabled(disabled), |
| 154 | new ButtonBuilder() |
| 155 | .setCustomId("spam:Suggestion") |
| 156 | .setLabel("Mark as Spam") |
| 157 | .setStyle(ButtonStyle.Danger) |
| 158 | .setDisabled(disabled) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 159 | ) |
| 160 | ] |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 161 | }); |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 162 | await interaction.editReply({ |
| 163 | embeds: [ |
| 164 | new EmojiEmbed() |
| 165 | .setEmoji("ICONS.ADD") |
| 166 | .setTitle("Suggest") |
| 167 | .setDescription("Your suggestion was sent successfully") |
| 168 | .setStatus("Success") |
| 169 | ], |
| 170 | components: [] |
| 171 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 172 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 173 | |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 174 | export { command }; |
| 175 | export { callback }; |