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