blob: 44926c78a3f0b2be2669c25b4a5cb0708246402b [file] [log] [blame]
Skyler Greyda16adf2023-03-05 10:22:12 +00001import { LoadingEmbed } from "../../utils/defaults.js";
TheCodedProf35e73712023-03-10 17:35:35 -05002import Discord, { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, ModalBuilder, TextInputBuilder, TextInputStyle } from "discord.js";
TheCodedProff86ba092023-01-27 17:10:07 -05003import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan377794f2022-04-18 19:01:01 +01004import confirmationMessage from "../../utils/confirmationMessage.js";
pineafan4edb7762022-06-26 19:21:04 +01005import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
pineafan63fc5e22022-08-04 22:04:10 +01006import client from "../../utils/client.js";
TheCodedProf35e73712023-03-10 17:35:35 -05007import config from "../../config/main.js"
8import _ from "lodash";
pineafan4f164f32022-02-26 22:07:12 +00009
10const command = (builder: SlashCommandSubcommandBuilder) =>
11 builder
pineafan63fc5e22022-08-04 22:04:10 +010012 .setName("suggest")
13 .setDescription("Sends a suggestion to the developers")
pineafan4f164f32022-02-26 22:07:12 +000014
pineafanbd02b4a2022-08-05 22:01:38 +010015const callback = async (interaction: CommandInteraction): Promise<void> => {
Skyler Greyda16adf2023-03-05 10:22:12 +000016 await interaction.guild?.members.fetch(interaction.member!.user.id);
Skyler Greyda16adf2023-03-05 10:22:12 +000017 await interaction.reply({ embeds: LoadingEmbed, ephemeral: true });
TheCodedProf35e73712023-03-10 17:35:35 -050018 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({
PineaFan0d06edc2023-01-17 22:10:31 +000091 embeds: [
92 new EmojiEmbed()
TheCodedProf35e73712023-03-10 17:35:35 -050093 .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 Greyda16adf2023-03-05 10:22:12 +000098 ],
99 components: [
TheCodedProf35e73712023-03-10 17:35:35 -0500100 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 Greyda16adf2023-03-05 10:22:12 +0000110 )
111 ]
TheCodedProf35e73712023-03-10 17:35:35 -0500112 })
PineaFan0d06edc2023-01-17 22:10:31 +0000113 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 });
pineafan63fc5e22022-08-04 22:04:10 +0100123};
pineafan4f164f32022-02-26 22:07:12 +0000124
pineafan4f164f32022-02-26 22:07:12 +0000125export { command };
126export { callback };