PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 1 | import { LoadingEmbed } from "../../utils/defaults.js"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 2 | import Discord, { |
| 3 | CommandInteraction, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 4 | Interaction, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 5 | Message, |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 6 | ActionRowBuilder, |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 7 | ButtonBuilder, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 8 | MessageComponentInteraction, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 9 | ModalSubmitInteraction, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 10 | Role, |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 11 | ButtonStyle, |
| 12 | StringSelectMenuBuilder, |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 13 | TextInputBuilder, |
| 14 | EmbedBuilder, |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 15 | ButtonComponent |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 16 | } from "discord.js"; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 17 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
| 18 | import confirmationMessage from "../../utils/confirmationMessage.js"; |
| 19 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 20 | import type { SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 21 | import client from "../../utils/client.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 22 | import { modalInteractionCollector } from "../../utils/dualCollector.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 23 | |
| 24 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 25 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 26 | .setName("verify") |
| 27 | .setDescription("Manage the role given after typing /verify") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 28 | .addRoleOption((option) => |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 29 | option.setName("role").setDescription("The role to give after verifying").setRequired(false) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 30 | ); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 31 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 32 | const callback = async (interaction: CommandInteraction): Promise<unknown> => { |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 33 | if (!interaction.guild) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 34 | const m = (await interaction.reply({ |
| 35 | embeds: LoadingEmbed, |
| 36 | ephemeral: true, |
| 37 | fetchReply: true |
| 38 | })) as Message; |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 39 | if (interaction.options.get("role")?.role) { |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 40 | let role: Role; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 41 | try { |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 42 | role = interaction.options.get("role")?.role as Role; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 43 | } catch { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 44 | return await interaction.editReply({ |
| 45 | embeds: [ |
| 46 | new EmojiEmbed() |
| 47 | .setEmoji("GUILD.ROLES.DELETE") |
| 48 | .setTitle("Verify Role") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 49 | .setDescription("The role you provided is not a valid role") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 50 | .setStatus("Danger") |
| 51 | ] |
| 52 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 53 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 54 | role = role as Discord.Role; |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 55 | if (role.guild.id !== interaction.guild.id) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 56 | return interaction.editReply({ |
| 57 | embeds: [ |
| 58 | new EmojiEmbed() |
| 59 | .setTitle("Verify Role") |
| 60 | .setDescription("You must choose a role in this server") |
| 61 | .setStatus("Danger") |
| 62 | .setEmoji("GUILD.ROLES.DELETE") |
| 63 | ] |
| 64 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 65 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 66 | const confirmation = await new confirmationMessage(interaction) |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 67 | .setEmoji("GUILD.ROLES.EDIT") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 68 | .setTitle("Verify Role") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 69 | .setDescription(`Are you sure you want to set the verify role to <@&${role.id}>?`) |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 70 | .setColor("Warning") |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 71 | .setFailedMessage("No changes were made", "Warning", "GUILD.ROLES.DELETE") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 72 | .setInverted(true) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 73 | .send(true); |
| 74 | if (confirmation.cancelled) return; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 75 | if (confirmation.success) { |
| 76 | try { |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 77 | await client.database.guilds.write(interaction.guild.id, { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 78 | "verify.role": role.id, |
| 79 | "verify.enabled": true |
| 80 | }); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 81 | const { log, NucleusColors, entry, renderUser, renderRole } = client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 82 | const data = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 83 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 84 | type: "verifyRoleChanged", |
| 85 | displayName: "Verify Role Changed", |
| 86 | calculateType: "nucleusSettingsUpdated", |
| 87 | color: NucleusColors.green, |
| 88 | emoji: "CONTROL.BLOCKTICK", |
| 89 | timestamp: new Date().getTime() |
| 90 | }, |
| 91 | list: { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 92 | memberId: entry(interaction.user.id, `\`${interaction.user.id}\``), |
| 93 | changedBy: entry(interaction.user.id, renderUser(interaction.user)), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 94 | role: entry(role.id, renderRole(role)) |
| 95 | }, |
| 96 | hidden: { |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 97 | guild: interaction.guild.id |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 98 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 99 | }; |
| 100 | log(data); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 101 | } catch (e) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 102 | console.log(e); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 103 | return interaction.editReply({ |
| 104 | embeds: [ |
| 105 | new EmojiEmbed() |
| 106 | .setTitle("Verify Role") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 107 | .setDescription("Something went wrong while setting the verify role") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 108 | .setStatus("Danger") |
| 109 | .setEmoji("GUILD.ROLES.DELETE") |
| 110 | ], |
| 111 | components: [] |
| 112 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 113 | } |
| 114 | } else { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 115 | return interaction.editReply({ |
| 116 | embeds: [ |
| 117 | new EmojiEmbed() |
| 118 | .setTitle("Verify Role") |
| 119 | .setDescription("No changes were made") |
| 120 | .setStatus("Success") |
| 121 | .setEmoji("GUILD.ROLES.CREATE") |
| 122 | ], |
| 123 | components: [] |
| 124 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | let clicks = 0; |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 128 | const data = await client.database.guilds.read(interaction.guild.id); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 129 | let role = data.verify.role; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 130 | |
| 131 | let timedOut = false; |
| 132 | while (!timedOut) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 133 | await interaction.editReply({ |
| 134 | embeds: [ |
| 135 | new EmojiEmbed() |
| 136 | .setTitle("Verify Role") |
| 137 | .setDescription( |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 138 | role ? `Your verify role is currently set to <@&${role}>` : "You have not set a verify role" |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 139 | ) |
| 140 | .setStatus("Success") |
| 141 | .setEmoji("GUILD.ROLES.CREATE") |
| 142 | ], |
| 143 | components: [ |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 144 | new ActionRowBuilder<ButtonBuilder>().addComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 145 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 146 | .setCustomId("clear") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 147 | .setLabel(clicks ? "Click again to confirm" : "Reset role") |
| 148 | .setEmoji(getEmojiByName(clicks ? "TICKETS.ISSUE" : "CONTROL.CROSS", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 149 | .setStyle(ButtonStyle.Danger) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 150 | .setDisabled(!role), |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 151 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 152 | .setCustomId("send") |
| 153 | .setLabel("Add verify button") |
| 154 | .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 155 | .setStyle(ButtonStyle.Primary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 156 | ]) |
| 157 | ] |
| 158 | }); |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 159 | let i: MessageComponentInteraction; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 160 | try { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 161 | i = await m.awaitMessageComponent({ |
| 162 | time: 300000, |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 163 | filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.message.id === m.id } |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 164 | }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 165 | } catch (e) { |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 166 | timedOut = true; |
| 167 | continue; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 168 | } |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 169 | await i.deferUpdate(); |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 170 | if ((i.component as ButtonComponent).customId === "clear") { |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 171 | clicks ++; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 172 | if (clicks === 2) { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 173 | clicks = 0; |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 174 | await client.database.guilds.write(interaction.guild.id, null, ["verify.role", "verify.enabled"]); |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 175 | role = null; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 176 | } |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 177 | } else if ((i.component as ButtonComponent).customId === "send") { |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 178 | const verifyMessages = [ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 179 | { |
| 180 | label: "Verify", |
| 181 | description: "Click the button below to get verified" |
| 182 | }, |
| 183 | { |
| 184 | label: "Get verified", |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 185 | description: "To get access to the rest of the server, click the button below" |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 186 | }, |
| 187 | { |
| 188 | label: "Ready to verify?", |
| 189 | description: "Click the button below to verify yourself" |
| 190 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 191 | ]; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 192 | let innerTimedOut = false; |
| 193 | let templateSelected = false; |
| 194 | while (!innerTimedOut && !templateSelected) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 195 | await interaction.editReply({ |
| 196 | embeds: [ |
| 197 | new EmojiEmbed() |
| 198 | .setTitle("Verify Button") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 199 | .setDescription("Select a message template to send in this channel") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 200 | .setFooter({ |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 201 | text: role ? "" : "You do no have a verify role set so the button will not work." |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 202 | }) |
| 203 | .setStatus(role ? "Success" : "Warning") |
| 204 | .setEmoji("GUILD.ROLES.CREATE") |
| 205 | ], |
| 206 | components: [ |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 207 | new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([ |
| 208 | new StringSelectMenuBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 209 | .setOptions( |
| 210 | verifyMessages.map( |
| 211 | ( |
| 212 | t: { |
| 213 | label: string; |
| 214 | description: string; |
| 215 | value?: string; |
| 216 | }, |
| 217 | index |
| 218 | ) => { |
| 219 | t.value = index.toString(); |
| 220 | return t as { |
| 221 | value: string; |
| 222 | label: string; |
| 223 | description: string; |
| 224 | }; |
| 225 | } |
| 226 | ) |
| 227 | ) |
| 228 | .setCustomId("template") |
| 229 | .setMaxValues(1) |
| 230 | .setMinValues(1) |
| 231 | .setPlaceholder("Select a message template") |
| 232 | ]), |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 233 | new ActionRowBuilder<ButtonBuilder>().addComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 234 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 235 | .setCustomId("back") |
| 236 | .setLabel("Back") |
| 237 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 238 | .setStyle(ButtonStyle.Danger), |
| 239 | new ButtonBuilder().setCustomId("blank").setLabel("Empty").setStyle(ButtonStyle.Secondary), |
| 240 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 241 | .setCustomId("custom") |
| 242 | .setLabel("Custom") |
| 243 | .setEmoji(getEmojiByName("TICKETS.OTHER", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 244 | .setStyle(ButtonStyle.Primary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 245 | ]) |
| 246 | ] |
| 247 | }); |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 248 | let i: MessageComponentInteraction; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 249 | try { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 250 | i = await m.awaitMessageComponent({ |
| 251 | time: 300000, |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 252 | filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.message.id === m.id } |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 253 | }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 254 | } catch (e) { |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 255 | innerTimedOut = true; |
| 256 | continue; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 257 | } |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 258 | if (i.isStringSelectMenu() && i.customId === "template") { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 259 | await i.deferUpdate(); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 260 | await interaction.channel!.send({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 261 | embeds: [ |
| 262 | new EmojiEmbed() |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 263 | .setTitle(verifyMessages[parseInt(i.values[0]!)]!.label) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 264 | .setDescription( |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 265 | verifyMessages[parseInt(i.values[0]!)]!.description |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 266 | ) |
| 267 | .setStatus("Success") |
| 268 | .setEmoji("CONTROL.BLOCKTICK") |
| 269 | ], |
| 270 | components: [ |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 271 | new ActionRowBuilder<ButtonBuilder>().addComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 272 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 273 | .setLabel("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 274 | .setEmoji(getEmojiByName("CONTROL.TICK", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 275 | .setStyle(ButtonStyle.Success) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 276 | .setCustomId("verifybutton") |
| 277 | ]) |
| 278 | ] |
| 279 | }); |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 280 | templateSelected = true; |
| 281 | continue; |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 282 | } else if ((i.component as ButtonComponent).customId === "blank") { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 283 | await i.deferUpdate(); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 284 | await interaction.channel!.send({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 285 | components: [ |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 286 | new ActionRowBuilder<ButtonBuilder>().addComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 287 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 288 | .setLabel("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 289 | .setEmoji(getEmojiByName("CONTROL.TICK", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 290 | .setStyle(ButtonStyle.Success) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 291 | .setCustomId("verifybutton") |
| 292 | ]) |
| 293 | ] |
| 294 | }); |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 295 | templateSelected = true; |
| 296 | continue; |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 297 | } else if ((i.component as ButtonComponent).customId === "custom") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 298 | await i.showModal( |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 299 | new Discord.ModalBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 300 | .setCustomId("modal") |
| 301 | .setTitle("Enter embed details") |
| 302 | .addComponents( |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 303 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 304 | new TextInputBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 305 | .setCustomId("title") |
| 306 | .setLabel("Title") |
| 307 | .setMaxLength(256) |
| 308 | .setRequired(true) |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 309 | .setStyle(Discord.TextInputStyle.Short) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 310 | ), |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 311 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 312 | new TextInputBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 313 | .setCustomId("description") |
| 314 | .setLabel("Description") |
| 315 | .setMaxLength(4000) |
| 316 | .setRequired(true) |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 317 | .setStyle(Discord.TextInputStyle.Paragraph) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 318 | ) |
| 319 | ) |
| 320 | ); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 321 | await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 322 | embeds: [ |
| 323 | new EmojiEmbed() |
| 324 | .setTitle("Verify Button") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 325 | .setDescription("Modal opened. If you can't see it, click back and try again.") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 326 | .setStatus("Success") |
| 327 | .setEmoji("GUILD.TICKET.OPEN") |
| 328 | ], |
| 329 | components: [ |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 330 | new ActionRowBuilder<ButtonBuilder>().addComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 331 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 332 | .setLabel("Back") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 333 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 334 | .setStyle(ButtonStyle.Primary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 335 | .setCustomId("back") |
| 336 | ]) |
| 337 | ] |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 338 | }); |
| 339 | let out; |
| 340 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 341 | out = await modalInteractionCollector( |
| 342 | m, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 343 | (m: Interaction) => |
| 344 | (m as MessageComponentInteraction | ModalSubmitInteraction).channelId === |
| 345 | interaction.channelId, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 346 | (m) => m.customId === "modify" |
| 347 | ); |
| 348 | } catch (e) { |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 349 | innerTimedOut = true; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 350 | continue; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 351 | } |
| 352 | if (out !== null && out instanceof ModalSubmitInteraction) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 353 | const title = out.fields.getTextInputValue("title"); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 354 | const description = out.fields.getTextInputValue("description"); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 355 | await interaction.channel!.send({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 356 | embeds: [ |
| 357 | new EmojiEmbed() |
| 358 | .setTitle(title) |
| 359 | .setDescription(description) |
| 360 | .setStatus("Success") |
| 361 | .setEmoji("CONTROL.BLOCKTICK") |
| 362 | ], |
| 363 | components: [ |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 364 | new ActionRowBuilder<ButtonBuilder>().addComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 365 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 366 | .setLabel("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 367 | .setEmoji(getEmojiByName("CONTROL.TICK", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 368 | .setStyle(ButtonStyle.Success) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 369 | .setCustomId("verifybutton") |
| 370 | ]) |
| 371 | ] |
| 372 | }); |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 373 | templateSelected = true; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 374 | } |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 375 | } |
| 376 | } |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 377 | } else { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 378 | await i.deferUpdate(); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 379 | break; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 380 | } |
| 381 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 382 | await interaction.editReply({ |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 383 | embeds: [new EmbedBuilder(m.embeds[0]!.data).setFooter({ text: "Message closed" })], |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 384 | components: [] |
| 385 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 386 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 387 | |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 388 | const check = (interaction: CommandInteraction) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 389 | const member = interaction.member as Discord.GuildMember; |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 390 | if (!member.permissions.has("ManageGuild")) |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 391 | return "You must have the *Manage Server* permission to use this command"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 392 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 393 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 394 | |
| 395 | export { command }; |
| 396 | export { callback }; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 397 | export { check }; |