pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../../utils/defaultEmbeds.js"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 2 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 3 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 4 | import confirmationMessage from "../../utils/confirmationMessage.js"; |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 5 | import Discord, { CommandInteraction, GuildChannel, Message, MessageActionRow, MessageActionRowComponent, MessageButton, MessageComponentInteraction, MessageSelectMenu, Role, SelectMenuInteraction, TextInputComponent } from "discord.js"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 6 | import { SelectMenuOption, SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 7 | import { ChannelType } from "discord-api-types"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 8 | import client from "../../utils/client.js"; |
| 9 | import { toHexInteger, toHexArray, tickets as ticketTypes } from "../../utils/calculate.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 10 | import { capitalize } from "../../utils/generateKeyValueList.js"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 11 | import { modalInteractionCollector } from "../../utils/dualCollector.js"; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 12 | import {GuildConfig} from "../../utils/database.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 13 | |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 14 | const command = (builder: SlashCommandSubcommandBuilder) => builder |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 15 | .setName("tickets") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 16 | .setDescription("Shows settings for tickets | Use no arguments to manage custom types") |
| 17 | .addStringOption(option => option.setName("enabled").setDescription("If users should be able to create tickets").setRequired(false) |
pineafan | 1dc1572 | 2022-03-14 21:27:34 +0000 | [diff] [blame] | 18 | .addChoices([["Yes", "yes"], ["No", "no"]])) |
| 19 | .addChannelOption(option => option.setName("category").setDescription("The category where tickets are created").addChannelType(ChannelType.GuildCategory).setRequired(false)) |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 20 | .addNumberOption(option => option.setName("maxticketsperuser").setDescription("The maximum amount of tickets a user can create | Default: 5").setRequired(false).setMinValue(1)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 21 | .addRoleOption(option => option.setName("supportrole").setDescription("This role will have view access to all tickets and will be pinged when a ticket is created").setRequired(false)); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 22 | |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 23 | const callback = async (interaction: CommandInteraction): Promise<void | unknown> => { |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 24 | let m = await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true}) as Message; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 25 | const options = { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 26 | enabled: interaction.options.getString("enabled") as string | boolean, |
| 27 | category: interaction.options.getChannel("category"), |
| 28 | maxtickets: interaction.options.getNumber("maxticketsperuser"), |
| 29 | supportping: interaction.options.getRole("supportrole") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 30 | }; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 31 | if (options.enabled !== null || options.category || options.maxtickets || options.supportping) { |
| 32 | options.enabled = options.enabled === "yes" ? true : false; |
| 33 | if (options.category) { |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 34 | let channel: GuildChannel; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 35 | try { |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 36 | channel = await interaction.guild.channels.fetch(options.category.id); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 37 | } catch { |
| 38 | return await interaction.editReply({ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 39 | embeds: [new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 40 | .setEmoji("CHANNEL.TEXT.DELETE") |
| 41 | .setTitle("Tickets > Category") |
| 42 | .setDescription("The channel you provided is not a valid category") |
| 43 | .setStatus("Danger") |
| 44 | ] |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 45 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 46 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 47 | channel = channel as Discord.CategoryChannel; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 48 | if (channel.guild.id !== interaction.guild.id) return interaction.editReply({ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 49 | embeds: [new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 50 | .setTitle("Tickets > Category") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 51 | .setDescription("You must choose a category in this server") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 52 | .setStatus("Danger") |
| 53 | .setEmoji("CHANNEL.TEXT.DELETE") |
| 54 | ] |
| 55 | }); |
| 56 | } |
| 57 | if (options.maxtickets) { |
| 58 | if (options.maxtickets < 1) return interaction.editReply({ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 59 | embeds: [new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 60 | .setTitle("Tickets > Max Tickets") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 61 | .setDescription("You must choose a number greater than 0") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 62 | .setStatus("Danger") |
| 63 | .setEmoji("CHANNEL.TEXT.DELETE") |
| 64 | ] |
| 65 | }); |
| 66 | } |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 67 | let role: Role; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 68 | if (options.supportping) { |
| 69 | try { |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 70 | role = await interaction.guild.roles.fetch(options.supportping.id); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 71 | } catch { |
| 72 | return await interaction.editReply({ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 73 | embeds: [new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 74 | .setEmoji("GUILD.ROLE.DELETE") |
| 75 | .setTitle("Tickets > Support Ping") |
| 76 | .setDescription("The role you provided is not a valid role") |
| 77 | .setStatus("Danger") |
| 78 | ] |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 79 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 80 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 81 | role = role as Discord.Role; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 82 | if (role.guild.id !== interaction.guild.id) return interaction.editReply({ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 83 | embeds: [new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 84 | .setTitle("Tickets > Support Ping") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 85 | .setDescription("You must choose a role in this server") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 86 | .setStatus("Danger") |
| 87 | .setEmoji("GUILD.ROLE.DELETE") |
| 88 | ] |
| 89 | }); |
| 90 | } |
| 91 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 92 | const confirmation = await new confirmationMessage(interaction) |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 93 | .setEmoji("GUILD.TICKET.ARCHIVED") |
| 94 | .setTitle("Tickets") |
| 95 | .setDescription( |
| 96 | (options.category ? `**Category:** ${options.category.name}\n` : "") + |
| 97 | (options.maxtickets ? `**Max Tickets:** ${options.maxtickets}\n` : "") + |
| 98 | (options.supportping ? `**Support Ping:** ${options.supportping.name}\n` : "") + |
| 99 | (options.enabled !== null ? `**Enabled:** ${options.enabled ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No` |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 100 | }\n` : "") + |
| 101 | "\nAre you sure you want to apply these settings?" |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 102 | ) |
| 103 | .setColor("Warning") |
| 104 | .setInverted(true) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 105 | .send(true); |
| 106 | if (confirmation.cancelled) return; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 107 | if (confirmation.success) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 108 | const toUpdate = {}; |
| 109 | if (options.enabled !== null) toUpdate["tickets.enabled"] = options.enabled; |
| 110 | if (options.category) toUpdate["tickets.category"] = options.category.id; |
| 111 | if (options.maxtickets) toUpdate["tickets.maxTickets"] = options.maxtickets; |
| 112 | if (options.supportping) toUpdate["tickets.supportRole"] = options.supportping.id; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 113 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 114 | await client.database.guilds.write(interaction.guild.id, toUpdate); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 115 | } catch (e) { |
| 116 | return interaction.editReply({ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 117 | embeds: [new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 118 | .setTitle("Tickets") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 119 | .setDescription("Something went wrong and the staff notifications channel could not be set") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 120 | .setStatus("Danger") |
| 121 | .setEmoji("GUILD.TICKET.DELETE") |
| 122 | ], components: [] |
| 123 | }); |
| 124 | } |
| 125 | } else { |
| 126 | return interaction.editReply({ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 127 | embeds: [new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 128 | .setTitle("Tickets") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 129 | .setDescription("No changes were made") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 130 | .setStatus("Success") |
| 131 | .setEmoji("GUILD.TICKET.OPEN") |
| 132 | ], components: [] |
| 133 | }); |
| 134 | } |
| 135 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 136 | let data = await client.database.guilds.read(interaction.guild.id); |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 137 | data.tickets.customTypes = (data.tickets.customTypes || []).filter((value: string, index: number, array: string[]) => array.indexOf(value) === index); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 138 | let lastClicked = ""; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 139 | let embed: EmojiEmbed; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 140 | data = { |
| 141 | enabled: data.tickets.enabled, |
| 142 | category: data.tickets.category, |
| 143 | maxTickets: data.tickets.maxTickets, |
| 144 | supportRole: data.tickets.supportRole, |
| 145 | useCustom: data.tickets.useCustom, |
| 146 | types: data.tickets.types, |
| 147 | customTypes: data.tickets.customTypes |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 148 | }; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 149 | while (true) { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 150 | embed = new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 151 | .setTitle("Tickets") |
| 152 | .setDescription( |
| 153 | `${data.enabled ? "" : getEmojiByName("TICKETS.REPORT")} **Enabled:** ${data.enabled ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`}\n` + |
| 154 | `${data.category ? "" : getEmojiByName("TICKETS.REPORT")} **Category:** ${data.category ? `<#${data.category}>` : "*None set*"}\n` + |
| 155 | `**Max Tickets:** ${data.maxTickets ? data.maxTickets : "*No limit*"}\n` + |
| 156 | `**Support Ping:** ${data.supportRole ? `<@&${data.supportRole}>` : "*None set*"}\n\n` + |
| 157 | ((data.useCustom && data.customTypes === null) ? `${getEmojiByName("TICKETS.REPORT")} ` : "") + |
| 158 | `${data.useCustom ? "Custom" : "Default"} types in use` + "\n\n" + |
| 159 | `${getEmojiByName("TICKETS.REPORT")} *Indicates a setting stopping tickets from being used*` |
| 160 | ) |
| 161 | .setStatus("Success") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 162 | .setEmoji("GUILD.TICKET.OPEN"); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 163 | m = await interaction.editReply({ |
| 164 | embeds: [embed], components: [new MessageActionRow().addComponents([ |
| 165 | new MessageButton() |
| 166 | .setLabel("Tickets " + (data.enabled ? "enabled" : "disabled")) |
| 167 | .setEmoji(getEmojiByName("CONTROL." + (data.enabled ? "TICK" : "CROSS"), "id")) |
| 168 | .setStyle(data.enabled ? "SUCCESS" : "DANGER") |
| 169 | .setCustomId("enabled"), |
| 170 | new MessageButton() |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 171 | .setLabel(lastClicked === "cat" ? "Click again to confirm" : "Clear category") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 172 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 173 | .setStyle("DANGER") |
| 174 | .setCustomId("clearCategory") |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 175 | .setDisabled(data.category === null), |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 176 | new MessageButton() |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 177 | .setLabel(lastClicked === "max" ? "Click again to confirm" : "Reset max tickets") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 178 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 179 | .setStyle("DANGER") |
| 180 | .setCustomId("clearMaxTickets") |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 181 | .setDisabled(data.maxTickets === 5), |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 182 | new MessageButton() |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 183 | .setLabel(lastClicked === "sup" ? "Click again to confirm" : "Clear support ping") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 184 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 185 | .setStyle("DANGER") |
| 186 | .setCustomId("clearSupportPing") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 187 | .setDisabled(data.supportRole === null) |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 188 | ]), new MessageActionRow().addComponents([ |
| 189 | new MessageButton() |
| 190 | .setLabel("Manage types") |
| 191 | .setEmoji(getEmojiByName("TICKETS.OTHER", "id")) |
| 192 | .setStyle("SECONDARY") |
| 193 | .setCustomId("manageTypes"), |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 194 | new MessageButton() |
| 195 | .setLabel("Add create ticket button") |
| 196 | .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id")) |
| 197 | .setStyle("PRIMARY") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 198 | .setCustomId("send") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 199 | ])] |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 200 | }) as Message; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 201 | let i: MessageComponentInteraction; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 202 | try { |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 203 | i = await m.awaitMessageComponent({ time: 300000 }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 204 | } catch (e) { break; } |
| 205 | i.deferUpdate(); |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 206 | if ((i.component as MessageActionRowComponent).customId === "clearCategory") { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 207 | if (lastClicked === "cat") { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 208 | lastClicked = ""; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 209 | await client.database.guilds.write(interaction.guild.id, null, ["tickets.category"]); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 210 | data.category = undefined; |
| 211 | } else lastClicked = "cat"; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 212 | } else if ((i.component as MessageActionRowComponent).customId === "clearMaxTickets") { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 213 | if (lastClicked === "max") { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 214 | lastClicked = ""; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 215 | await client.database.guilds.write(interaction.guild.id, null, ["tickets.maxTickets"]); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 216 | data.maxTickets = 5; |
| 217 | } else lastClicked = "max"; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 218 | } else if ((i.component as MessageActionRowComponent).customId === "clearSupportPing") { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 219 | if (lastClicked === "sup") { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 220 | lastClicked = ""; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 221 | await client.database.guilds.write(interaction.guild.id, null, ["tickets.supportRole"]); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 222 | data.supportRole = undefined; |
| 223 | } else lastClicked = "sup"; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 224 | } else if ((i.component as MessageActionRowComponent).customId === "send") { |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 225 | const ticketMessages = [ |
| 226 | {label: "Create ticket", description: "Click the button below to create a ticket"}, |
| 227 | {label: "Issues, questions or feedback?", description: "Click below to open a ticket and get help from our staff team"}, |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 228 | {label: "Contact Us", description: "Click the button below to speak to us privately"} |
| 229 | ]; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 230 | while (true) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 231 | const enabled = data.enabled && data.category !== null; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 232 | await interaction.editReply({embeds: [new EmojiEmbed() |
| 233 | .setTitle("Ticket Button") |
| 234 | .setDescription("Select a message template to send in this channel") |
| 235 | .setFooter({text: enabled ? "" : "Tickets are not set up correctly so the button may not work for users. Check the main menu to find which options must be set."}) |
| 236 | .setStatus(enabled ? "Success" : "Warning") |
| 237 | .setEmoji("GUILD.ROLES.CREATE") |
| 238 | ], components: [ |
| 239 | new MessageActionRow().addComponents([ |
| 240 | new MessageSelectMenu().setOptions(ticketMessages.map((t: {label: string, description: string, value?: string}, index) => { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 241 | t.value = index.toString(); return t as {value: string, label: string, description: string}; |
| 242 | })).setCustomId("template").setMaxValues(1).setMinValues(1).setPlaceholder("Select a message template") |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 243 | ]), |
| 244 | new MessageActionRow().addComponents([ |
| 245 | new MessageButton() |
| 246 | .setCustomId("back") |
| 247 | .setLabel("Back") |
| 248 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 249 | .setStyle("DANGER"), |
| 250 | new MessageButton() |
| 251 | .setCustomId("blank") |
| 252 | .setLabel("Empty") |
| 253 | .setStyle("SECONDARY"), |
| 254 | new MessageButton() |
| 255 | .setCustomId("custom") |
| 256 | .setLabel("Custom") |
| 257 | .setEmoji(getEmojiByName("TICKETS.OTHER", "id")) |
| 258 | .setStyle("PRIMARY") |
| 259 | ]) |
| 260 | ]}); |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 261 | let i: MessageComponentInteraction; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 262 | try { |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 263 | i = await m.awaitMessageComponent({time: 300000}); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 264 | } catch(e) { break; } |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 265 | if ((i.component as MessageActionRowComponent).customId === "template") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 266 | i.deferUpdate(); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 267 | await interaction.channel.send({embeds: [new EmojiEmbed() |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 268 | .setTitle(ticketMessages[parseInt((i as SelectMenuInteraction).values[0])].label) |
| 269 | .setDescription(ticketMessages[parseInt((i as SelectMenuInteraction).values[0])].description) |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 270 | .setStatus("Success") |
| 271 | .setEmoji("GUILD.TICKET.OPEN") |
| 272 | ], components: [new MessageActionRow().addComponents([new MessageButton() |
| 273 | .setLabel("Create Ticket") |
| 274 | .setEmoji(getEmojiByName("CONTROL.TICK", "id")) |
| 275 | .setStyle("SUCCESS") |
| 276 | .setCustomId("createticket") |
| 277 | ])]}); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 278 | break; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 279 | } else if ((i.component as MessageActionRowComponent).customId === "blank") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 280 | i.deferUpdate(); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 281 | await interaction.channel.send({components: [new MessageActionRow().addComponents([new MessageButton() |
| 282 | .setLabel("Create Ticket") |
| 283 | .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id")) |
| 284 | .setStyle("SUCCESS") |
| 285 | .setCustomId("createticket") |
| 286 | ])]}); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 287 | break; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 288 | } else if ((i.component as MessageActionRowComponent).customId === "custom") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 289 | await i.showModal(new Discord.Modal().setCustomId("modal").setTitle("Enter embed details").addComponents( |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 290 | new MessageActionRow<TextInputComponent>().addComponents(new TextInputComponent() |
| 291 | .setCustomId("title") |
| 292 | .setLabel("Title") |
| 293 | .setMaxLength(256) |
| 294 | .setRequired(true) |
| 295 | .setStyle("SHORT") |
| 296 | ), |
| 297 | new MessageActionRow<TextInputComponent>().addComponents(new TextInputComponent() |
| 298 | .setCustomId("description") |
| 299 | .setLabel("Description") |
| 300 | .setMaxLength(4000) |
| 301 | .setRequired(true) |
| 302 | .setStyle("PARAGRAPH") |
| 303 | ) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 304 | )); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 305 | await interaction.editReply({ |
| 306 | embeds: [new EmojiEmbed() |
| 307 | .setTitle("Ticket Button") |
| 308 | .setDescription("Modal opened. If you can't see it, click back and try again.") |
| 309 | .setStatus("Success") |
| 310 | .setEmoji("GUILD.TICKET.OPEN") |
| 311 | ], components: [new MessageActionRow().addComponents([new MessageButton() |
| 312 | .setLabel("Back") |
| 313 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 314 | .setStyle("PRIMARY") |
| 315 | .setCustomId("back") |
| 316 | ])] |
| 317 | }); |
| 318 | let out; |
| 319 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 320 | out = await modalInteractionCollector(m, (m) => m.channel.id === interaction.channel.id, (m) => m.customId === "modify"); |
| 321 | } catch (e) { break; } |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 322 | if (out.fields) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 323 | const title = out.fields.getTextInputValue("title"); |
| 324 | const description = out.fields.getTextInputValue("description"); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 325 | await interaction.channel.send({embeds: [new EmojiEmbed() |
| 326 | .setTitle(title) |
| 327 | .setDescription(description) |
| 328 | .setStatus("Success") |
| 329 | .setEmoji("GUILD.TICKET.OPEN") |
| 330 | ], components: [new MessageActionRow().addComponents([new MessageButton() |
| 331 | .setLabel("Create Ticket") |
| 332 | .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id")) |
| 333 | .setStyle("SUCCESS") |
| 334 | .setCustomId("createticket") |
| 335 | ])]}); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 336 | break; |
| 337 | } else { continue; } |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 338 | } |
| 339 | } |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 340 | } else if ((i.component as MessageActionRowComponent).customId === "enabled") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 341 | await client.database.guilds.write(interaction.guild.id, { "tickets.enabled": !data.enabled }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 342 | data.enabled = !data.enabled; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 343 | } else if ((i.component as MessageActionRowComponent).customId === "manageTypes") { |
| 344 | data = await manageTypes(interaction, data, m as Message); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 345 | } else { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 346 | break; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | await interaction.editReply({ embeds: [embed.setFooter({ text: "Message closed" })], components: [] }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 350 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 351 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 352 | async function manageTypes(interaction: CommandInteraction, data: GuildConfig["tickets"], m: Message) { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 353 | while (true) { |
| 354 | if (data.useCustom) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 355 | const customTypes = data.customTypes; |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 356 | await interaction.editReply({ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 357 | embeds: [new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 358 | .setTitle("Tickets > Types") |
| 359 | .setDescription( |
| 360 | "**Custom types enabled**\n\n" + |
| 361 | "**Types in use:**\n" + ((customTypes !== null) ? |
| 362 | (customTypes.map((t) => `> ${t}`).join("\n")) : |
| 363 | "*None set*" |
| 364 | ) + "\n\n" + (customTypes === null ? |
| 365 | `${getEmojiByName("TICKETS.REPORT")} Having no types will disable tickets. Please add at least 1 type or use default types` : "" |
| 366 | ) |
| 367 | ) |
| 368 | .setStatus("Success") |
| 369 | .setEmoji("GUILD.TICKET.OPEN") |
| 370 | ], components: (customTypes ? [ |
| 371 | new MessageActionRow().addComponents([new Discord.MessageSelectMenu() |
| 372 | .setCustomId("removeTypes") |
| 373 | .setPlaceholder("Select types to remove") |
| 374 | .setMaxValues(customTypes.length) |
| 375 | .setMinValues(1) |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 376 | .addOptions(customTypes.map((t) => ({ |
| 377 | label: t, |
| 378 | value: t |
| 379 | }))) |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 380 | ]) |
| 381 | ] : []).concat([ |
| 382 | new MessageActionRow().addComponents([ |
| 383 | new MessageButton() |
| 384 | .setLabel("Back") |
| 385 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 386 | .setStyle("PRIMARY") |
| 387 | .setCustomId("back"), |
| 388 | new MessageButton() |
| 389 | .setLabel("Add new type") |
| 390 | .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id")) |
| 391 | .setStyle("PRIMARY") |
| 392 | .setCustomId("addType") |
| 393 | .setDisabled(customTypes !== null && customTypes.length >= 25), |
| 394 | new MessageButton() |
| 395 | .setLabel("Switch to default types") |
| 396 | .setStyle("SECONDARY") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 397 | .setCustomId("switchToDefault") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 398 | ]) |
| 399 | ]) |
| 400 | }); |
| 401 | } else { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 402 | const inUse = toHexArray(data.types, ticketTypes); |
| 403 | const options = []; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 404 | ticketTypes.forEach(type => { |
| 405 | options.push(new SelectMenuOption({ |
| 406 | label: capitalize(type), |
| 407 | value: type, |
PineappleFan | b3dd83c | 2022-06-17 10:53:48 +0100 | [diff] [blame] | 408 | emoji: client.emojis.cache.get(getEmojiByName(`TICKETS.${type.toUpperCase()}`, "id")), |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 409 | default: inUse.includes(type) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 410 | })); |
| 411 | }); |
| 412 | const selectPane = new MessageActionRow().addComponents([ |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 413 | new Discord.MessageSelectMenu() |
| 414 | .addOptions(options) |
| 415 | .setCustomId("types") |
| 416 | .setMaxValues(ticketTypes.length) |
| 417 | .setMinValues(1) |
| 418 | .setPlaceholder("Select types to use") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 419 | ]); |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 420 | await interaction.editReply({ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 421 | embeds: [new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 422 | .setTitle("Tickets > Types") |
| 423 | .setDescription( |
| 424 | "**Default types enabled**\n\n" + |
| 425 | "**Types in use:**\n" + |
| 426 | (inUse.map((t) => `> ${getEmojiByName("TICKETS." + t.toUpperCase())} ${capitalize(t)}`).join("\n")) |
| 427 | ) |
| 428 | .setStatus("Success") |
| 429 | .setEmoji("GUILD.TICKET.OPEN") |
| 430 | ], components: [ |
| 431 | selectPane, |
| 432 | new MessageActionRow().addComponents([ |
| 433 | new MessageButton() |
| 434 | .setLabel("Back") |
| 435 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 436 | .setStyle("PRIMARY") |
| 437 | .setCustomId("back"), |
| 438 | new MessageButton() |
| 439 | .setLabel("Switch to custom types") |
| 440 | .setStyle("SECONDARY") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 441 | .setCustomId("switchToCustom") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 442 | ]) |
| 443 | ] |
| 444 | }); |
| 445 | } |
| 446 | let i; |
| 447 | try { |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 448 | i = await m.awaitMessageComponent({ time: 300000 }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 449 | } catch (e) { break; } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 450 | if (i.component.customId === "types") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 451 | i.deferUpdate(); |
| 452 | const types = toHexInteger(i.values, ticketTypes); |
| 453 | await client.database.guilds.write(interaction.guild.id, { "tickets.types": types }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 454 | data.types = types; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 455 | } else if (i.component.customId === "removeTypes") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 456 | i.deferUpdate(); |
| 457 | const types = i.values; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 458 | let customTypes = data.customTypes; |
| 459 | if (customTypes) { |
| 460 | customTypes = customTypes.filter((t) => !types.includes(t)); |
| 461 | customTypes = customTypes.length > 0 ? customTypes : null; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 462 | await client.database.guilds.write(interaction.guild.id, { "tickets.customTypes": customTypes }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 463 | data.customTypes = customTypes; |
| 464 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 465 | } else if (i.component.customId === "addType") { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 466 | await i.showModal(new Discord.Modal().setCustomId("modal").setTitle("Enter a name for the new type").addComponents( |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 467 | new MessageActionRow<TextInputComponent>().addComponents(new TextInputComponent() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 468 | .setCustomId("type") |
| 469 | .setLabel("Name") |
| 470 | .setMaxLength(100) |
| 471 | .setMinLength(1) |
| 472 | .setPlaceholder("E.g. \"Server Idea\"") |
| 473 | .setRequired(true) |
| 474 | .setStyle("SHORT") |
| 475 | ) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 476 | )); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 477 | await interaction.editReply({ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 478 | embeds: [new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 479 | .setTitle("Tickets > Types") |
| 480 | .setDescription("Modal opened. If you can't see it, click back and try again.") |
| 481 | .setStatus("Success") |
| 482 | .setEmoji("GUILD.TICKET.OPEN") |
| 483 | ], components: [new MessageActionRow().addComponents([new MessageButton() |
| 484 | .setLabel("Back") |
| 485 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 486 | .setStyle("PRIMARY") |
| 487 | .setCustomId("back") |
| 488 | ])] |
| 489 | }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 490 | let out; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 491 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 492 | out = await modalInteractionCollector(m, (m) => m.channel.id === interaction.channel.id, (m) => m.customId === "addType"); |
| 493 | } catch (e) { continue; } |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 494 | if (out.fields) { |
| 495 | let toAdd = out.fields.getTextInputValue("type"); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 496 | if (!toAdd) { continue; } |
| 497 | toAdd = toAdd.substring(0, 80); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 498 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 499 | await client.database.guilds.append(interaction.guild.id, "tickets.customTypes", toAdd); |
| 500 | } catch { continue; } |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 501 | data.customTypes = data.customTypes || []; |
| 502 | if (!data.customTypes.includes(toAdd)) { |
| 503 | data.customTypes.push(toAdd); |
| 504 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 505 | } else { continue; } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 506 | } else if (i.component.customId === "switchToDefault") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 507 | i.deferUpdate(); |
| 508 | await client.database.guilds.write(interaction.guild.id, { "tickets.useCustom": false }, []); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 509 | data.useCustom = false; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 510 | } else if (i.component.customId === "switchToCustom") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 511 | i.deferUpdate(); |
| 512 | await client.database.guilds.write(interaction.guild.id, { "tickets.useCustom": true }, []); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 513 | data.useCustom = true; |
| 514 | } else { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 515 | i.deferUpdate(); |
| 516 | break; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 517 | } |
| 518 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 519 | return data; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 523 | const check = (interaction: CommandInteraction) => { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 524 | const member = (interaction.member as Discord.GuildMember); |
| 525 | if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the *Manage Server* permission to use this command"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 526 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 527 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 528 | |
| 529 | export { command }; |
| 530 | export { callback }; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 531 | export { check }; |