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.guild?.members.fetch(interaction.member!.user.id); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 23 | await interaction.reply({ embeds: LoadingEmbed, ephemeral: true }); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 24 | let closed = false; |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 25 | let suggestionTitle: string | null = null; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 26 | let suggestionDesc: string | null = null; |
| 27 | do { |
| 28 | const modal = new ModalBuilder() |
| 29 | .setTitle("Suggestion") |
| 30 | .setComponents( |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 31 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 32 | new TextInputBuilder() |
| 33 | .setLabel("Suggestion Title") |
| 34 | .setRequired(false) |
| 35 | .setStyle(TextInputStyle.Short) |
| 36 | .setCustomId("suggestionTitle") |
| 37 | .setPlaceholder("Summarize your suggestion in 1 sentence...") |
| 38 | .setMaxLength(256) |
| 39 | ), |
| 40 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 41 | new TextInputBuilder() |
| 42 | .setLabel("Suggestion Description") |
| 43 | .setCustomId("suggestionDesc") |
| 44 | .setStyle(TextInputStyle.Paragraph) |
| 45 | .setRequired(true) |
| 46 | .setPlaceholder("Put the full details of your suggestion here...") |
| 47 | .setMinLength(50) |
| 48 | ) |
| 49 | ); |
| 50 | const o: { suggestionDesc?: string; suggestionTitle?: string } = {}; |
| 51 | if (suggestionTitle) { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 52 | o.suggestionTitle = suggestionTitle; |
| 53 | modal.components[0]!.components[0]!.setValue(suggestionTitle); |
| 54 | } |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 55 | if (suggestionDesc) { |
| 56 | o.suggestionDesc = suggestionDesc; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 57 | modal.components[1]!.components[0]!.setValue(suggestionDesc); |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 58 | } |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 59 | const confirmation = await new confirmationMessage(interaction) |
| 60 | .setEmoji("ICONS.ADD") |
| 61 | .setTitle("Suggest") |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 62 | .setDescription( |
| 63 | suggestionDesc |
| 64 | ? `Are you sure you want to send this suggestion?\n\n**Title ${ |
| 65 | suggestionTitle ? "" : "(*Placeholder*)" |
| 66 | }:**\n> ${ |
| 67 | suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}` |
| 68 | }\n\n**Suggestion:**\n> ${suggestionDesc}` |
| 69 | : "Please enter your suggestion below." |
| 70 | ) |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 71 | .addModal("Edit Suggestion", "ICONS.EDIT", "editSuggestion", _.cloneDeep(o), modal) |
| 72 | .setColor("Success") |
| 73 | .setInverted(true) |
| 74 | .setFailedMessage("Your suggestion was deleted", "Success", "ICONS.ADD") |
| 75 | .send(true); |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 76 | if (confirmation.modals?.[0] && !_.isEqual(confirmation.modals[0].values, o)) { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 77 | suggestionTitle = confirmation.modals[0].values["suggestionTitle"] as string | null; |
| 78 | suggestionDesc = confirmation.modals[0].values["suggestionDesc"] as string | null; |
| 79 | continue; |
| 80 | } |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 81 | if (confirmation.cancelled || confirmation.success === false) { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 82 | closed = true; |
| 83 | return; |
| 84 | } |
| 85 | if (confirmation.success) { |
| 86 | closed = true; |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 87 | } |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 88 | } while (!closed); |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 89 | if (!suggestionDesc) return; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 90 | suggestionTitle = suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}`; |
| 91 | const channel = client.channels.cache.get(config.suggestionChannel) as Discord.TextChannel; |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 92 | const m = await channel.send({ embeds: LoadingEmbed }); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 93 | const issue = await client.GitHub.rest.issues.create({ |
| 94 | owner: "ClicksMinutePer", |
| 95 | repo: "Nucleus", |
| 96 | title: suggestionTitle, |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 97 | body: `Linked Suggestion in Private Developer Channel: [Message](${ |
| 98 | m.url |
| 99 | })\n\n**Suggestion:**\n> ${suggestionDesc |
| 100 | .replaceAll("@", "@<!-- -->") |
| 101 | .replaceAll("/issues", "/issues<!-- -->") |
| 102 | .replaceAll("/pull", "/pull<!-- -->")}\n\n`, |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 103 | labels: ["🤖 Auto", "📝 Suggestion"] |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 104 | }); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 105 | await m.edit({ |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 106 | embeds: [ |
| 107 | new EmojiEmbed() |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 108 | .setEmoji("ICONS.ADD") |
| 109 | .setTitle(`Suggestion from ${interaction.user.tag} (${interaction.user.id})`) |
| 110 | .setDescription(`**Suggestion:**\n> ${suggestionDesc}\n\n`) |
| 111 | .setStatus("Success") |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 112 | .setFooter({ text: `${issue.data.number}` }) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 113 | ], |
| 114 | components: [ |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 115 | new Discord.ActionRowBuilder<ButtonBuilder>().addComponents( |
| 116 | new ButtonBuilder().setCustomId("accept:Suggestion").setLabel("Accept").setStyle(ButtonStyle.Success), |
| 117 | new ButtonBuilder().setCustomId("deny:Suggestion").setLabel("Deny").setStyle(ButtonStyle.Danger), |
| 118 | new ButtonBuilder().setCustomId("close:Suggestion").setLabel("Close").setStyle(ButtonStyle.Secondary), |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 119 | new ButtonBuilder() |
| 120 | .setCustomId("implemented:Suggestion") |
| 121 | .setLabel("Implemented") |
| 122 | .setStyle(ButtonStyle.Secondary), |
| 123 | new ButtonBuilder() |
| 124 | .setLabel(`Open Issue #${issue.data.number}`) |
| 125 | .setStyle(ButtonStyle.Link) |
| 126 | .setURL(`https://github.com/ClicksMinutePer/Nucleus/issues/${issue.data.number}`) |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 127 | ), |
| 128 | new Discord.ActionRowBuilder<ButtonBuilder>().addComponents( |
| 129 | new ButtonBuilder().setCustomId("lock:Suggestion").setLabel("Lock").setStyle(ButtonStyle.Danger), |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 130 | new ButtonBuilder().setCustomId("spam:Suggestion").setLabel("Mark as Spam").setStyle(ButtonStyle.Danger) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 131 | ) |
| 132 | ] |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 133 | }); |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 134 | await interaction.editReply({ |
| 135 | embeds: [ |
| 136 | new EmojiEmbed() |
| 137 | .setEmoji("ICONS.ADD") |
| 138 | .setTitle("Suggest") |
| 139 | .setDescription("Your suggestion was sent successfully") |
| 140 | .setStatus("Success") |
| 141 | ], |
| 142 | components: [] |
| 143 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 144 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 145 | |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 146 | export { command }; |
| 147 | export { callback }; |