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