blob: c1f03122f518ccf7495b6c402394e5d0679458bc [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.guild?.members.fetch(interaction.member!.user.id);
Skyler Greyda16adf2023-03-05 10:22:12 +000023 await interaction.reply({ embeds: LoadingEmbed, ephemeral: true });
TheCodedProf35e73712023-03-10 17:35:35 -050024 let closed = false;
TheCodedProfca29ebb2023-03-10 17:40:09 -050025 let suggestionTitle: string | null = null;
TheCodedProf35e73712023-03-10 17:35:35 -050026 let suggestionDesc: string | null = null;
27 do {
28 const modal = new ModalBuilder()
29 .setTitle("Suggestion")
30 .setComponents(
TheCodedProfca29ebb2023-03-10 17:40:09 -050031 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) {
TheCodedProf35e73712023-03-10 17:35:35 -050052 o.suggestionTitle = suggestionTitle;
53 modal.components[0]!.components[0]!.setValue(suggestionTitle);
54 }
TheCodedProfca29ebb2023-03-10 17:40:09 -050055 if (suggestionDesc) {
56 o.suggestionDesc = suggestionDesc;
TheCodedProf35e73712023-03-10 17:35:35 -050057 modal.components[1]!.components[0]!.setValue(suggestionDesc);
TheCodedProfca29ebb2023-03-10 17:40:09 -050058 }
TheCodedProf35e73712023-03-10 17:35:35 -050059 const confirmation = await new confirmationMessage(interaction)
60 .setEmoji("ICONS.ADD")
61 .setTitle("Suggest")
TheCodedProfca29ebb2023-03-10 17:40:09 -050062 .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 )
TheCodedProf35e73712023-03-10 17:35:35 -050071 .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);
TheCodedProfca29ebb2023-03-10 17:40:09 -050076 if (confirmation.modals?.[0] && !_.isEqual(confirmation.modals[0].values, o)) {
TheCodedProf35e73712023-03-10 17:35:35 -050077 suggestionTitle = confirmation.modals[0].values["suggestionTitle"] as string | null;
78 suggestionDesc = confirmation.modals[0].values["suggestionDesc"] as string | null;
79 continue;
80 }
TheCodedProfca29ebb2023-03-10 17:40:09 -050081 if (confirmation.cancelled || confirmation.success === false) {
TheCodedProf35e73712023-03-10 17:35:35 -050082 closed = true;
83 return;
84 }
85 if (confirmation.success) {
86 closed = true;
TheCodedProfca29ebb2023-03-10 17:40:09 -050087 }
TheCodedProf35e73712023-03-10 17:35:35 -050088 } while (!closed);
TheCodedProfca29ebb2023-03-10 17:40:09 -050089 if (!suggestionDesc) return;
TheCodedProf35e73712023-03-10 17:35:35 -050090 suggestionTitle = suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}`;
91 const channel = client.channels.cache.get(config.suggestionChannel) as Discord.TextChannel;
TheCodedProfca29ebb2023-03-10 17:40:09 -050092 const m = await channel.send({ embeds: LoadingEmbed });
TheCodedProf35e73712023-03-10 17:35:35 -050093 const issue = await client.GitHub.rest.issues.create({
94 owner: "ClicksMinutePer",
95 repo: "Nucleus",
96 title: suggestionTitle,
TheCodedProfca29ebb2023-03-10 17:40:09 -050097 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`,
TheCodedProf35e73712023-03-10 17:35:35 -0500103 labels: ["🤖 Auto", "📝 Suggestion"]
TheCodedProfca29ebb2023-03-10 17:40:09 -0500104 });
TheCodedProf35e73712023-03-10 17:35:35 -0500105 await m.edit({
PineaFan0d06edc2023-01-17 22:10:31 +0000106 embeds: [
107 new EmojiEmbed()
TheCodedProf35e73712023-03-10 17:35:35 -0500108 .setEmoji("ICONS.ADD")
109 .setTitle(`Suggestion from ${interaction.user.tag} (${interaction.user.id})`)
110 .setDescription(`**Suggestion:**\n> ${suggestionDesc}\n\n`)
111 .setStatus("Success")
TheCodedProfca29ebb2023-03-10 17:40:09 -0500112 .setFooter({ text: `${issue.data.number}` })
Skyler Greyda16adf2023-03-05 10:22:12 +0000113 ],
114 components: [
TheCodedProf35e73712023-03-10 17:35:35 -0500115 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),
TheCodedProfca29ebb2023-03-10 17:40:09 -0500119 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}`)
TheCodedProf35e73712023-03-10 17:35:35 -0500127 ),
128 new Discord.ActionRowBuilder<ButtonBuilder>().addComponents(
129 new ButtonBuilder().setCustomId("lock:Suggestion").setLabel("Lock").setStyle(ButtonStyle.Danger),
TheCodedProfca29ebb2023-03-10 17:40:09 -0500130 new ButtonBuilder().setCustomId("spam:Suggestion").setLabel("Mark as Spam").setStyle(ButtonStyle.Danger)
Skyler Greyda16adf2023-03-05 10:22:12 +0000131 )
132 ]
TheCodedProfca29ebb2023-03-10 17:40:09 -0500133 });
PineaFan0d06edc2023-01-17 22:10:31 +0000134 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 });
pineafan63fc5e22022-08-04 22:04:10 +0100144};
pineafan4f164f32022-02-26 22:07:12 +0000145
pineafan4f164f32022-02-26 22:07:12 +0000146export { command };
147export { callback };