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