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