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