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