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