TheCodedProf | afca98b | 2023-01-17 22:25:43 -0500 | [diff] [blame] | 1 | import type Discord from "discord.js"; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 2 | import { ActionRowBuilder, APIMessageComponentEmoji, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction, Message, ModalBuilder, RoleSelectMenuBuilder, RoleSelectMenuInteraction, StringSelectMenuBuilder, StringSelectMenuInteraction, StringSelectMenuOptionBuilder, TextInputBuilder, TextInputStyle } from "discord.js"; |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 3 | import type { SlashCommandSubcommandBuilder } from "discord.js"; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 4 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
| 5 | import { LoadingEmbed } from "../../utils/defaults.js"; |
| 6 | import client from "../../utils/client.js"; |
| 7 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
| 8 | import createPageIndicator from "../../utils/createPageIndicator.js"; |
| 9 | import { configToDropdown } from "../../actions/roleMenu.js"; |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 10 | import { modalInteractionCollector } from "../../utils/dualCollector.js"; |
| 11 | import lodash from 'lodash'; |
| 12 | const isEqual = lodash.isEqual; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 13 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 14 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 15 | .setName("rolemenu") |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 16 | .setDescription("rolemenu") |
| 17 | |
| 18 | interface ObjectSchema { |
| 19 | name: string; |
| 20 | description: string; |
| 21 | min: number; |
| 22 | max: number; |
| 23 | options: { |
| 24 | name: string; |
| 25 | description: string | null; |
| 26 | role: string; |
| 27 | }[]; |
| 28 | } |
| 29 | |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 30 | const defaultRolePageConfig = { |
| 31 | name: "Role Menu Page", |
| 32 | description: "A new role menu page", |
| 33 | min: 0, |
| 34 | max: 0, |
| 35 | options: [ |
| 36 | {name: "Role 1", description: null, role: "No role set"} |
| 37 | ] |
| 38 | } |
| 39 | |
| 40 | const editNameDescription = async (i: ButtonInteraction, interaction: StringSelectMenuInteraction | ButtonInteraction, m: Message, data: {name?: string, description?: string}) => { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 41 | |
| 42 | let {name, description} = data; |
| 43 | const modal = new ModalBuilder() |
| 44 | .setTitle("Edit Name and Description") |
| 45 | .setCustomId("editNameDescription") |
| 46 | .addComponents( |
| 47 | new ActionRowBuilder<TextInputBuilder>() |
| 48 | .addComponents( |
| 49 | new TextInputBuilder() |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 50 | .setLabel("Name") |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 51 | .setCustomId("name") |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 52 | .setPlaceholder("Name here...") // TODO: Make better placeholder |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 53 | .setStyle(TextInputStyle.Short) |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 54 | .setValue(name ?? "") |
| 55 | .setRequired(true) |
| 56 | ), |
| 57 | new ActionRowBuilder<TextInputBuilder>() |
| 58 | .addComponents( |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 59 | new TextInputBuilder() |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 60 | .setLabel("Description") |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 61 | .setCustomId("description") |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 62 | .setPlaceholder("Description here...") // TODO: Make better placeholder |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 63 | .setStyle(TextInputStyle.Short) |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 64 | .setValue(description ?? "") |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 65 | ) |
| 66 | ) |
| 67 | const button = new ActionRowBuilder<ButtonBuilder>() |
| 68 | .addComponents( |
| 69 | new ButtonBuilder() |
| 70 | .setCustomId("back") |
| 71 | .setLabel("Back") |
| 72 | .setStyle(ButtonStyle.Secondary) |
| 73 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji) |
| 74 | ) |
| 75 | |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 76 | await i.showModal(modal) |
| 77 | await interaction.editReply({ |
| 78 | embeds: [ |
| 79 | new EmojiEmbed() |
| 80 | .setTitle("Role Menu") |
| 81 | .setDescription("Modal opened. If you can't see it, click back and try again.") |
| 82 | .setStatus("Success") |
| 83 | ], |
| 84 | components: [button] |
| 85 | }); |
| 86 | |
| 87 | let out: Discord.ModalSubmitInteraction | null; |
| 88 | try { |
| 89 | out = await modalInteractionCollector( |
| 90 | m, |
| 91 | (m) => m.channel!.id === interaction.channel!.id, |
| 92 | (_) => true |
| 93 | ) as Discord.ModalSubmitInteraction | null; |
| 94 | } catch (e) { |
| 95 | console.error(e); |
| 96 | out = null; |
| 97 | } |
| 98 | if(!out) return [name, description]; |
| 99 | if (out.isButton()) return [name, description]; |
| 100 | if(!out.fields) return [name, description]; |
| 101 | name = out.fields.fields.find((f) => f.customId === "name")?.value ?? name; |
| 102 | description = out.fields.fields.find((f) => f.customId === "description")?.value ?? description; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 103 | return [name, description] |
| 104 | |
| 105 | } |
| 106 | |
| 107 | const ellipsis = (str: string, max: number): string => { |
| 108 | if (str.length <= max) return str; |
| 109 | return str.slice(0, max - 3) + "..."; |
| 110 | } |
| 111 | |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 112 | const createRoleMenuPage = async (interaction: StringSelectMenuInteraction | ButtonInteraction, m: Message, data?: ObjectSchema): Promise<ObjectSchema | null> => { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 113 | if (!data) data = { |
| 114 | name: "Role Menu Page", |
| 115 | description: "A new role menu page", |
| 116 | min: 0, |
| 117 | max: 0, |
| 118 | options: [] |
| 119 | }; |
| 120 | const buttons = new ActionRowBuilder<ButtonBuilder>() |
| 121 | .addComponents( |
| 122 | new ButtonBuilder() |
| 123 | .setCustomId("back") |
| 124 | .setLabel("Back") |
| 125 | .setStyle(ButtonStyle.Secondary) |
| 126 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji), |
| 127 | new ButtonBuilder() |
| 128 | .setCustomId("edit") |
| 129 | .setLabel("Edit") |
| 130 | .setStyle(ButtonStyle.Primary) |
| 131 | .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji), |
| 132 | new ButtonBuilder() |
| 133 | .setCustomId("addRole") |
| 134 | .setLabel("Add Role") |
| 135 | .setStyle(ButtonStyle.Secondary) |
| 136 | .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id") as APIMessageComponentEmoji) |
| 137 | ); |
| 138 | |
| 139 | let back = false |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 140 | if(data.options.length === 0) { |
| 141 | data.options = [ |
| 142 | {name: "Role 1", description: null, role: "No role set"} |
| 143 | ] |
| 144 | } |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 145 | do { |
| 146 | const previewSelect = configToDropdown("Edit Roles", {name: data.name, description: data.description, min: 1, max: 1, options: data.options}); |
| 147 | const embed = new EmojiEmbed() |
| 148 | .setTitle(`${data.name}`) |
| 149 | .setStatus("Success") |
| 150 | .setDescription( |
| 151 | `**Description:**\n> ${data.description}\n\n` + |
| 152 | `**Min:** ${data.min}` + (data.min === 0 ? " (Members will be given a skip button)" : "") + "\n" + |
| 153 | `**Max:** ${data.max}\n` |
| 154 | ) |
| 155 | |
| 156 | interaction.editReply({embeds: [embed], components: [previewSelect, buttons]}); |
| 157 | let i: StringSelectMenuInteraction | ButtonInteraction; |
| 158 | try { |
| 159 | i = await m.awaitMessageComponent({ time: 300000, filter: (i) => i.user.id === interaction.user.id && i.message.id === m.id && i.channelId === interaction.channelId}) as ButtonInteraction | StringSelectMenuInteraction; |
| 160 | } catch (e) { |
| 161 | back = true; |
| 162 | break; |
| 163 | } |
| 164 | |
| 165 | if (i.isStringSelectMenu()) { |
| 166 | if(i.customId === "roles") { |
| 167 | await i.deferUpdate(); |
| 168 | await createRoleMenuOptionPage(interaction, m, data.options.find((o) => o.role === (i as StringSelectMenuInteraction).values[0])); |
| 169 | } |
| 170 | } else if (i.isButton()) { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 171 | switch (i.customId) { |
| 172 | case "back": |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 173 | await i.deferUpdate(); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 174 | back = true; |
| 175 | break; |
| 176 | case "edit": |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 177 | let [name, description] = await editNameDescription(i, interaction, m, data); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 178 | data.name = name ? name : data.name; |
| 179 | data.description = description ? description : data.description; |
| 180 | break; |
| 181 | case "addRole": |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 182 | await i.deferUpdate(); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 183 | data.options.push(await createRoleMenuOptionPage(interaction, m)); |
| 184 | break; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | } while (!back); |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 189 | if(isEqual(data, defaultRolePageConfig)) return null; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 190 | return data; |
| 191 | } |
| 192 | |
| 193 | const createRoleMenuOptionPage = async (interaction: StringSelectMenuInteraction | ButtonInteraction, m: Message, data?: {name: string; description: string | null; role: string}) => { |
| 194 | const { renderRole} = client.logger; |
| 195 | if (!data) data = { |
| 196 | name: "Role Menu Option", |
| 197 | description: null, |
| 198 | role: "No role set" |
| 199 | }; |
| 200 | let back = false; |
| 201 | const buttons = new ActionRowBuilder<ButtonBuilder>() |
| 202 | .addComponents( |
| 203 | new ButtonBuilder() |
| 204 | .setCustomId("back") |
| 205 | .setLabel("Back") |
| 206 | .setStyle(ButtonStyle.Secondary) |
| 207 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji), |
| 208 | new ButtonBuilder() |
| 209 | .setCustomId("edit") |
| 210 | .setLabel("Edit Details") |
| 211 | .setStyle(ButtonStyle.Primary) |
| 212 | .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji) |
| 213 | ); |
| 214 | do { |
| 215 | const roleSelect = new RoleSelectMenuBuilder().setCustomId("role").setPlaceholder(data.role ? "Set role to" : "Set the role"); |
| 216 | const embed = new EmojiEmbed() |
| 217 | .setTitle(`${data.name ?? "New Role Menu Option"}`) |
| 218 | .setStatus("Success") |
| 219 | .setDescription( |
| 220 | `**Description:**\n> ${data.description ?? "No description set"}\n\n` + |
| 221 | `**Role:** ${renderRole((await interaction.guild!.roles.fetch(data.role))!) ?? "No role set"}\n` |
| 222 | ) |
| 223 | |
| 224 | interaction.editReply({embeds: [embed], components: [new ActionRowBuilder<RoleSelectMenuBuilder>().addComponents(roleSelect), buttons]}); |
| 225 | |
| 226 | let i: RoleSelectMenuInteraction | ButtonInteraction; |
| 227 | try { |
| 228 | i = await m.awaitMessageComponent({ time: 300000, filter: (i) => i.user.id === interaction.user.id && i.message.id === m.id && i.channelId === interaction.channelId}) as ButtonInteraction | RoleSelectMenuInteraction; |
| 229 | } catch (e) { |
| 230 | back = true; |
| 231 | break; |
| 232 | } |
| 233 | |
| 234 | if (i.isRoleSelectMenu()) { |
| 235 | if(i.customId === "role") { |
| 236 | await i.deferUpdate(); |
| 237 | data.role = (i as RoleSelectMenuInteraction).values[0]!; |
| 238 | } |
| 239 | } else if (i.isButton()) { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 240 | switch (i.customId) { |
| 241 | case "back": |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 242 | await i.deferUpdate(); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 243 | back = true; |
| 244 | break; |
| 245 | case "edit": |
| 246 | await i.deferUpdate(); |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 247 | let [name, description] = await editNameDescription(i, interaction, m, data as {name: string; description: string}); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 248 | data.name = name ? name : data.name; |
| 249 | data.description = description ? description : data.description; |
| 250 | break; |
| 251 | } |
| 252 | } |
| 253 | } while (!back); |
| 254 | return data; |
| 255 | } |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 256 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 257 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 258 | if (!interaction.guild) return; |
| 259 | const m = await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true}); |
| 260 | |
| 261 | let page = 0; |
| 262 | let closed = false; |
| 263 | const config = await client.database.guilds.read(interaction.guild.id); |
| 264 | let currentObject: ObjectSchema[] = config.roleMenu.options; |
| 265 | let modified = false; |
| 266 | do { |
| 267 | const embed = new EmojiEmbed() |
| 268 | .setTitle("Role Menu Settings") |
| 269 | .setEmoji("GUILD.GREEN") |
| 270 | .setStatus("Success"); |
| 271 | const noRoleMenus = currentObject.length === 0; |
| 272 | let current: ObjectSchema; |
| 273 | |
| 274 | const pageSelect = new StringSelectMenuBuilder() |
| 275 | .setCustomId("page") |
| 276 | .setPlaceholder("Select a Role Menu page to manage"); |
| 277 | const actionSelect = new StringSelectMenuBuilder() |
| 278 | .setCustomId("action") |
| 279 | .setPlaceholder("Perform an action") |
| 280 | .addOptions( |
| 281 | new StringSelectMenuOptionBuilder() |
| 282 | .setLabel("Edit") |
| 283 | .setDescription("Edit this page") |
| 284 | .setValue("edit") |
| 285 | .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji), |
| 286 | new StringSelectMenuOptionBuilder() |
| 287 | .setLabel("Delete") |
| 288 | .setDescription("Delete this page") |
| 289 | .setValue("delete") |
| 290 | .setEmoji(getEmojiByName("TICKETS.ISSUE", "id") as APIMessageComponentEmoji) |
| 291 | ); |
| 292 | const buttonRow = new ActionRowBuilder<ButtonBuilder>() |
| 293 | .addComponents( |
| 294 | new ButtonBuilder() |
| 295 | .setCustomId("back") |
| 296 | .setStyle(ButtonStyle.Primary) |
| 297 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji) |
| 298 | .setDisabled(page === 0), |
| 299 | new ButtonBuilder() |
| 300 | .setCustomId("next") |
| 301 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id") as APIMessageComponentEmoji) |
| 302 | .setStyle(ButtonStyle.Primary) |
| 303 | .setDisabled(page === Object.keys(currentObject).length - 1), |
| 304 | new ButtonBuilder() |
| 305 | .setCustomId("add") |
| 306 | .setLabel("New Page") |
| 307 | .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id") as APIMessageComponentEmoji) |
| 308 | .setStyle(ButtonStyle.Secondary) |
| 309 | .setDisabled(Object.keys(currentObject).length >= 24), |
| 310 | new ButtonBuilder() |
| 311 | .setCustomId("reorder") |
| 312 | .setLabel("Reorder Pages") |
| 313 | .setEmoji(getEmojiByName("ICONS.SHUFFLE", "id") as APIMessageComponentEmoji) |
| 314 | .setStyle(ButtonStyle.Secondary) |
| 315 | .setDisabled(Object.keys(currentObject).length <= 1), |
| 316 | new ButtonBuilder() |
| 317 | .setCustomId("save") |
| 318 | .setLabel("Save") |
| 319 | .setEmoji(getEmojiByName("ICONS.SAVE", "id") as APIMessageComponentEmoji) |
| 320 | .setStyle(ButtonStyle.Success) |
| 321 | .setDisabled(!modified), |
| 322 | ); |
| 323 | if(noRoleMenus) { |
| 324 | embed.setDescription("No role menu page have been set up yet. Use the button below to add one.\n\n" + |
| 325 | createPageIndicator(1, 1, undefined, true) |
| 326 | ); |
| 327 | pageSelect.setDisabled(true); |
| 328 | actionSelect.setDisabled(true); |
| 329 | pageSelect.addOptions(new StringSelectMenuOptionBuilder() |
| 330 | .setLabel("No role menu pages") |
| 331 | .setValue("none") |
| 332 | ); |
| 333 | } else { |
| 334 | page = Math.min(page, Object.keys(currentObject).length - 1); |
| 335 | current = currentObject[page]!; |
| 336 | embed.setDescription(`**Currently Editing:** ${current.name}\n\n` + |
| 337 | `**Description:** \`${current.description}\`\n` + |
| 338 | `\n\n${createPageIndicator(Object.keys(config.roleMenu.options).length, page)}` |
| 339 | ); |
| 340 | |
| 341 | pageSelect.addOptions( |
| 342 | currentObject.map((key: ObjectSchema, index) => { |
| 343 | return new StringSelectMenuOptionBuilder() |
| 344 | .setLabel(ellipsis(key.name, 50)) |
| 345 | .setDescription(ellipsis(key.description, 50)) |
| 346 | .setValue(index.toString()); |
| 347 | }) |
| 348 | ); |
| 349 | |
| 350 | } |
| 351 | |
| 352 | await interaction.editReply({embeds: [embed], components: [new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(actionSelect), new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(pageSelect), buttonRow]}); |
| 353 | let i: StringSelectMenuInteraction | ButtonInteraction; |
| 354 | try { |
| 355 | i = await m.awaitMessageComponent({ time: 300000, filter: (i) => i.user.id === interaction.user.id && i.message.id === m.id && i.channelId === interaction.channelId}) as ButtonInteraction | StringSelectMenuInteraction; |
| 356 | } catch (e) { |
| 357 | closed = true; |
| 358 | break; |
| 359 | } |
| 360 | |
| 361 | await i.deferUpdate(); |
| 362 | if (i.isButton()) { |
| 363 | switch (i.customId) { |
| 364 | case "back": |
| 365 | page--; |
| 366 | break; |
| 367 | case "next": |
| 368 | page++; |
| 369 | break; |
| 370 | case "add": |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 371 | let newPage = await createRoleMenuPage(i, m) |
| 372 | if(!newPage) break; |
| 373 | currentObject.push(); |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 374 | page = currentObject.length - 1; |
| 375 | break; |
| 376 | case "reorder": |
| 377 | break; |
| 378 | case "save": |
| 379 | client.database.guilds.write(interaction.guild.id, {"roleMenu.options": currentObject}); |
| 380 | modified = false; |
| 381 | break; |
| 382 | } |
| 383 | } else if (i.isStringSelectMenu()) { |
| 384 | switch (i.customId) { |
| 385 | case "action": |
| 386 | switch(i.values[0]) { |
| 387 | case "edit": |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 388 | let edited = await createRoleMenuPage(i, m, current!); |
| 389 | if(!edited) break; |
| 390 | currentObject[page] = edited; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 391 | modified = true; |
| 392 | break; |
| 393 | case "delete": |
TheCodedProf | f4facde | 2023-01-28 13:42:48 -0500 | [diff] [blame^] | 394 | if(page === 0 && currentObject.keys.length - 1 > 0) page++; |
| 395 | else page--; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 396 | currentObject.splice(page, 1); |
| 397 | break; |
| 398 | } |
| 399 | break; |
| 400 | case "page": |
| 401 | page = parseInt(i.values[0]!); |
| 402 | break; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | } while (!closed) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 407 | }; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 408 | |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 409 | const check = (interaction: CommandInteraction, _partial: boolean = false) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 410 | const member = interaction.member as Discord.GuildMember; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 411 | if (!member.permissions.has("ManageRoles")) |
| 412 | return "You must have the *Manage Roles* permission to use this command"; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 413 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 414 | }; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 415 | |
| 416 | export { command }; |
| 417 | export { callback }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 418 | export { check }; |