TheCodedProf | afca98b | 2023-01-17 22:25:43 -0500 | [diff] [blame] | 1 | import type Discord from "discord.js"; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 2 | import { |
| 3 | ActionRowBuilder, |
| 4 | APIMessageComponentEmoji, |
| 5 | ButtonBuilder, |
| 6 | ButtonInteraction, |
| 7 | ButtonStyle, |
| 8 | CommandInteraction, |
| 9 | Message, |
| 10 | ModalBuilder, |
| 11 | RoleSelectMenuBuilder, |
| 12 | RoleSelectMenuInteraction, |
| 13 | StringSelectMenuBuilder, |
| 14 | StringSelectMenuInteraction, |
| 15 | StringSelectMenuOptionBuilder, |
| 16 | TextInputBuilder, |
| 17 | TextInputStyle |
| 18 | } from "discord.js"; |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 19 | import type { SlashCommandSubcommandBuilder } from "discord.js"; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 20 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
| 21 | import { LoadingEmbed } from "../../utils/defaults.js"; |
| 22 | import client from "../../utils/client.js"; |
| 23 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
| 24 | import createPageIndicator from "../../utils/createPageIndicator.js"; |
| 25 | import { configToDropdown } from "../../actions/roleMenu.js"; |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame] | 26 | import { modalInteractionCollector } from "../../utils/dualCollector.js"; |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 27 | import ellipsis from "../../utils/ellipsis.js"; |
TheCodedProf | e92b9b5 | 2023-03-06 17:07:34 -0500 | [diff] [blame] | 28 | import _ from "lodash"; |
TheCodedProf | a112f61 | 2023-01-28 18:06:45 -0500 | [diff] [blame] | 29 | |
TheCodedProf | e92b9b5 | 2023-03-06 17:07:34 -0500 | [diff] [blame] | 30 | const isEqual = _.isEqual; |
TheCodedProf | a112f61 | 2023-01-28 18:06:45 -0500 | [diff] [blame] | 31 | |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 32 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 33 | builder.setName("rolemenu").setDescription("Allows you to change settings for the servers rolemenu"); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 34 | |
| 35 | interface ObjectSchema { |
| 36 | name: string; |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 37 | description: string | null; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 38 | min: number; |
| 39 | max: number; |
| 40 | options: { |
| 41 | name: string; |
| 42 | description: string | null; |
| 43 | role: string; |
| 44 | }[]; |
| 45 | } |
| 46 | |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame] | 47 | const defaultRolePageConfig = { |
| 48 | name: "Role Menu Page", |
| 49 | description: "A new role menu page", |
| 50 | min: 0, |
| 51 | max: 0, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 52 | options: [{ name: "Role 1", description: null, role: "No role set" }] |
| 53 | }; |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame] | 54 | |
TheCodedProf | a112f61 | 2023-01-28 18:06:45 -0500 | [diff] [blame] | 55 | const reorderRoleMenuPages = async (interaction: CommandInteraction, m: Message, currentObj: ObjectSchema[]) => { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 56 | const reorderRow = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 57 | new StringSelectMenuBuilder() |
| 58 | .setCustomId("reorder") |
| 59 | .setPlaceholder("Select all pages in the order you want them to appear.") |
| 60 | .setMinValues(currentObj.length) |
| 61 | .setMaxValues(currentObj.length) |
| 62 | .addOptions( |
| 63 | currentObj.map((o, i) => new StringSelectMenuOptionBuilder().setLabel(o.name).setValue(i.toString())) |
| 64 | ) |
| 65 | ); |
| 66 | const buttonRow = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 67 | new ButtonBuilder() |
| 68 | .setCustomId("back") |
| 69 | .setLabel("Back") |
| 70 | .setStyle(ButtonStyle.Secondary) |
| 71 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji) |
| 72 | ); |
TheCodedProf | a112f61 | 2023-01-28 18:06:45 -0500 | [diff] [blame] | 73 | await interaction.editReply({ |
| 74 | embeds: [ |
| 75 | new EmojiEmbed() |
| 76 | .setTitle("Role Menu") |
| 77 | .setDescription("Select pages in the order you want them to appear.") |
| 78 | .setStatus("Success") |
| 79 | ], |
| 80 | components: [reorderRow, buttonRow] |
| 81 | }); |
| 82 | let out: StringSelectMenuInteraction | ButtonInteraction | null; |
| 83 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 84 | out = (await m.awaitMessageComponent({ |
TheCodedProf | a112f61 | 2023-01-28 18:06:45 -0500 | [diff] [blame] | 85 | filter: (i) => i.channel!.id === interaction.channel!.id, |
| 86 | time: 300000 |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 87 | })) as StringSelectMenuInteraction | ButtonInteraction | null; |
TheCodedProf | a112f61 | 2023-01-28 18:06:45 -0500 | [diff] [blame] | 88 | } catch (e) { |
| 89 | console.error(e); |
| 90 | out = null; |
| 91 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 92 | if (!out) return; |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 93 | await out.deferUpdate(); |
TheCodedProf | a112f61 | 2023-01-28 18:06:45 -0500 | [diff] [blame] | 94 | if (out.isButton()) return; |
TheCodedProf | a112f61 | 2023-01-28 18:06:45 -0500 | [diff] [blame] | 95 | const values = out.values; |
| 96 | |
| 97 | const newOrder: ObjectSchema[] = currentObj.map((_, i) => { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 98 | const index = values.findIndex((v) => v === i.toString()); |
TheCodedProf | a112f61 | 2023-01-28 18:06:45 -0500 | [diff] [blame] | 99 | return currentObj[index]; |
| 100 | }) as ObjectSchema[]; |
| 101 | |
| 102 | return newOrder; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 103 | }; |
TheCodedProf | a112f61 | 2023-01-28 18:06:45 -0500 | [diff] [blame] | 104 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 105 | const editNameDescription = async ( |
| 106 | i: ButtonInteraction, |
| 107 | interaction: StringSelectMenuInteraction | ButtonInteraction, |
| 108 | m: Message, |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 109 | data: { name?: string; description?: string | null } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 110 | ) => { |
| 111 | let { name, description } = data; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 112 | const modal = new ModalBuilder() |
| 113 | .setTitle("Edit Name and Description") |
| 114 | .setCustomId("editNameDescription") |
| 115 | .addComponents( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 116 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 117 | new TextInputBuilder() |
| 118 | .setLabel("Name") |
| 119 | .setCustomId("name") |
| 120 | .setPlaceholder("The name of the role (e.g. Programmer)") |
| 121 | .setStyle(TextInputStyle.Short) |
| 122 | .setValue(name ?? "") |
| 123 | .setRequired(true) |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 124 | .setMaxLength(100) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 125 | ), |
| 126 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 127 | new TextInputBuilder() |
| 128 | .setLabel("Description") |
| 129 | .setCustomId("description") |
| 130 | .setPlaceholder("A short description of the role (e.g. A role for people who code)") |
| 131 | .setStyle(TextInputStyle.Short) |
| 132 | .setValue(description ?? "") |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 133 | .setRequired(false) |
| 134 | .setMaxLength(100) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 135 | ) |
| 136 | ); |
| 137 | const button = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 138 | new ButtonBuilder() |
| 139 | .setCustomId("back") |
| 140 | .setLabel("Back") |
| 141 | .setStyle(ButtonStyle.Secondary) |
| 142 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji) |
| 143 | ); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 144 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 145 | await i.showModal(modal); |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame] | 146 | await interaction.editReply({ |
| 147 | embeds: [ |
| 148 | new EmojiEmbed() |
| 149 | .setTitle("Role Menu") |
| 150 | .setDescription("Modal opened. If you can't see it, click back and try again.") |
| 151 | .setStatus("Success") |
| 152 | ], |
| 153 | components: [button] |
| 154 | }); |
| 155 | |
| 156 | let out: Discord.ModalSubmitInteraction | null; |
| 157 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 158 | out = (await modalInteractionCollector(m, interaction.user)) as Discord.ModalSubmitInteraction | null; |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame] | 159 | } catch (e) { |
| 160 | console.error(e); |
| 161 | out = null; |
| 162 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 163 | if (!out) return [name, description]; |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame] | 164 | if (out.isButton()) return [name, description]; |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame] | 165 | name = out.fields.fields.find((f) => f.customId === "name")?.value ?? name; |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 166 | description = out.fields.fields.find((f) => f.customId === "description")?.value ?? null; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 167 | return [name, description]; |
| 168 | }; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 169 | |
TheCodedProf | 7a83f76 | 2023-03-06 17:17:00 -0500 | [diff] [blame] | 170 | const defaultRoleMenuData = { |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 171 | name: "New Page", |
| 172 | description: "", |
TheCodedProf | 7a83f76 | 2023-03-06 17:17:00 -0500 | [diff] [blame] | 173 | min: 0, |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 174 | max: 1, |
TheCodedProf | 7a83f76 | 2023-03-06 17:17:00 -0500 | [diff] [blame] | 175 | options: [] |
| 176 | }; |
| 177 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 178 | const editRoleMenuPage = async ( |
| 179 | interaction: StringSelectMenuInteraction | ButtonInteraction, |
| 180 | m: Message, |
| 181 | data?: ObjectSchema |
| 182 | ): Promise<ObjectSchema | null> => { |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 183 | if (!data) data = _.cloneDeep(defaultRoleMenuData); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 184 | const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 185 | new ButtonBuilder() |
| 186 | .setCustomId("back") |
| 187 | .setLabel("Back") |
| 188 | .setStyle(ButtonStyle.Secondary) |
| 189 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji), |
| 190 | new ButtonBuilder() |
| 191 | .setCustomId("edit") |
| 192 | .setLabel("Edit") |
| 193 | .setStyle(ButtonStyle.Primary) |
| 194 | .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji), |
| 195 | new ButtonBuilder() |
| 196 | .setCustomId("addRole") |
| 197 | .setLabel("Add Role") |
| 198 | .setStyle(ButtonStyle.Secondary) |
| 199 | .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id") as APIMessageComponentEmoji) |
| 200 | ); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 201 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 202 | let back = false; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 203 | do { |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 204 | const noRoles = data.options.length === 0; |
| 205 | const previewSelect = configToDropdown( |
| 206 | "Edit Roles", |
| 207 | { |
| 208 | name: data.name, |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 209 | description: data.description ?? null, |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 210 | min: 1, |
| 211 | max: 1, |
| 212 | options: noRoles ? [{ name: "Role 1", description: null, role: "No role set" }] : data.options |
| 213 | }, |
| 214 | undefined, |
| 215 | noRoles |
| 216 | ); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 217 | const embed = new EmojiEmbed() |
| 218 | .setTitle(`${data.name}`) |
| 219 | .setStatus("Success") |
| 220 | .setDescription( |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 221 | `**Description:**\n> ${data.description ?? '*No description set*'}\n\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 222 | `**Min:** ${data.min}` + |
| 223 | (data.min === 0 ? " (Members will be given a skip button)" : "") + |
| 224 | "\n" + |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 225 | `**Max:** ${data.max}\n` + |
| 226 | `\n**Roles:** ${data.options.length === 0 ? "*No roles set*" : data.options.length}` |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 227 | ); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 228 | |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 229 | await interaction.editReply({ embeds: [embed], components: [previewSelect, buttons] }); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 230 | let i: StringSelectMenuInteraction | ButtonInteraction; |
| 231 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 232 | i = (await m.awaitMessageComponent({ |
| 233 | time: 300000, |
| 234 | filter: (i) => |
| 235 | i.user.id === interaction.user.id && i.message.id === m.id && i.channelId === interaction.channelId |
| 236 | })) as ButtonInteraction | StringSelectMenuInteraction; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 237 | } catch (e) { |
| 238 | back = true; |
| 239 | break; |
| 240 | } |
| 241 | |
| 242 | if (i.isStringSelectMenu()) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 243 | if (i.customId === "roles") { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 244 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 245 | await createRoleMenuOptionPage( |
| 246 | interaction, |
| 247 | m, |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 248 | data.options.find((o) => o.role === (i as StringSelectMenuInteraction).values[0]), |
| 249 | false |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 250 | ); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 251 | } |
| 252 | } else if (i.isButton()) { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 253 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 254 | case "back": { |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame] | 255 | await i.deferUpdate(); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 256 | back = true; |
| 257 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 258 | } |
| 259 | case "edit": { |
| 260 | const [name, description] = await editNameDescription(i, interaction, m, data); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 261 | data.name = name ? name : data.name; |
| 262 | data.description = description ? description : data.description; |
| 263 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 264 | } |
| 265 | case "addRole": { |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame] | 266 | await i.deferUpdate(); |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 267 | const out = await createRoleMenuOptionPage(interaction, m, undefined, true); |
| 268 | if (out) data.options.push(out); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 269 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 270 | } |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 271 | } |
| 272 | } |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 273 | } while (!back); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 274 | if (isEqual(data, defaultRolePageConfig)) return null; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 275 | return data; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 276 | }; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 277 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 278 | const createRoleMenuOptionPage = async ( |
| 279 | interaction: StringSelectMenuInteraction | ButtonInteraction, |
| 280 | m: Message, |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 281 | data?: { name: string; description: string | null; role: string }, |
| 282 | newRole: boolean = false |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 283 | ) => { |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 284 | const initialData = _.cloneDeep(data); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 285 | const { renderRole } = client.logger; |
| 286 | if (!data) |
| 287 | data = { |
| 288 | name: "New role Menu Option", |
| 289 | description: null, |
| 290 | role: "" |
| 291 | }; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 292 | let back = false; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 293 | const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 294 | new ButtonBuilder() |
| 295 | .setCustomId("back") |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 296 | .setLabel(newRole ? "Add" : "Back") |
| 297 | .setStyle(newRole ? ButtonStyle.Success : ButtonStyle.Secondary) |
| 298 | .setEmoji(getEmojiByName("ICONS.SAVE", "id") as APIMessageComponentEmoji), |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 299 | new ButtonBuilder() |
| 300 | .setCustomId("edit") |
| 301 | .setLabel("Edit Details") |
| 302 | .setStyle(ButtonStyle.Primary) |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 303 | .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji), |
| 304 | new ButtonBuilder() |
| 305 | .setCustomId("delete") |
| 306 | .setLabel("Delete") |
| 307 | .setStyle(ButtonStyle.Danger) |
| 308 | .setEmoji(getEmojiByName("TICKETS.ISSUE", "id") as APIMessageComponentEmoji), |
| 309 | new ButtonBuilder() |
| 310 | .setCustomId("cancel") |
| 311 | .setLabel("Cancel") |
| 312 | .setStyle(ButtonStyle.Secondary) |
| 313 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 314 | ); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 315 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 316 | const roleSelect = new RoleSelectMenuBuilder() |
| 317 | .setCustomId("role") |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 318 | .setPlaceholder(data.role ? "Change role to" : "Select a role"); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 319 | const embed = new EmojiEmbed() |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 320 | .setTitle(`${data.name}`) |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 321 | .setStatus("Success") |
| 322 | .setDescription( |
| 323 | `**Description:**\n> ${data.description ?? "No description set"}\n\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 324 | `**Role:** ${ |
| 325 | data.role ? renderRole((await interaction.guild!.roles.fetch(data.role))!) : "No role set" |
| 326 | }\n` |
| 327 | ); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 328 | |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 329 | await interaction.editReply({ |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 330 | embeds: [embed], |
| 331 | components: [new ActionRowBuilder<RoleSelectMenuBuilder>().addComponents(roleSelect), buttons] |
| 332 | }); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 333 | |
| 334 | let i: RoleSelectMenuInteraction | ButtonInteraction; |
| 335 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 336 | i = (await m.awaitMessageComponent({ |
| 337 | time: 300000, |
| 338 | filter: (i) => |
| 339 | i.user.id === interaction.user.id && i.message.id === m.id && i.channelId === interaction.channelId |
| 340 | })) as ButtonInteraction | RoleSelectMenuInteraction; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 341 | } catch (e) { |
| 342 | back = true; |
| 343 | break; |
| 344 | } |
| 345 | |
| 346 | if (i.isRoleSelectMenu()) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 347 | if (i.customId === "role") { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 348 | await i.deferUpdate(); |
| 349 | data.role = (i as RoleSelectMenuInteraction).values[0]!; |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 350 | await interaction.editReply({ |
| 351 | embeds: [ |
| 352 | new EmojiEmbed().setTitle(`Applying changes`).setStatus("Danger").setEmoji("NUCLEUS.LOADING") |
| 353 | ], |
| 354 | components: [] |
| 355 | }); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 356 | } |
| 357 | } else if (i.isButton()) { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 358 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 359 | case "back": { |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame] | 360 | await i.deferUpdate(); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 361 | back = true; |
| 362 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 363 | } |
| 364 | case "edit": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 365 | const [name, description] = await editNameDescription( |
| 366 | i, |
| 367 | interaction, |
| 368 | m, |
| 369 | data as { name: string; description: string } |
| 370 | ); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 371 | data.name = name ? name : data.name; |
| 372 | data.description = description ? description : data.description; |
| 373 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 374 | } |
pineafan | 72659cc | 2023-05-28 13:36:44 +0100 | [diff] [blame] | 375 | case "delete": { |
| 376 | await i.deferUpdate(); |
| 377 | return null; |
| 378 | } |
| 379 | case "cancel": { |
| 380 | await i.deferUpdate(); |
| 381 | if (newRole) return null; |
| 382 | else return initialData; |
| 383 | } |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | } while (!back); |
| 387 | return data; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 388 | }; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 389 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 390 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 391 | if (!interaction.guild) return; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 392 | const m = await interaction.reply({ embeds: LoadingEmbed, ephemeral: true, fetchReply: true }); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 393 | |
| 394 | let page = 0; |
| 395 | let closed = false; |
| 396 | const config = await client.database.guilds.read(interaction.guild.id); |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 397 | const currentObject: typeof config.roleMenu = _.cloneDeep(config.roleMenu); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 398 | let modified = false; |
| 399 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 400 | const embed = new EmojiEmbed().setTitle("Role Menu").setEmoji("GUILD.GREEN").setStatus("Success"); |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 401 | const noRoleMenus = currentObject.options.length === 0; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 402 | let current: ObjectSchema; |
| 403 | |
| 404 | const pageSelect = new StringSelectMenuBuilder() |
| 405 | .setCustomId("page") |
| 406 | .setPlaceholder("Select a Role Menu page to manage"); |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 407 | let actionSelect; |
| 408 | if (page === 0) { |
| 409 | actionSelect = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 410 | new ButtonBuilder() |
| 411 | .setCustomId("switch") |
| 412 | .setLabel(currentObject.enabled ? "Enabled" : "Disabled") |
| 413 | .setStyle(currentObject.enabled ? ButtonStyle.Success : ButtonStyle.Danger) |
| 414 | .setEmoji( |
| 415 | getEmojiByName( |
| 416 | currentObject.enabled ? "CONTROL.TICK" : "CONTROL.CROSS", |
| 417 | "id" |
| 418 | ) as APIMessageComponentEmoji |
| 419 | ) |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 420 | ); |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 421 | } else { |
| 422 | actionSelect = new StringSelectMenuBuilder() |
| 423 | .setCustomId("action") |
| 424 | .setPlaceholder("Perform an action") |
| 425 | .addOptions( |
| 426 | new StringSelectMenuOptionBuilder() |
| 427 | .setLabel("Edit") |
| 428 | .setDescription("Edit this page") |
| 429 | .setValue("edit") |
| 430 | .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji), |
| 431 | new StringSelectMenuOptionBuilder() |
| 432 | .setLabel("Delete") |
| 433 | .setDescription("Delete this page") |
| 434 | .setValue("delete") |
| 435 | .setEmoji(getEmojiByName("TICKETS.ISSUE", "id") as APIMessageComponentEmoji) |
| 436 | ); |
| 437 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 438 | const buttonRow = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 439 | new ButtonBuilder() |
| 440 | .setCustomId("back") |
| 441 | .setStyle(ButtonStyle.Primary) |
| 442 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji) |
| 443 | .setDisabled(page === 0), |
| 444 | new ButtonBuilder() |
| 445 | .setCustomId("next") |
| 446 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id") as APIMessageComponentEmoji) |
| 447 | .setStyle(ButtonStyle.Primary) |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 448 | .setDisabled(page === Object.keys(currentObject.options).length || noRoleMenus), |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 449 | new ButtonBuilder() |
| 450 | .setCustomId("add") |
| 451 | .setLabel("New Page") |
| 452 | .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id") as APIMessageComponentEmoji) |
| 453 | .setStyle(ButtonStyle.Secondary) |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 454 | .setDisabled(Object.keys(currentObject.options).length >= 24), |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 455 | new ButtonBuilder() |
| 456 | .setCustomId("reorder") |
| 457 | .setLabel("Reorder Pages") |
| 458 | .setEmoji(getEmojiByName("ICONS.REORDER", "id") as APIMessageComponentEmoji) |
| 459 | .setStyle(ButtonStyle.Secondary) |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 460 | .setDisabled(Object.keys(currentObject.options).length <= 1), |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 461 | new ButtonBuilder() |
| 462 | .setCustomId("save") |
| 463 | .setLabel("Save") |
| 464 | .setEmoji(getEmojiByName("ICONS.SAVE", "id") as APIMessageComponentEmoji) |
| 465 | .setStyle(ButtonStyle.Success) |
| 466 | .setDisabled(!modified) |
| 467 | ); |
| 468 | if (noRoleMenus) { |
| 469 | embed.setDescription( |
| 470 | "No role menu pages have been set up yet. Use the button below to add one.\n\n" + |
| 471 | createPageIndicator(1, 1, undefined, true) |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 472 | ); |
| 473 | pageSelect.setDisabled(true); |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 474 | if (page > 0) (actionSelect as StringSelectMenuBuilder).setDisabled(true); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 475 | pageSelect.addOptions(new StringSelectMenuOptionBuilder().setLabel("No role menu pages").setValue("none")); |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 476 | } else if (page === 0) { |
| 477 | const cross = getEmojiByName("CONTROL.CROSS"); |
| 478 | const tick = getEmojiByName("CONTROL.TICK"); |
| 479 | embed.setDescription( |
| 480 | `**Enabled:** ${config.roleMenu.enabled ? `${tick} Yes` : `${cross} No`}\n\n` + |
| 481 | `**Pages:** ${currentObject.options.length}\n` + |
| 482 | (currentObject.options.length > 0 |
| 483 | ? currentObject.options |
| 484 | .map((key: ObjectSchema) => { |
| 485 | return `> **${key.name}:** ${key.description ?? "*No description set*"}`; |
| 486 | }) |
| 487 | .join("\n") |
| 488 | : "") |
| 489 | ); |
| 490 | if(currentObject.options.length > 0) { |
| 491 | pageSelect.addOptions( |
| 492 | currentObject.options.map((key: ObjectSchema, index) => { |
| 493 | return new StringSelectMenuOptionBuilder() |
| 494 | .setLabel(ellipsis(key.name, 50)) |
| 495 | .setDescription(ellipsis(key.description?.length ? (key.description.length > 0 ? key.description : "No description set") : "No description set", 50)) |
| 496 | .setValue(index.toString()); |
| 497 | }) |
| 498 | ); |
| 499 | } else { |
| 500 | pageSelect.setDisabled(true); |
| 501 | pageSelect.addOptions(new StringSelectMenuOptionBuilder().setLabel("No role menu pages").setValue("none")); |
| 502 | } |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 503 | } else { |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 504 | page = Math.max(Math.min(page, currentObject.options.length), 0); |
| 505 | current = currentObject.options[page - 1]!; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 506 | embed.setDescription( |
| 507 | `**Currently Editing:** ${current.name}\n\n` + |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 508 | `**Description:**\n> ${current.description ?? "*No description set*"}\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 509 | `\n\n${createPageIndicator(Object.keys(config.roleMenu.options).length, page)}` |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 510 | ); |
| 511 | |
| 512 | pageSelect.addOptions( |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 513 | currentObject.options.map((key: ObjectSchema, index) => { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 514 | return new StringSelectMenuOptionBuilder() |
| 515 | .setLabel(ellipsis(key.name, 50)) |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 516 | .setDescription(ellipsis(key.description?.length ? (key.description.length > 0 ? key.description : "No description set") : "No description set", 50)) |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 517 | .setValue(index.toString()); |
| 518 | }) |
| 519 | ); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 520 | } |
| 521 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 522 | await interaction.editReply({ |
| 523 | embeds: [embed], |
| 524 | components: [ |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 525 | page === 0 |
| 526 | ? (actionSelect as ActionRowBuilder<ButtonBuilder>) |
| 527 | : new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 528 | actionSelect as StringSelectMenuBuilder |
| 529 | ), |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 530 | new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(pageSelect), |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 531 | buttonRow as ActionRowBuilder<ButtonBuilder> |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 532 | ] |
| 533 | }); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 534 | let i: StringSelectMenuInteraction | ButtonInteraction; |
| 535 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 536 | i = (await m.awaitMessageComponent({ |
| 537 | time: 300000, |
| 538 | filter: (i) => |
| 539 | i.user.id === interaction.user.id && i.message.id === m.id && i.channelId === interaction.channelId |
| 540 | })) as ButtonInteraction | StringSelectMenuInteraction; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 541 | } catch (e) { |
| 542 | closed = true; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 543 | continue; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | await i.deferUpdate(); |
| 547 | if (i.isButton()) { |
| 548 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 549 | case "back": { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 550 | page--; |
| 551 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 552 | } |
| 553 | case "next": { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 554 | page++; |
| 555 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 556 | } |
| 557 | case "add": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 558 | const newPage = await editRoleMenuPage(i, m); |
pineafan | 44713d4 | 2023-06-03 20:29:49 +0100 | [diff] [blame] | 559 | if (_.isEqual(newPage, defaultRoleMenuData)) { |
| 560 | break; |
| 561 | } |
pineafan | 6f600f0 | 2023-06-03 20:27:07 +0100 | [diff] [blame] | 562 | if (newPage) { |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 563 | currentObject.options.push(newPage); |
| 564 | page = currentObject.options.length; |
| 565 | modified = true; |
pineafan | 6f600f0 | 2023-06-03 20:27:07 +0100 | [diff] [blame] | 566 | } |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 567 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 568 | } |
| 569 | case "reorder": { |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 570 | const reordered = await reorderRoleMenuPages(interaction, m, currentObject.options); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 571 | if (!reordered) break; |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 572 | currentObject.options = reordered; |
| 573 | modified = true; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 574 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 575 | } |
| 576 | case "save": { |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 577 | await client.database.guilds.write(interaction.guild.id, { |
| 578 | "roleMenu.options": currentObject.options |
| 579 | }); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 580 | modified = false; |
Skyler Grey | 16ecb17 | 2023-03-05 07:30:32 +0000 | [diff] [blame] | 581 | await client.memory.forceUpdate(interaction.guild.id); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 582 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 583 | } |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 584 | case "switch": { |
| 585 | currentObject.enabled = !currentObject.enabled; |
| 586 | modified = true; |
| 587 | break; |
| 588 | } |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 589 | } |
| 590 | } else if (i.isStringSelectMenu()) { |
| 591 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 592 | case "action": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 593 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 594 | case "edit": { |
| 595 | const edited = await editRoleMenuPage(i, m, current!); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 596 | if (!edited) break; |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 597 | currentObject.options[page] = edited; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 598 | modified = true; |
| 599 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 600 | } |
| 601 | case "delete": { |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 602 | if (page === 0 && currentObject.options.keys.length - 1 > 0) page++; |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame] | 603 | else page--; |
TheCodedProf | 920d729 | 2023-06-05 11:02:32 -0400 | [diff] [blame^] | 604 | currentObject.options.splice(page, 1); |
| 605 | modified = true; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 606 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 607 | } |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 608 | } |
| 609 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 610 | } |
| 611 | case "page": { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 612 | page = parseInt(i.values[0]!); |
| 613 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 614 | } |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 615 | } |
| 616 | } |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 617 | } while (!closed); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 618 | await interaction.deleteReply(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 619 | }; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 620 | |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 621 | const check = (interaction: CommandInteraction, _partial: boolean = false) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 622 | const member = interaction.member as Discord.GuildMember; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 623 | if (!member.permissions.has("ManageRoles")) |
| 624 | return "You must have the *Manage Roles* permission to use this command"; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 625 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 626 | }; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 627 | |
| 628 | export { command }; |
| 629 | export { callback }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 630 | export { check }; |