blob: f6755e2f676c36f4d9b88d456f6f4724c5caf38d [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(
pineafandef38a72023-05-28 12:47:36 +0100122 new ButtonBuilder().setCustomId("accept:Suggestion").setLabel("Accept").setStyle(ButtonStyle.Success).setDisabled(disabled),
123 new ButtonBuilder().setCustomId("deny:Suggestion").setLabel("Deny").setStyle(ButtonStyle.Danger).setDisabled(disabled),
124 new ButtonBuilder().setCustomId("close:Suggestion").setLabel("Close").setStyle(ButtonStyle.Secondary).setDisabled(disabled),
TheCodedProfca29ebb2023-03-10 17:40:09 -0500125 new ButtonBuilder()
126 .setCustomId("implemented:Suggestion")
127 .setLabel("Implemented")
pineafandef38a72023-05-28 12:47:36 +0100128 .setStyle(ButtonStyle.Secondary)
129 .setDisabled(disabled),
TheCodedProfca29ebb2023-03-10 17:40:09 -0500130 new ButtonBuilder()
pineafandef38a72023-05-28 12:47:36 +0100131 .setLabel(`Open Issue #${issueNumber ? issueNumber : "0"}`)
TheCodedProfca29ebb2023-03-10 17:40:09 -0500132 .setStyle(ButtonStyle.Link)
pineafandef38a72023-05-28 12:47:36 +0100133 .setURL(`https://github.com/ClicksMinutePer/Nucleus/issues/${issueNumber}`)
134 .setDisabled(disabled)
TheCodedProf35e73712023-03-10 17:35:35 -0500135 ),
136 new Discord.ActionRowBuilder<ButtonBuilder>().addComponents(
pineafandef38a72023-05-28 12:47:36 +0100137 new ButtonBuilder().setCustomId("lock:Comment").setLabel("Lock").setStyle(ButtonStyle.Danger).setDisabled(disabled),
138 new ButtonBuilder().setCustomId("spam:Suggestion").setLabel("Mark as Spam").setStyle(ButtonStyle.Danger).setDisabled(disabled)
Skyler Greyda16adf2023-03-05 10:22:12 +0000139 )
140 ]
TheCodedProfca29ebb2023-03-10 17:40:09 -0500141 });
PineaFan0d06edc2023-01-17 22:10:31 +0000142 await interaction.editReply({
143 embeds: [
144 new EmojiEmbed()
145 .setEmoji("ICONS.ADD")
146 .setTitle("Suggest")
147 .setDescription("Your suggestion was sent successfully")
148 .setStatus("Success")
149 ],
150 components: []
151 });
pineafan63fc5e22022-08-04 22:04:10 +0100152};
pineafan4f164f32022-02-26 22:07:12 +0000153
pineafan4f164f32022-02-26 22:07:12 +0000154export { command };
155export { callback };