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