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