blob: ff545aaa68f28015aa5146187b69549df44ba47f [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../../utils/defaults.js";
pineafan6702cef2022-06-13 17:52:37 +01002import getEmojiByName from "../../utils/getEmojiByName.js";
pineafan4edb7762022-06-26 19:21:04 +01003import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
pineafan6702cef2022-06-13 17:52:37 +01004import confirmationMessage from "../../utils/confirmationMessage.js";
Skyler Grey75ea9172022-08-06 10:22:23 +01005import Discord, {
6 CommandInteraction,
7 GuildChannel,
8 Message,
TheCodedProf21c08592022-09-13 14:14:43 -04009 ActionRowBuilder,
10 Component,
11 ButtonBuilder,
Skyler Grey75ea9172022-08-06 10:22:23 +010012 MessageComponentInteraction,
TheCodedProfa16d1672023-01-18 18:58:34 -050013 StringSelectMenuBuilder,
Skyler Grey75ea9172022-08-06 10:22:23 +010014 Role,
TheCodedProfa16d1672023-01-18 18:58:34 -050015 StringSelectMenuInteraction,
TheCodedProf59772f82023-01-18 22:17:16 -050016 ButtonStyle,
17 TextInputBuilder,
18 ButtonComponent,
19 StringSelectMenuComponent,
20 ModalSubmitInteraction,
21 APIMessageComponentEmoji
Skyler Grey75ea9172022-08-06 10:22:23 +010022} from "discord.js";
TheCodedProf59772f82023-01-18 22:17:16 -050023import { SlashCommandSubcommandBuilder, StringSelectMenuOptionBuilder } from "@discordjs/builders";
Skyler Greyc634e2b2022-08-06 17:50:48 +010024import { ChannelType } from "discord-api-types/v9";
pineafan6702cef2022-06-13 17:52:37 +010025import client from "../../utils/client.js";
Skyler Grey11236ba2022-08-08 21:13:33 +010026import { toHexInteger, toHexArray, tickets as ticketTypes } from "../../utils/calculate.js";
pineafan63fc5e22022-08-04 22:04:10 +010027import { capitalize } from "../../utils/generateKeyValueList.js";
pineafan6702cef2022-06-13 17:52:37 +010028import { modalInteractionCollector } from "../../utils/dualCollector.js";
pineafan3a02ea32022-08-11 21:35:04 +010029import type { GuildConfig } from "../../utils/database.js";
pineafan4f164f32022-02-26 22:07:12 +000030
Skyler Grey75ea9172022-08-06 10:22:23 +010031const command = (builder: SlashCommandSubcommandBuilder) =>
32 builder
33 .setName("tickets")
Skyler Grey11236ba2022-08-08 21:13:33 +010034 .setDescription("Shows settings for tickets | Use no arguments to manage custom types")
Skyler Grey75ea9172022-08-06 10:22:23 +010035 .addStringOption((option) =>
36 option
37 .setName("enabled")
38 .setDescription("If users should be able to create tickets")
39 .setRequired(false)
PineaFan64486c42022-12-28 09:21:04 +000040 .addChoices(
41 {name: "Yes", value: "yes"},
42 {name: "No",value: "no"}
43 )
Skyler Grey75ea9172022-08-06 10:22:23 +010044 )
45 .addChannelOption((option) =>
46 option
47 .setName("category")
48 .setDescription("The category where tickets are created")
PineaFan64486c42022-12-28 09:21:04 +000049 .addChannelTypes(ChannelType.GuildCategory)
Skyler Grey75ea9172022-08-06 10:22:23 +010050 .setRequired(false)
51 )
52 .addNumberOption((option) =>
53 option
54 .setName("maxticketsperuser")
Skyler Grey11236ba2022-08-08 21:13:33 +010055 .setDescription("The maximum amount of tickets a user can create | Default: 5")
Skyler Grey75ea9172022-08-06 10:22:23 +010056 .setRequired(false)
57 .setMinValue(1)
58 )
59 .addRoleOption((option) =>
60 option
61 .setName("supportrole")
62 .setDescription(
63 "This role will have view access to all tickets and will be pinged when a ticket is created"
64 )
65 .setRequired(false)
66 );
pineafan4f164f32022-02-26 22:07:12 +000067
pineafan3a02ea32022-08-11 21:35:04 +010068const callback = async (interaction: CommandInteraction): Promise<unknown> => {
PineaFana00db1b2023-01-02 15:32:54 +000069 if (!interaction.guild) return;
Skyler Grey75ea9172022-08-06 10:22:23 +010070 let m = (await interaction.reply({
71 embeds: LoadingEmbed,
72 ephemeral: true,
73 fetchReply: true
74 })) as Message;
pineafan63fc5e22022-08-04 22:04:10 +010075 const options = {
TheCodedProfa16d1672023-01-18 18:58:34 -050076 enabled: (interaction.options.get("enabled")?.value as string).startsWith("yes") as boolean | null,
77 category: interaction.options.get("category")?.channel,
78 maxtickets: interaction.options.get("maxticketsperuser")?.value as number,
79 supportping: interaction.options.get("supportrole")?.role as Role
pineafan63fc5e22022-08-04 22:04:10 +010080 };
Skyler Grey11236ba2022-08-08 21:13:33 +010081 if (options.enabled !== null || options.category || options.maxtickets || options.supportping) {
pineafan6702cef2022-06-13 17:52:37 +010082 if (options.category) {
pineafan3a02ea32022-08-11 21:35:04 +010083 let channel: GuildChannel | null;
pineafan6702cef2022-06-13 17:52:37 +010084 try {
TheCodedProf59772f82023-01-18 22:17:16 -050085 channel = await interaction.guild.channels.fetch(options.category.id) as GuildChannel;
pineafan6702cef2022-06-13 17:52:37 +010086 } catch {
87 return await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +010088 embeds: [
89 new EmojiEmbed()
90 .setEmoji("CHANNEL.TEXT.DELETE")
91 .setTitle("Tickets > Category")
Skyler Grey11236ba2022-08-08 21:13:33 +010092 .setDescription("The channel you provided is not a valid category")
Skyler Grey75ea9172022-08-06 10:22:23 +010093 .setStatus("Danger")
pineafan6702cef2022-06-13 17:52:37 +010094 ]
pineafan63fc5e22022-08-04 22:04:10 +010095 });
pineafan6702cef2022-06-13 17:52:37 +010096 }
pineafan3a02ea32022-08-11 21:35:04 +010097 if (!channel) return;
pineafan63fc5e22022-08-04 22:04:10 +010098 channel = channel as Discord.CategoryChannel;
PineaFana00db1b2023-01-02 15:32:54 +000099 if (channel.guild.id !== interaction.guild.id)
Skyler Grey75ea9172022-08-06 10:22:23 +0100100 return interaction.editReply({
101 embeds: [
102 new EmojiEmbed()
103 .setTitle("Tickets > Category")
Skyler Grey11236ba2022-08-08 21:13:33 +0100104 .setDescription("You must choose a category in this server")
Skyler Grey75ea9172022-08-06 10:22:23 +0100105 .setStatus("Danger")
106 .setEmoji("CHANNEL.TEXT.DELETE")
107 ]
108 });
pineafan6702cef2022-06-13 17:52:37 +0100109 }
110 if (options.maxtickets) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100111 if (options.maxtickets < 1)
112 return interaction.editReply({
113 embeds: [
114 new EmojiEmbed()
115 .setTitle("Tickets > Max Tickets")
Skyler Grey11236ba2022-08-08 21:13:33 +0100116 .setDescription("You must choose a number greater than 0")
Skyler Grey75ea9172022-08-06 10:22:23 +0100117 .setStatus("Danger")
118 .setEmoji("CHANNEL.TEXT.DELETE")
119 ]
120 });
pineafan6702cef2022-06-13 17:52:37 +0100121 }
pineafan3a02ea32022-08-11 21:35:04 +0100122 let role: Role | null;
pineafan6702cef2022-06-13 17:52:37 +0100123 if (options.supportping) {
124 try {
PineaFana00db1b2023-01-02 15:32:54 +0000125 role = await interaction.guild.roles.fetch(options.supportping.id);
pineafan6702cef2022-06-13 17:52:37 +0100126 } catch {
127 return await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100128 embeds: [
129 new EmojiEmbed()
130 .setEmoji("GUILD.ROLE.DELETE")
131 .setTitle("Tickets > Support Ping")
Skyler Grey11236ba2022-08-08 21:13:33 +0100132 .setDescription("The role you provided is not a valid role")
Skyler Grey75ea9172022-08-06 10:22:23 +0100133 .setStatus("Danger")
pineafan6702cef2022-06-13 17:52:37 +0100134 ]
pineafan63fc5e22022-08-04 22:04:10 +0100135 });
pineafan6702cef2022-06-13 17:52:37 +0100136 }
pineafan3a02ea32022-08-11 21:35:04 +0100137 if (!role) return;
pineafan63fc5e22022-08-04 22:04:10 +0100138 role = role as Discord.Role;
PineaFana00db1b2023-01-02 15:32:54 +0000139 if (role.guild.id !== interaction.guild.id)
Skyler Grey75ea9172022-08-06 10:22:23 +0100140 return interaction.editReply({
141 embeds: [
142 new EmojiEmbed()
143 .setTitle("Tickets > Support Ping")
Skyler Grey11236ba2022-08-08 21:13:33 +0100144 .setDescription("You must choose a role in this server")
Skyler Grey75ea9172022-08-06 10:22:23 +0100145 .setStatus("Danger")
146 .setEmoji("GUILD.ROLE.DELETE")
147 ]
148 });
pineafan6702cef2022-06-13 17:52:37 +0100149 }
150
pineafan63fc5e22022-08-04 22:04:10 +0100151 const confirmation = await new confirmationMessage(interaction)
TheCodedProf59772f82023-01-18 22:17:16 -0500152 .setEmoji("GUILD.TICKET.ARCHIVED")
pineafan6702cef2022-06-13 17:52:37 +0100153 .setTitle("Tickets")
154 .setDescription(
Skyler Grey11236ba2022-08-08 21:13:33 +0100155 (options.category ? `**Category:** ${options.category.name}\n` : "") +
156 (options.maxtickets ? `**Max Tickets:** ${options.maxtickets}\n` : "") +
157 (options.supportping ? `**Support Ping:** ${options.supportping.name}\n` : "") +
Skyler Grey75ea9172022-08-06 10:22:23 +0100158 (options.enabled !== null
159 ? `**Enabled:** ${
pineafan62ce1922022-08-25 20:34:45 +0100160 options.enabled
161 ? `${getEmojiByName("CONTROL.TICK")} Yes`
162 : `${getEmojiByName("CONTROL.CROSS")} No`
163 }\n`
Skyler Grey75ea9172022-08-06 10:22:23 +0100164 : "") +
165 "\nAre you sure you want to apply these settings?"
pineafan6702cef2022-06-13 17:52:37 +0100166 )
167 .setColor("Warning")
TheCodedProf59772f82023-01-18 22:17:16 -0500168 .setFailedMessage("Cancelled", "Warning", "GUILD.TICKET.CLOSE") // TODO: Set Actual Message
pineafan6702cef2022-06-13 17:52:37 +0100169 .setInverted(true)
pineafan63fc5e22022-08-04 22:04:10 +0100170 .send(true);
171 if (confirmation.cancelled) return;
pineafan6702cef2022-06-13 17:52:37 +0100172 if (confirmation.success) {
pineafan3a02ea32022-08-11 21:35:04 +0100173 const toUpdate: Record<string, string | boolean | number> = {};
Skyler Grey11236ba2022-08-08 21:13:33 +0100174 if (options.enabled !== null) toUpdate["tickets.enabled"] = options.enabled;
175 if (options.category) toUpdate["tickets.category"] = options.category.id;
176 if (options.maxtickets) toUpdate["tickets.maxTickets"] = options.maxtickets;
177 if (options.supportping) toUpdate["tickets.supportRole"] = options.supportping.id;
pineafan6702cef2022-06-13 17:52:37 +0100178 try {
PineaFana00db1b2023-01-02 15:32:54 +0000179 await client.database.guilds.write(interaction.guild.id, toUpdate);
pineafan6702cef2022-06-13 17:52:37 +0100180 } catch (e) {
181 return interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100182 embeds: [
183 new EmojiEmbed()
184 .setTitle("Tickets")
Skyler Grey11236ba2022-08-08 21:13:33 +0100185 .setDescription("Something went wrong and the staff notifications channel could not be set")
Skyler Grey75ea9172022-08-06 10:22:23 +0100186 .setStatus("Danger")
187 .setEmoji("GUILD.TICKET.DELETE")
188 ],
189 components: []
pineafan6702cef2022-06-13 17:52:37 +0100190 });
191 }
192 } else {
193 return interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100194 embeds: [
195 new EmojiEmbed()
196 .setTitle("Tickets")
197 .setDescription("No changes were made")
198 .setStatus("Success")
199 .setEmoji("GUILD.TICKET.OPEN")
200 ],
201 components: []
pineafan6702cef2022-06-13 17:52:37 +0100202 });
203 }
204 }
PineaFana00db1b2023-01-02 15:32:54 +0000205 let data = await client.database.guilds.read(interaction.guild.id);
Skyler Grey75ea9172022-08-06 10:22:23 +0100206 data.tickets.customTypes = (data.tickets.customTypes || []).filter(
Skyler Grey11236ba2022-08-08 21:13:33 +0100207 (value: string, index: number, array: string[]) => array.indexOf(value) === index
Skyler Grey75ea9172022-08-06 10:22:23 +0100208 );
pineafan6702cef2022-06-13 17:52:37 +0100209 let lastClicked = "";
TheCodedProf59772f82023-01-18 22:17:16 -0500210 let embed: EmojiEmbed = new EmojiEmbed();
211 let compiledData = {
pineafan6702cef2022-06-13 17:52:37 +0100212 enabled: data.tickets.enabled,
213 category: data.tickets.category,
214 maxTickets: data.tickets.maxTickets,
215 supportRole: data.tickets.supportRole,
216 useCustom: data.tickets.useCustom,
217 types: data.tickets.types,
218 customTypes: data.tickets.customTypes
pineafan63fc5e22022-08-04 22:04:10 +0100219 };
Skyler Greyad002172022-08-16 18:48:26 +0100220 let timedOut = false;
221 while (!timedOut) {
TheCodedProf59772f82023-01-18 22:17:16 -0500222 embed
pineafan6702cef2022-06-13 17:52:37 +0100223 .setTitle("Tickets")
224 .setDescription(
TheCodedProf59772f82023-01-18 22:17:16 -0500225 `${compiledData.enabled ? "" : getEmojiByName("TICKETS.REPORT")} **Enabled:** ${
226 compiledData.enabled ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
Skyler Grey75ea9172022-08-06 10:22:23 +0100227 }\n` +
TheCodedProf59772f82023-01-18 22:17:16 -0500228 `${compiledData.category ? "" : getEmojiByName("TICKETS.REPORT")} **Category:** ${
229 compiledData.category ? `<#${compiledData.category}>` : "*None set*"
Skyler Grey75ea9172022-08-06 10:22:23 +0100230 }\n` +
TheCodedProf59772f82023-01-18 22:17:16 -0500231 `**Max Tickets:** ${compiledData.maxTickets ? compiledData.maxTickets : "*No limit*"}\n` +
232 `**Support Ping:** ${compiledData.supportRole ? `<@&${compiledData.supportRole}>` : "*None set*"}\n\n` +
233 (compiledData.useCustom && compiledData.customTypes === null ? `${getEmojiByName("TICKETS.REPORT")} ` : "") +
234 `${compiledData.useCustom ? "Custom" : "Default"} types in use` +
Skyler Grey75ea9172022-08-06 10:22:23 +0100235 "\n\n" +
Skyler Grey11236ba2022-08-08 21:13:33 +0100236 `${getEmojiByName("TICKETS.REPORT")} *Indicates a setting stopping tickets from being used*`
pineafan6702cef2022-06-13 17:52:37 +0100237 )
238 .setStatus("Success")
pineafan63fc5e22022-08-04 22:04:10 +0100239 .setEmoji("GUILD.TICKET.OPEN");
Skyler Grey75ea9172022-08-06 10:22:23 +0100240 m = (await interaction.editReply({
241 embeds: [embed],
242 components: [
TheCodedProf59772f82023-01-18 22:17:16 -0500243 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400244 new ButtonBuilder()
TheCodedProf59772f82023-01-18 22:17:16 -0500245 .setLabel("Tickets " + (compiledData.enabled ? "enabled" : "disabled"))
246 .setEmoji(getEmojiByName("CONTROL." + (compiledData.enabled ? "TICK" : "CROSS"), "id"))
247 .setStyle(compiledData.enabled ? ButtonStyle.Success : ButtonStyle.Danger)
Skyler Grey75ea9172022-08-06 10:22:23 +0100248 .setCustomId("enabled"),
TheCodedProf21c08592022-09-13 14:14:43 -0400249 new ButtonBuilder()
Skyler Grey11236ba2022-08-08 21:13:33 +0100250 .setLabel(lastClicked === "cat" ? "Click again to confirm" : "Clear category")
Skyler Grey75ea9172022-08-06 10:22:23 +0100251 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400252 .setStyle(ButtonStyle.Danger)
Skyler Grey75ea9172022-08-06 10:22:23 +0100253 .setCustomId("clearCategory")
TheCodedProf59772f82023-01-18 22:17:16 -0500254 .setDisabled(compiledData.category === null),
TheCodedProf21c08592022-09-13 14:14:43 -0400255 new ButtonBuilder()
Skyler Grey11236ba2022-08-08 21:13:33 +0100256 .setLabel(lastClicked === "max" ? "Click again to confirm" : "Reset max tickets")
Skyler Grey75ea9172022-08-06 10:22:23 +0100257 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400258 .setStyle(ButtonStyle.Danger)
Skyler Grey75ea9172022-08-06 10:22:23 +0100259 .setCustomId("clearMaxTickets")
TheCodedProf59772f82023-01-18 22:17:16 -0500260 .setDisabled(compiledData.maxTickets === 5),
TheCodedProf21c08592022-09-13 14:14:43 -0400261 new ButtonBuilder()
Skyler Grey11236ba2022-08-08 21:13:33 +0100262 .setLabel(lastClicked === "sup" ? "Click again to confirm" : "Clear support ping")
Skyler Grey75ea9172022-08-06 10:22:23 +0100263 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400264 .setStyle(ButtonStyle.Danger)
Skyler Grey75ea9172022-08-06 10:22:23 +0100265 .setCustomId("clearSupportPing")
TheCodedProf59772f82023-01-18 22:17:16 -0500266 .setDisabled(compiledData.supportRole === null)
Skyler Grey75ea9172022-08-06 10:22:23 +0100267 ]),
TheCodedProf59772f82023-01-18 22:17:16 -0500268 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400269 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100270 .setLabel("Manage types")
271 .setEmoji(getEmojiByName("TICKETS.OTHER", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400272 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100273 .setCustomId("manageTypes"),
TheCodedProf21c08592022-09-13 14:14:43 -0400274 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100275 .setLabel("Add create ticket button")
276 .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400277 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100278 .setCustomId("send")
279 ])
280 ]
281 })) as Message;
Skyler Grey1a67e182022-08-04 23:05:44 +0100282 let i: MessageComponentInteraction;
pineafan6702cef2022-06-13 17:52:37 +0100283 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000284 i = await m.awaitMessageComponent({
285 time: 300000,
286 filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id }
287 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100288 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100289 timedOut = true;
290 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100291 }
pineafan63fc5e22022-08-04 22:04:10 +0100292 i.deferUpdate();
TheCodedProf59772f82023-01-18 22:17:16 -0500293 if ((i.component as ButtonComponent).customId === "clearCategory") {
pineafane23c4ec2022-07-27 21:56:27 +0100294 if (lastClicked === "cat") {
pineafan6702cef2022-06-13 17:52:37 +0100295 lastClicked = "";
PineaFana00db1b2023-01-02 15:32:54 +0000296 await client.database.guilds.write(interaction.guild.id, null, ["tickets.category"]);
TheCodedProf59772f82023-01-18 22:17:16 -0500297 compiledData.category = null;
pineafan6702cef2022-06-13 17:52:37 +0100298 } else lastClicked = "cat";
TheCodedProf59772f82023-01-18 22:17:16 -0500299 } else if ((i.component as ButtonComponent).customId === "clearMaxTickets") {
pineafane23c4ec2022-07-27 21:56:27 +0100300 if (lastClicked === "max") {
pineafan6702cef2022-06-13 17:52:37 +0100301 lastClicked = "";
PineaFana00db1b2023-01-02 15:32:54 +0000302 await client.database.guilds.write(interaction.guild.id, null, ["tickets.maxTickets"]);
TheCodedProf59772f82023-01-18 22:17:16 -0500303 compiledData.maxTickets = 5;
pineafan6702cef2022-06-13 17:52:37 +0100304 } else lastClicked = "max";
TheCodedProf59772f82023-01-18 22:17:16 -0500305 } else if ((i.component as ButtonComponent).customId === "clearSupportPing") {
pineafane23c4ec2022-07-27 21:56:27 +0100306 if (lastClicked === "sup") {
pineafan6702cef2022-06-13 17:52:37 +0100307 lastClicked = "";
PineaFana00db1b2023-01-02 15:32:54 +0000308 await client.database.guilds.write(interaction.guild.id, null, ["tickets.supportRole"]);
TheCodedProf59772f82023-01-18 22:17:16 -0500309 compiledData.supportRole = null;
pineafan6702cef2022-06-13 17:52:37 +0100310 } else lastClicked = "sup";
TheCodedProf59772f82023-01-18 22:17:16 -0500311 } else if ((i.component as ButtonComponent).customId === "send") {
pineafan41d93562022-07-30 22:10:15 +0100312 const ticketMessages = [
Skyler Grey75ea9172022-08-06 10:22:23 +0100313 {
314 label: "Create ticket",
315 description: "Click the button below to create a ticket"
316 },
317 {
318 label: "Issues, questions or feedback?",
Skyler Grey11236ba2022-08-08 21:13:33 +0100319 description: "Click below to open a ticket and get help from our staff team"
Skyler Grey75ea9172022-08-06 10:22:23 +0100320 },
321 {
322 label: "Contact Us",
Skyler Grey11236ba2022-08-08 21:13:33 +0100323 description: "Click the button below to speak to us privately"
Skyler Grey75ea9172022-08-06 10:22:23 +0100324 }
pineafan63fc5e22022-08-04 22:04:10 +0100325 ];
Skyler Greyad002172022-08-16 18:48:26 +0100326 let innerTimedOut = false;
327 let templateSelected = false;
328 while (!innerTimedOut && !templateSelected) {
TheCodedProf59772f82023-01-18 22:17:16 -0500329 const enabled = compiledData.enabled && compiledData.category !== null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100330 await interaction.editReply({
331 embeds: [
332 new EmojiEmbed()
333 .setTitle("Ticket Button")
Skyler Grey11236ba2022-08-08 21:13:33 +0100334 .setDescription("Select a message template to send in this channel")
Skyler Grey75ea9172022-08-06 10:22:23 +0100335 .setFooter({
336 text: enabled
337 ? ""
338 : "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."
339 })
340 .setStatus(enabled ? "Success" : "Warning")
341 .setEmoji("GUILD.ROLES.CREATE")
342 ],
343 components: [
TheCodedProf59772f82023-01-18 22:17:16 -0500344 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
TheCodedProfa16d1672023-01-18 18:58:34 -0500345 new StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100346 .setOptions(
347 ticketMessages.map(
348 (
349 t: {
350 label: string;
351 description: string;
352 value?: string;
353 },
354 index
355 ) => {
356 t.value = index.toString();
357 return t as {
358 value: string;
359 label: string;
360 description: string;
361 };
362 }
363 )
364 )
365 .setCustomId("template")
366 .setMaxValues(1)
367 .setMinValues(1)
368 .setPlaceholder("Select a message template")
369 ]),
TheCodedProf59772f82023-01-18 22:17:16 -0500370 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400371 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100372 .setCustomId("back")
373 .setLabel("Back")
374 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400375 .setStyle(ButtonStyle.Danger),
376 new ButtonBuilder().setCustomId("blank").setLabel("Empty").setStyle(ButtonStyle.Secondary),
377 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100378 .setCustomId("custom")
379 .setLabel("Custom")
380 .setEmoji(getEmojiByName("TICKETS.OTHER", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400381 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100382 ])
383 ]
384 });
Skyler Grey1a67e182022-08-04 23:05:44 +0100385 let i: MessageComponentInteraction;
pineafan41d93562022-07-30 22:10:15 +0100386 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000387 i = await m.awaitMessageComponent({
388 time: 300000,
389 filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id }
390 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100391 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100392 innerTimedOut = true;
393 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100394 }
TheCodedProf59772f82023-01-18 22:17:16 -0500395 if ((i.component as StringSelectMenuComponent).customId === "template") {
pineafan63fc5e22022-08-04 22:04:10 +0100396 i.deferUpdate();
pineafan3a02ea32022-08-11 21:35:04 +0100397 await interaction.channel!.send({
Skyler Grey75ea9172022-08-06 10:22:23 +0100398 embeds: [
399 new EmojiEmbed()
TheCodedProfa16d1672023-01-18 18:58:34 -0500400 .setTitle(ticketMessages[parseInt((i as StringSelectMenuInteraction).values[0]!)]!.label)
Skyler Grey75ea9172022-08-06 10:22:23 +0100401 .setDescription(
TheCodedProfa16d1672023-01-18 18:58:34 -0500402 ticketMessages[parseInt((i as StringSelectMenuInteraction).values[0]!)]!.description
Skyler Grey75ea9172022-08-06 10:22:23 +0100403 )
404 .setStatus("Success")
405 .setEmoji("GUILD.TICKET.OPEN")
406 ],
407 components: [
TheCodedProf59772f82023-01-18 22:17:16 -0500408 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400409 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100410 .setLabel("Create Ticket")
Skyler Grey11236ba2022-08-08 21:13:33 +0100411 .setEmoji(getEmojiByName("CONTROL.TICK", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400412 .setStyle(ButtonStyle.Success)
Skyler Grey75ea9172022-08-06 10:22:23 +0100413 .setCustomId("createticket")
414 ])
415 ]
416 });
Skyler Greyad002172022-08-16 18:48:26 +0100417 templateSelected = true;
418 continue;
TheCodedProf59772f82023-01-18 22:17:16 -0500419 } else if ((i.component as ButtonComponent).customId === "blank") {
Skyler Grey75ea9172022-08-06 10:22:23 +0100420 i.deferUpdate();
pineafan3a02ea32022-08-11 21:35:04 +0100421 await interaction.channel!.send({
Skyler Grey75ea9172022-08-06 10:22:23 +0100422 components: [
TheCodedProf59772f82023-01-18 22:17:16 -0500423 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400424 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100425 .setLabel("Create Ticket")
Skyler Grey11236ba2022-08-08 21:13:33 +0100426 .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400427 .setStyle(ButtonStyle.Success)
Skyler Grey75ea9172022-08-06 10:22:23 +0100428 .setCustomId("createticket")
429 ])
430 ]
431 });
Skyler Greyad002172022-08-16 18:48:26 +0100432 templateSelected = true;
433 continue;
TheCodedProf59772f82023-01-18 22:17:16 -0500434 } else if ((i.component as ButtonComponent).customId === "custom") {
Skyler Grey75ea9172022-08-06 10:22:23 +0100435 await i.showModal(
TheCodedProf59772f82023-01-18 22:17:16 -0500436 new Discord.ModalBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100437 .setCustomId("modal")
438 .setTitle("Enter embed details")
439 .addComponents(
TheCodedProf59772f82023-01-18 22:17:16 -0500440 new ActionRowBuilder<TextInputBuilder>().addComponents(
441 new TextInputBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100442 .setCustomId("title")
443 .setLabel("Title")
444 .setMaxLength(256)
445 .setRequired(true)
TheCodedProf59772f82023-01-18 22:17:16 -0500446 .setStyle(Discord.TextInputStyle.Short)
Skyler Grey75ea9172022-08-06 10:22:23 +0100447 ),
TheCodedProf59772f82023-01-18 22:17:16 -0500448 new ActionRowBuilder<TextInputBuilder>().addComponents(
449 new TextInputBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100450 .setCustomId("description")
451 .setLabel("Description")
452 .setMaxLength(4000)
453 .setRequired(true)
TheCodedProf59772f82023-01-18 22:17:16 -0500454 .setStyle(Discord.TextInputStyle.Paragraph)
Skyler Grey75ea9172022-08-06 10:22:23 +0100455 )
456 )
457 );
pineafan41d93562022-07-30 22:10:15 +0100458 await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100459 embeds: [
460 new EmojiEmbed()
461 .setTitle("Ticket Button")
Skyler Grey11236ba2022-08-08 21:13:33 +0100462 .setDescription("Modal opened. If you can't see it, click back and try again.")
Skyler Grey75ea9172022-08-06 10:22:23 +0100463 .setStatus("Success")
464 .setEmoji("GUILD.TICKET.OPEN")
465 ],
466 components: [
TheCodedProf59772f82023-01-18 22:17:16 -0500467 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400468 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100469 .setLabel("Back")
Skyler Grey11236ba2022-08-08 21:13:33 +0100470 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400471 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100472 .setCustomId("back")
473 ])
474 ]
pineafan41d93562022-07-30 22:10:15 +0100475 });
476 let out;
477 try {
Skyler Grey75ea9172022-08-06 10:22:23 +0100478 out = await modalInteractionCollector(
479 m,
pineafan3a02ea32022-08-11 21:35:04 +0100480 (m) => m.channel!.id === interaction.channel!.id,
Skyler Grey75ea9172022-08-06 10:22:23 +0100481 (m) => m.customId === "modify"
482 );
483 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100484 innerTimedOut = true;
485 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100486 }
TheCodedProf59772f82023-01-18 22:17:16 -0500487 out = out as ModalSubmitInteraction;
pineafan41d93562022-07-30 22:10:15 +0100488 if (out.fields) {
pineafan63fc5e22022-08-04 22:04:10 +0100489 const title = out.fields.getTextInputValue("title");
Skyler Grey11236ba2022-08-08 21:13:33 +0100490 const description = out.fields.getTextInputValue("description");
TheCodedProf59772f82023-01-18 22:17:16 -0500491 await interaction.channel!.send({
Skyler Grey75ea9172022-08-06 10:22:23 +0100492 embeds: [
493 new EmojiEmbed()
494 .setTitle(title)
495 .setDescription(description)
496 .setStatus("Success")
497 .setEmoji("GUILD.TICKET.OPEN")
498 ],
499 components: [
TheCodedProf59772f82023-01-18 22:17:16 -0500500 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400501 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100502 .setLabel("Create Ticket")
Skyler Grey11236ba2022-08-08 21:13:33 +0100503 .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400504 .setStyle(ButtonStyle.Success)
Skyler Grey75ea9172022-08-06 10:22:23 +0100505 .setCustomId("createticket")
506 ])
507 ]
508 });
Skyler Greyad002172022-08-16 18:48:26 +0100509 templateSelected = true;
Skyler Grey75ea9172022-08-06 10:22:23 +0100510 }
pineafan41d93562022-07-30 22:10:15 +0100511 }
512 }
TheCodedProf59772f82023-01-18 22:17:16 -0500513 } else if ((i.component as ButtonComponent).customId === "enabled") {
Skyler Grey75ea9172022-08-06 10:22:23 +0100514 await client.database.guilds.write(interaction.guild.id, {
TheCodedProf59772f82023-01-18 22:17:16 -0500515 "tickets.enabled": !compiledData.enabled
Skyler Grey75ea9172022-08-06 10:22:23 +0100516 });
TheCodedProf59772f82023-01-18 22:17:16 -0500517 compiledData.enabled = !compiledData.enabled;
518 } else if ((i.component as ButtonComponent).customId === "manageTypes") {
519 data = await manageTypes(interaction, data, m as Message); //TODO: Fix this
pineafan6702cef2022-06-13 17:52:37 +0100520 }
521 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100522 await interaction.editReply({
TheCodedProf59772f82023-01-18 22:17:16 -0500523 embeds: [ embed.setFooter({ text: "Message timed out" })],
Skyler Grey75ea9172022-08-06 10:22:23 +0100524 components: []
525 });
pineafan63fc5e22022-08-04 22:04:10 +0100526};
pineafan4f164f32022-02-26 22:07:12 +0000527
Skyler Grey11236ba2022-08-08 21:13:33 +0100528async function manageTypes(interaction: CommandInteraction, data: GuildConfig["tickets"], m: Message) {
Skyler Greyad002172022-08-16 18:48:26 +0100529 let timedOut = false;
530 let backPressed = false;
531 while (!timedOut && !backPressed) {
pineafan6702cef2022-06-13 17:52:37 +0100532 if (data.useCustom) {
pineafan63fc5e22022-08-04 22:04:10 +0100533 const customTypes = data.customTypes;
pineafanc6158ab2022-06-17 16:34:07 +0100534 await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100535 embeds: [
536 new EmojiEmbed()
537 .setTitle("Tickets > Types")
538 .setDescription(
539 "**Custom types enabled**\n\n" +
540 "**Types in use:**\n" +
Skyler Grey11236ba2022-08-08 21:13:33 +0100541 (customTypes !== null ? customTypes.map((t) => `> ${t}`).join("\n") : "*None set*") +
Skyler Grey75ea9172022-08-06 10:22:23 +0100542 "\n\n" +
543 (customTypes === null
544 ? `${getEmojiByName(
545 "TICKETS.REPORT"
546 )} Having no types will disable tickets. Please add at least 1 type or use default types`
547 : "")
pineafan6702cef2022-06-13 17:52:37 +0100548 )
Skyler Grey75ea9172022-08-06 10:22:23 +0100549 .setStatus("Success")
550 .setEmoji("GUILD.TICKET.OPEN")
551 ],
552 components: (customTypes
553 ? [
TheCodedProf59772f82023-01-18 22:17:16 -0500554 new ActionRowBuilder<StringSelectMenuBuilder | ButtonBuilder>().addComponents([
TheCodedProfa16d1672023-01-18 18:58:34 -0500555 new Discord.StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100556 .setCustomId("removeTypes")
557 .setPlaceholder("Select types to remove")
558 .setMaxValues(customTypes.length)
559 .setMinValues(1)
560 .addOptions(
561 customTypes.map((t) => ({
562 label: t,
563 value: t
564 }))
565 )
566 ])
567 ]
568 : []
569 ).concat([
TheCodedProf59772f82023-01-18 22:17:16 -0500570 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400571 new ButtonBuilder()
pineafan6702cef2022-06-13 17:52:37 +0100572 .setLabel("Back")
573 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400574 .setStyle(ButtonStyle.Primary)
pineafan6702cef2022-06-13 17:52:37 +0100575 .setCustomId("back"),
TheCodedProf21c08592022-09-13 14:14:43 -0400576 new ButtonBuilder()
pineafan6702cef2022-06-13 17:52:37 +0100577 .setLabel("Add new type")
Skyler Grey11236ba2022-08-08 21:13:33 +0100578 .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400579 .setStyle(ButtonStyle.Primary)
pineafan6702cef2022-06-13 17:52:37 +0100580 .setCustomId("addType")
Skyler Grey11236ba2022-08-08 21:13:33 +0100581 .setDisabled(customTypes !== null && customTypes.length >= 25),
TheCodedProf21c08592022-09-13 14:14:43 -0400582 new ButtonBuilder()
pineafan6702cef2022-06-13 17:52:37 +0100583 .setLabel("Switch to default types")
TheCodedProf21c08592022-09-13 14:14:43 -0400584 .setStyle(ButtonStyle.Secondary)
pineafan63fc5e22022-08-04 22:04:10 +0100585 .setCustomId("switchToDefault")
pineafan6702cef2022-06-13 17:52:37 +0100586 ])
587 ])
588 });
589 } else {
pineafan63fc5e22022-08-04 22:04:10 +0100590 const inUse = toHexArray(data.types, ticketTypes);
TheCodedProf59772f82023-01-18 22:17:16 -0500591 const options: StringSelectMenuOptionBuilder[] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +0100592 ticketTypes.forEach((type) => {
593 options.push(
TheCodedProf59772f82023-01-18 22:17:16 -0500594 new StringSelectMenuOptionBuilder({
Skyler Grey75ea9172022-08-06 10:22:23 +0100595 label: capitalize(type),
596 value: type,
TheCodedProf59772f82023-01-18 22:17:16 -0500597 emoji: client.emojis.cache.get(getEmojiByName(`TICKETS.${type.toUpperCase()}`, "id")) as APIMessageComponentEmoji,
Skyler Grey75ea9172022-08-06 10:22:23 +0100598 default: inUse.includes(type)
599 })
600 );
pineafan63fc5e22022-08-04 22:04:10 +0100601 });
TheCodedProf59772f82023-01-18 22:17:16 -0500602 const selectPane = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
TheCodedProfa16d1672023-01-18 18:58:34 -0500603 new Discord.StringSelectMenuBuilder()
pineafan6702cef2022-06-13 17:52:37 +0100604 .addOptions(options)
605 .setCustomId("types")
606 .setMaxValues(ticketTypes.length)
607 .setMinValues(1)
608 .setPlaceholder("Select types to use")
pineafan63fc5e22022-08-04 22:04:10 +0100609 ]);
pineafanc6158ab2022-06-17 16:34:07 +0100610 await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100611 embeds: [
612 new EmojiEmbed()
613 .setTitle("Tickets > Types")
614 .setDescription(
615 "**Default types enabled**\n\n" +
616 "**Types in use:**\n" +
617 inUse
Skyler Grey11236ba2022-08-08 21:13:33 +0100618 .map((t) => `> ${getEmojiByName("TICKETS." + t.toUpperCase())} ${capitalize(t)}`)
Skyler Grey75ea9172022-08-06 10:22:23 +0100619 .join("\n")
620 )
621 .setStatus("Success")
622 .setEmoji("GUILD.TICKET.OPEN")
623 ],
624 components: [
pineafan6702cef2022-06-13 17:52:37 +0100625 selectPane,
TheCodedProf59772f82023-01-18 22:17:16 -0500626 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400627 new ButtonBuilder()
pineafan6702cef2022-06-13 17:52:37 +0100628 .setLabel("Back")
629 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400630 .setStyle(ButtonStyle.Primary)
pineafan6702cef2022-06-13 17:52:37 +0100631 .setCustomId("back"),
TheCodedProf21c08592022-09-13 14:14:43 -0400632 new ButtonBuilder()
pineafan6702cef2022-06-13 17:52:37 +0100633 .setLabel("Switch to custom types")
TheCodedProf21c08592022-09-13 14:14:43 -0400634 .setStyle(ButtonStyle.Secondary)
pineafan63fc5e22022-08-04 22:04:10 +0100635 .setCustomId("switchToCustom")
pineafan6702cef2022-06-13 17:52:37 +0100636 ])
637 ]
638 });
639 }
640 let i;
641 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000642 i = await m.awaitMessageComponent({
643 time: 300000,
644 filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id }
645 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100646 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100647 timedOut = true;
648 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100649 }
TheCodedProf59772f82023-01-18 22:17:16 -0500650 if ((i.component as StringSelectMenuComponent).customId === "types") {
pineafan63fc5e22022-08-04 22:04:10 +0100651 i.deferUpdate();
TheCodedProf59772f82023-01-18 22:17:16 -0500652 const types = toHexInteger((i as StringSelectMenuInteraction).values, ticketTypes);
653 await client.database.guilds.write(interaction.guild!.id, {
Skyler Grey75ea9172022-08-06 10:22:23 +0100654 "tickets.types": types
655 });
pineafan6702cef2022-06-13 17:52:37 +0100656 data.types = types;
TheCodedProf59772f82023-01-18 22:17:16 -0500657 } else if ((i.component as StringSelectMenuComponent).customId === "removeTypes") {
pineafan63fc5e22022-08-04 22:04:10 +0100658 i.deferUpdate();
TheCodedProf59772f82023-01-18 22:17:16 -0500659 const types = (i as StringSelectMenuInteraction).values;
pineafan6702cef2022-06-13 17:52:37 +0100660 let customTypes = data.customTypes;
661 if (customTypes) {
662 customTypes = customTypes.filter((t) => !types.includes(t));
663 customTypes = customTypes.length > 0 ? customTypes : null;
TheCodedProf59772f82023-01-18 22:17:16 -0500664 await client.database.guilds.write(interaction.guild!.id, {
Skyler Grey75ea9172022-08-06 10:22:23 +0100665 "tickets.customTypes": customTypes
666 });
pineafan6702cef2022-06-13 17:52:37 +0100667 data.customTypes = customTypes;
668 }
TheCodedProf59772f82023-01-18 22:17:16 -0500669 } else if ((i.component as ButtonComponent).customId === "addType") {
Skyler Grey75ea9172022-08-06 10:22:23 +0100670 await i.showModal(
TheCodedProf59772f82023-01-18 22:17:16 -0500671 new Discord.ModalBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100672 .setCustomId("modal")
673 .setTitle("Enter a name for the new type")
674 .addComponents(
TheCodedProf59772f82023-01-18 22:17:16 -0500675 new ActionRowBuilder<TextInputBuilder>().addComponents(
676 new TextInputBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100677 .setCustomId("type")
678 .setLabel("Name")
679 .setMaxLength(100)
680 .setMinLength(1)
681 .setPlaceholder('E.g. "Server Idea"')
682 .setRequired(true)
TheCodedProf59772f82023-01-18 22:17:16 -0500683 .setStyle(Discord.TextInputStyle.Short)
Skyler Grey75ea9172022-08-06 10:22:23 +0100684 )
685 )
686 );
pineafan6702cef2022-06-13 17:52:37 +0100687 await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100688 embeds: [
689 new EmojiEmbed()
690 .setTitle("Tickets > Types")
Skyler Grey11236ba2022-08-08 21:13:33 +0100691 .setDescription("Modal opened. If you can't see it, click back and try again.")
Skyler Grey75ea9172022-08-06 10:22:23 +0100692 .setStatus("Success")
693 .setEmoji("GUILD.TICKET.OPEN")
694 ],
695 components: [
TheCodedProf59772f82023-01-18 22:17:16 -0500696 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400697 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100698 .setLabel("Back")
699 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400700 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100701 .setCustomId("back")
702 ])
703 ]
pineafan6702cef2022-06-13 17:52:37 +0100704 });
pineafan4edb7762022-06-26 19:21:04 +0100705 let out;
pineafan6702cef2022-06-13 17:52:37 +0100706 try {
Skyler Grey75ea9172022-08-06 10:22:23 +0100707 out = await modalInteractionCollector(
708 m,
TheCodedProf59772f82023-01-18 22:17:16 -0500709 (m) => m.channel!.id === interaction.channel!.id,
Skyler Grey75ea9172022-08-06 10:22:23 +0100710 (m) => m.customId === "addType"
711 );
712 } catch (e) {
713 continue;
714 }
TheCodedProf59772f82023-01-18 22:17:16 -0500715 out = out as ModalSubmitInteraction;
pineafan6702cef2022-06-13 17:52:37 +0100716 if (out.fields) {
717 let toAdd = out.fields.getTextInputValue("type");
Skyler Grey75ea9172022-08-06 10:22:23 +0100718 if (!toAdd) {
719 continue;
720 }
pineafan63fc5e22022-08-04 22:04:10 +0100721 toAdd = toAdd.substring(0, 80);
pineafan6702cef2022-06-13 17:52:37 +0100722 try {
TheCodedProf59772f82023-01-18 22:17:16 -0500723 await client.database.guilds.append(interaction.guild!.id, "tickets.customTypes", toAdd);
Skyler Grey75ea9172022-08-06 10:22:23 +0100724 } catch {
725 continue;
726 }
Skyler Greyad002172022-08-16 18:48:26 +0100727 data.customTypes = data.customTypes ?? [];
pineafan6702cef2022-06-13 17:52:37 +0100728 if (!data.customTypes.includes(toAdd)) {
729 data.customTypes.push(toAdd);
730 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100731 } else {
732 continue;
733 }
TheCodedProf59772f82023-01-18 22:17:16 -0500734 } else if ((i.component as ButtonComponent).customId === "switchToDefault") {
pineafan63fc5e22022-08-04 22:04:10 +0100735 i.deferUpdate();
TheCodedProf59772f82023-01-18 22:17:16 -0500736 await client.database.guilds.write(interaction.guild!.id, { "tickets.useCustom": false }, []);
pineafan6702cef2022-06-13 17:52:37 +0100737 data.useCustom = false;
TheCodedProf59772f82023-01-18 22:17:16 -0500738 } else if ((i.component as ButtonComponent).customId === "switchToCustom") {
pineafan63fc5e22022-08-04 22:04:10 +0100739 i.deferUpdate();
TheCodedProf59772f82023-01-18 22:17:16 -0500740 await client.database.guilds.write(interaction.guild!.id, { "tickets.useCustom": true }, []);
pineafan6702cef2022-06-13 17:52:37 +0100741 data.useCustom = true;
742 } else {
pineafan63fc5e22022-08-04 22:04:10 +0100743 i.deferUpdate();
Skyler Greyad002172022-08-16 18:48:26 +0100744 backPressed = true;
pineafan6702cef2022-06-13 17:52:37 +0100745 }
746 }
pineafan63fc5e22022-08-04 22:04:10 +0100747 return data;
pineafan6702cef2022-06-13 17:52:37 +0100748}
749
Skyler Grey1a67e182022-08-04 23:05:44 +0100750const check = (interaction: CommandInteraction) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100751 const member = interaction.member as Discord.GuildMember;
PineaFana00db1b2023-01-02 15:32:54 +0000752 if (!member.permissions.has("ManageGuild"))
PineaFan0d06edc2023-01-17 22:10:31 +0000753 return "You must have the *Manage Server* permission to use this command";
pineafan6702cef2022-06-13 17:52:37 +0100754 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100755};
pineafan4f164f32022-02-26 22:07:12 +0000756
757export { command };
758export { callback };
Skyler Grey1a67e182022-08-04 23:05:44 +0100759export { check };