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 | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 65 | .setEmoji("GUILD.ROLES.EDIT") |
| 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; |
| 127 | while (true) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 128 | await interaction.editReply({ |
| 129 | embeds: [ |
| 130 | new EmojiEmbed() |
| 131 | .setTitle("Verify Role") |
| 132 | .setDescription( |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 133 | 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] | 134 | ) |
| 135 | .setStatus("Success") |
| 136 | .setEmoji("GUILD.ROLES.CREATE") |
| 137 | ], |
| 138 | components: [ |
| 139 | new MessageActionRow().addComponents([ |
| 140 | new MessageButton() |
| 141 | .setCustomId("clear") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 142 | .setLabel(clicks ? "Click again to confirm" : "Reset role") |
| 143 | .setEmoji(getEmojiByName(clicks ? "TICKETS.ISSUE" : "CONTROL.CROSS", "id")) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 144 | .setStyle("DANGER") |
| 145 | .setDisabled(!role), |
| 146 | new MessageButton() |
| 147 | .setCustomId("send") |
| 148 | .setLabel("Add verify button") |
| 149 | .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id")) |
| 150 | .setStyle("PRIMARY") |
| 151 | ]) |
| 152 | ] |
| 153 | }); |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 154 | let i: MessageComponentInteraction; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 155 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 156 | i = await m.awaitMessageComponent({ time: 300000 }); |
| 157 | } catch (e) { |
| 158 | break; |
| 159 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 160 | i.deferUpdate(); |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 161 | if ((i.component as MessageActionRowComponent).customId === "clear") { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 162 | clicks += 1; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 163 | if (clicks === 2) { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 164 | clicks = 0; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 165 | await client.database.guilds.write(interaction.guild!.id, null, ["verify.role", "verify.enabled"]); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 166 | role = undefined; |
| 167 | } |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 168 | } else if ((i.component as MessageActionRowComponent).customId === "send") { |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 169 | const verifyMessages = [ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 170 | { |
| 171 | label: "Verify", |
| 172 | description: "Click the button below to get verified" |
| 173 | }, |
| 174 | { |
| 175 | label: "Get verified", |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 176 | 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] | 177 | }, |
| 178 | { |
| 179 | label: "Ready to verify?", |
| 180 | description: "Click the button below to verify yourself" |
| 181 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 182 | ]; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 183 | while (true) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 184 | await interaction.editReply({ |
| 185 | embeds: [ |
| 186 | new EmojiEmbed() |
| 187 | .setTitle("Verify Button") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 188 | .setDescription("Select a message template to send in this channel") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 189 | .setFooter({ |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 190 | 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] | 191 | }) |
| 192 | .setStatus(role ? "Success" : "Warning") |
| 193 | .setEmoji("GUILD.ROLES.CREATE") |
| 194 | ], |
| 195 | components: [ |
| 196 | new MessageActionRow().addComponents([ |
| 197 | new MessageSelectMenu() |
| 198 | .setOptions( |
| 199 | verifyMessages.map( |
| 200 | ( |
| 201 | t: { |
| 202 | label: string; |
| 203 | description: string; |
| 204 | value?: string; |
| 205 | }, |
| 206 | index |
| 207 | ) => { |
| 208 | t.value = index.toString(); |
| 209 | return t as { |
| 210 | value: string; |
| 211 | label: string; |
| 212 | description: string; |
| 213 | }; |
| 214 | } |
| 215 | ) |
| 216 | ) |
| 217 | .setCustomId("template") |
| 218 | .setMaxValues(1) |
| 219 | .setMinValues(1) |
| 220 | .setPlaceholder("Select a message template") |
| 221 | ]), |
| 222 | new MessageActionRow().addComponents([ |
| 223 | new MessageButton() |
| 224 | .setCustomId("back") |
| 225 | .setLabel("Back") |
| 226 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 227 | .setStyle("DANGER"), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 228 | new MessageButton().setCustomId("blank").setLabel("Empty").setStyle("SECONDARY"), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 229 | new MessageButton() |
| 230 | .setCustomId("custom") |
| 231 | .setLabel("Custom") |
| 232 | .setEmoji(getEmojiByName("TICKETS.OTHER", "id")) |
| 233 | .setStyle("PRIMARY") |
| 234 | ]) |
| 235 | ] |
| 236 | }); |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 237 | let i: MessageComponentInteraction; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 238 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 239 | i = await m.awaitMessageComponent({ time: 300000 }); |
| 240 | } catch (e) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 241 | break; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 242 | } |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 243 | if ((i.component as MessageActionRowComponent).customId === "template") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 244 | i.deferUpdate(); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 245 | await interaction.channel!.send({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 246 | embeds: [ |
| 247 | new EmojiEmbed() |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 248 | .setTitle(verifyMessages[parseInt((i as SelectMenuInteraction).values[0]!)]!.label) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 249 | .setDescription( |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 250 | verifyMessages[parseInt((i as SelectMenuInteraction).values[0]!)]!.description |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 251 | ) |
| 252 | .setStatus("Success") |
| 253 | .setEmoji("CONTROL.BLOCKTICK") |
| 254 | ], |
| 255 | components: [ |
| 256 | new MessageActionRow().addComponents([ |
| 257 | new MessageButton() |
| 258 | .setLabel("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 259 | .setEmoji(getEmojiByName("CONTROL.TICK", "id")) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 260 | .setStyle("SUCCESS") |
| 261 | .setCustomId("verifybutton") |
| 262 | ]) |
| 263 | ] |
| 264 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 265 | break; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 266 | } else if ((i.component as MessageActionRowComponent).customId === "blank") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 267 | i.deferUpdate(); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 268 | await interaction.channel!.send({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 269 | components: [ |
| 270 | new MessageActionRow().addComponents([ |
| 271 | new MessageButton() |
| 272 | .setLabel("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 273 | .setEmoji(getEmojiByName("CONTROL.TICK", "id")) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 274 | .setStyle("SUCCESS") |
| 275 | .setCustomId("verifybutton") |
| 276 | ]) |
| 277 | ] |
| 278 | }); |
| 279 | break; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 280 | } else if ((i.component as MessageActionRowComponent).customId === "custom") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 281 | await i.showModal( |
| 282 | new Discord.Modal() |
| 283 | .setCustomId("modal") |
| 284 | .setTitle("Enter embed details") |
| 285 | .addComponents( |
| 286 | new MessageActionRow<TextInputComponent>().addComponents( |
| 287 | new TextInputComponent() |
| 288 | .setCustomId("title") |
| 289 | .setLabel("Title") |
| 290 | .setMaxLength(256) |
| 291 | .setRequired(true) |
| 292 | .setStyle("SHORT") |
| 293 | ), |
| 294 | new MessageActionRow<TextInputComponent>().addComponents( |
| 295 | new TextInputComponent() |
| 296 | .setCustomId("description") |
| 297 | .setLabel("Description") |
| 298 | .setMaxLength(4000) |
| 299 | .setRequired(true) |
| 300 | .setStyle("PARAGRAPH") |
| 301 | ) |
| 302 | ) |
| 303 | ); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 304 | await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 305 | embeds: [ |
| 306 | new EmojiEmbed() |
| 307 | .setTitle("Verify Button") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 308 | .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] | 309 | .setStatus("Success") |
| 310 | .setEmoji("GUILD.TICKET.OPEN") |
| 311 | ], |
| 312 | components: [ |
| 313 | new MessageActionRow().addComponents([ |
| 314 | new MessageButton() |
| 315 | .setLabel("Back") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 316 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 317 | .setStyle("PRIMARY") |
| 318 | .setCustomId("back") |
| 319 | ]) |
| 320 | ] |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 321 | }); |
| 322 | let out; |
| 323 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 324 | out = await modalInteractionCollector( |
| 325 | m, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 326 | (m: Interaction) => |
| 327 | (m as MessageComponentInteraction | ModalSubmitInteraction).channelId === |
| 328 | interaction.channelId, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 329 | (m) => m.customId === "modify" |
| 330 | ); |
| 331 | } catch (e) { |
| 332 | break; |
| 333 | } |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 334 | if (out === null) { |
| 335 | continue; |
| 336 | } else if (out instanceof ModalSubmitInteraction) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 337 | const title = out.fields.getTextInputValue("title"); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 338 | const description = out.fields.getTextInputValue("description"); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 339 | await interaction.channel!.send({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 340 | embeds: [ |
| 341 | new EmojiEmbed() |
| 342 | .setTitle(title) |
| 343 | .setDescription(description) |
| 344 | .setStatus("Success") |
| 345 | .setEmoji("CONTROL.BLOCKTICK") |
| 346 | ], |
| 347 | components: [ |
| 348 | new MessageActionRow().addComponents([ |
| 349 | new MessageButton() |
| 350 | .setLabel("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 351 | .setEmoji(getEmojiByName("CONTROL.TICK", "id")) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 352 | .setStyle("SUCCESS") |
| 353 | .setCustomId("verifybutton") |
| 354 | ]) |
| 355 | ] |
| 356 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 357 | break; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 358 | } else { |
| 359 | continue; |
| 360 | } |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 361 | } |
| 362 | } |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 363 | } else { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 364 | i.deferUpdate(); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 365 | break; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 366 | } |
| 367 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 368 | await interaction.editReply({ |
| 369 | embeds: [m.embeds[0]!.setFooter({ text: "Message closed" })], |
| 370 | components: [] |
| 371 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 372 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 373 | |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 374 | const check = (interaction: CommandInteraction) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 375 | const member = interaction.member as Discord.GuildMember; |
| 376 | if (!member.permissions.has("MANAGE_GUILD")) |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 377 | 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] | 378 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 379 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 380 | |
| 381 | export { command }; |
| 382 | export { callback }; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 383 | export { check }; |