blob: 1110b9aa7dec8cb1e4b1a4f2c4a8822e5e4a3d85 [file] [log] [blame]
Skyler Greyda16adf2023-03-05 10:22:12 +00001import { LoadingEmbed } from "../../utils/defaults.js";
TheCodedProfca29ebb2023-03-10 17:40:09 -05002import Discord, {
3 ActionRowBuilder,
4 ButtonBuilder,
5 ButtonStyle,
6 CommandInteraction,
7 ModalBuilder,
8 TextInputBuilder,
9 TextInputStyle
10} from "discord.js";
TheCodedProff86ba092023-01-27 17:10:07 -050011import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan377794f2022-04-18 19:01:01 +010012import confirmationMessage from "../../utils/confirmationMessage.js";
pineafan4edb7762022-06-26 19:21:04 +010013import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
pineafan63fc5e22022-08-04 22:04:10 +010014import client from "../../utils/client.js";
TheCodedProfca29ebb2023-03-10 17:40:09 -050015import config from "../../config/main.js";
TheCodedProf35e73712023-03-10 17:35:35 -050016import _ from "lodash";
pineafan4f164f32022-02-26 22:07:12 +000017
18const command = (builder: SlashCommandSubcommandBuilder) =>
TheCodedProfca29ebb2023-03-10 17:40:09 -050019 builder.setName("suggest").setDescription("Sends a suggestion to the developers");
pineafan4f164f32022-02-26 22:07:12 +000020
pineafanbd02b4a2022-08-05 22:01:38 +010021const callback = async (interaction: CommandInteraction): Promise<void> => {
Skyler Greyda16adf2023-03-05 10:22:12 +000022 await interaction.reply({ embeds: LoadingEmbed, ephemeral: true });
TheCodedProf35e73712023-03-10 17:35:35 -050023 let closed = false;
TheCodedProfca29ebb2023-03-10 17:40:09 -050024 let suggestionTitle: string | null = null;
TheCodedProf35e73712023-03-10 17:35:35 -050025 let suggestionDesc: string | null = null;
26 do {
27 const modal = new ModalBuilder()
28 .setTitle("Suggestion")
29 .setComponents(
TheCodedProfca29ebb2023-03-10 17:40:09 -050030 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) {
TheCodedProf35e73712023-03-10 17:35:35 -050051 o.suggestionTitle = suggestionTitle;
52 modal.components[0]!.components[0]!.setValue(suggestionTitle);
53 }
TheCodedProfca29ebb2023-03-10 17:40:09 -050054 if (suggestionDesc) {
55 o.suggestionDesc = suggestionDesc;
TheCodedProf35e73712023-03-10 17:35:35 -050056 modal.components[1]!.components[0]!.setValue(suggestionDesc);
TheCodedProfca29ebb2023-03-10 17:40:09 -050057 }
TheCodedProf35e73712023-03-10 17:35:35 -050058 const confirmation = await new confirmationMessage(interaction)
59 .setEmoji("ICONS.ADD")
60 .setTitle("Suggest")
TheCodedProfca29ebb2023-03-10 17:40:09 -050061 .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 )
TheCodedProf35e73712023-03-10 17:35:35 -050070 .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);
TheCodedProfca29ebb2023-03-10 17:40:09 -050075 if (confirmation.modals?.[0] && !_.isEqual(confirmation.modals[0].values, o)) {
TheCodedProf35e73712023-03-10 17:35:35 -050076 suggestionTitle = confirmation.modals[0].values["suggestionTitle"] as string | null;
77 suggestionDesc = confirmation.modals[0].values["suggestionDesc"] as string | null;
78 continue;
79 }
TheCodedProfca29ebb2023-03-10 17:40:09 -050080 if (confirmation.cancelled || confirmation.success === false) {
TheCodedProf35e73712023-03-10 17:35:35 -050081 closed = true;
82 return;
83 }
84 if (confirmation.success) {
85 closed = true;
TheCodedProfca29ebb2023-03-10 17:40:09 -050086 }
TheCodedProf35e73712023-03-10 17:35:35 -050087 } while (!closed);
TheCodedProfca29ebb2023-03-10 17:40:09 -050088 if (!suggestionDesc) return;
TheCodedProf35e73712023-03-10 17:35:35 -050089 suggestionTitle = suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}`;
90 const channel = client.channels.cache.get(config.suggestionChannel) as Discord.TextChannel;
TheCodedProfca29ebb2023-03-10 17:40:09 -050091 const m = await channel.send({ embeds: LoadingEmbed });
pineafandef38a72023-05-28 12:47:36 +010092 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;
TheCodedProf35e73712023-03-10 17:35:35 -0500111 await m.edit({
PineaFan0d06edc2023-01-17 22:10:31 +0000112 embeds: [
113 new EmojiEmbed()
TheCodedProf35e73712023-03-10 17:35:35 -0500114 .setEmoji("ICONS.ADD")
115 .setTitle(`Suggestion from ${interaction.user.tag} (${interaction.user.id})`)
116 .setDescription(`**Suggestion:**\n> ${suggestionDesc}\n\n`)
117 .setStatus("Success")
pineafandef38a72023-05-28 12:47:36 +0100118 .setFooter({ text: `${issueNumber ? issueNumber : "Could not connect to GitHub"}` })
Skyler Greyda16adf2023-03-05 10:22:12 +0000119 ],
120 components: [
TheCodedProf35e73712023-03-10 17:35:35 -0500121 new Discord.ActionRowBuilder<ButtonBuilder>().addComponents(
pineafan72659cc2023-05-28 13:36:44 +0100122 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),
TheCodedProfca29ebb2023-03-10 17:40:09 -0500137 new ButtonBuilder()
138 .setCustomId("implemented:Suggestion")
139 .setLabel("Implemented")
pineafandef38a72023-05-28 12:47:36 +0100140 .setStyle(ButtonStyle.Secondary)
141 .setDisabled(disabled),
TheCodedProfca29ebb2023-03-10 17:40:09 -0500142 new ButtonBuilder()
pineafandef38a72023-05-28 12:47:36 +0100143 .setLabel(`Open Issue #${issueNumber ? issueNumber : "0"}`)
TheCodedProfca29ebb2023-03-10 17:40:09 -0500144 .setStyle(ButtonStyle.Link)
pineafandef38a72023-05-28 12:47:36 +0100145 .setURL(`https://github.com/ClicksMinutePer/Nucleus/issues/${issueNumber}`)
146 .setDisabled(disabled)
TheCodedProf35e73712023-03-10 17:35:35 -0500147 ),
148 new Discord.ActionRowBuilder<ButtonBuilder>().addComponents(
pineafan72659cc2023-05-28 13:36:44 +0100149 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 Greyda16adf2023-03-05 10:22:12 +0000159 )
160 ]
TheCodedProfca29ebb2023-03-10 17:40:09 -0500161 });
PineaFan0d06edc2023-01-17 22:10:31 +0000162 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 });
pineafan63fc5e22022-08-04 22:04:10 +0100172};
pineafan4f164f32022-02-26 22:07:12 +0000173
pineafan4f164f32022-02-26 22:07:12 +0000174export { command };
175export { callback };