Bug fixes and ~~performance~~ typing improvements
diff --git a/src/commands/settings/tickets.ts b/src/commands/settings/tickets.ts
index 206e157..3c6515d 100644
--- a/src/commands/settings/tickets.ts
+++ b/src/commands/settings/tickets.ts
@@ -15,17 +15,10 @@
SelectMenuInteraction,
TextInputComponent
} from "discord.js";
-import {
- SelectMenuOption,
- SlashCommandSubcommandBuilder
-} from "@discordjs/builders";
+import { SelectMenuOption, SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { ChannelType } from "discord-api-types/v9";
import client from "../../utils/client.js";
-import {
- toHexInteger,
- toHexArray,
- tickets as ticketTypes
-} from "../../utils/calculate.js";
+import { toHexInteger, toHexArray, tickets as ticketTypes } from "../../utils/calculate.js";
import { capitalize } from "../../utils/generateKeyValueList.js";
import { modalInteractionCollector } from "../../utils/dualCollector.js";
import { GuildConfig } from "../../utils/database.js";
@@ -33,9 +26,7 @@
const command = (builder: SlashCommandSubcommandBuilder) =>
builder
.setName("tickets")
- .setDescription(
- "Shows settings for tickets | Use no arguments to manage custom types"
- )
+ .setDescription("Shows settings for tickets | Use no arguments to manage custom types")
.addStringOption((option) =>
option
.setName("enabled")
@@ -56,9 +47,7 @@
.addNumberOption((option) =>
option
.setName("maxticketsperuser")
- .setDescription(
- "The maximum amount of tickets a user can create | Default: 5"
- )
+ .setDescription("The maximum amount of tickets a user can create | Default: 5")
.setRequired(false)
.setMinValue(1)
)
@@ -71,9 +60,7 @@
.setRequired(false)
);
-const callback = async (
- interaction: CommandInteraction
-): Promise<void | unknown> => {
+const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
let m = (await interaction.reply({
embeds: LoadingEmbed,
ephemeral: true,
@@ -85,28 +72,19 @@
maxtickets: interaction.options.getNumber("maxticketsperuser"),
supportping: interaction.options.getRole("supportrole")
};
- if (
- options.enabled !== null ||
- options.category ||
- options.maxtickets ||
- options.supportping
- ) {
+ if (options.enabled !== null || options.category || options.maxtickets || options.supportping) {
options.enabled = options.enabled === "yes" ? true : false;
if (options.category) {
let channel: GuildChannel;
try {
- channel = await interaction.guild.channels.fetch(
- options.category.id
- );
+ channel = await interaction.guild.channels.fetch(options.category.id);
} catch {
return await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("CHANNEL.TEXT.DELETE")
.setTitle("Tickets > Category")
- .setDescription(
- "The channel you provided is not a valid category"
- )
+ .setDescription("The channel you provided is not a valid category")
.setStatus("Danger")
]
});
@@ -117,9 +95,7 @@
embeds: [
new EmojiEmbed()
.setTitle("Tickets > Category")
- .setDescription(
- "You must choose a category in this server"
- )
+ .setDescription("You must choose a category in this server")
.setStatus("Danger")
.setEmoji("CHANNEL.TEXT.DELETE")
]
@@ -131,9 +107,7 @@
embeds: [
new EmojiEmbed()
.setTitle("Tickets > Max Tickets")
- .setDescription(
- "You must choose a number greater than 0"
- )
+ .setDescription("You must choose a number greater than 0")
.setStatus("Danger")
.setEmoji("CHANNEL.TEXT.DELETE")
]
@@ -142,18 +116,14 @@
let role: Role;
if (options.supportping) {
try {
- role = await interaction.guild.roles.fetch(
- options.supportping.id
- );
+ role = await interaction.guild.roles.fetch(options.supportping.id);
} catch {
return await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("GUILD.ROLE.DELETE")
.setTitle("Tickets > Support Ping")
- .setDescription(
- "The role you provided is not a valid role"
- )
+ .setDescription("The role you provided is not a valid role")
.setStatus("Danger")
]
});
@@ -164,9 +134,7 @@
embeds: [
new EmojiEmbed()
.setTitle("Tickets > Support Ping")
- .setDescription(
- "You must choose a role in this server"
- )
+ .setDescription("You must choose a role in this server")
.setStatus("Danger")
.setEmoji("GUILD.ROLE.DELETE")
]
@@ -177,15 +145,9 @@
.setEmoji("GUILD.TICKET.ARCHIVED")
.setTitle("Tickets")
.setDescription(
- (options.category
- ? `**Category:** ${options.category.name}\n`
- : "") +
- (options.maxtickets
- ? `**Max Tickets:** ${options.maxtickets}\n`
- : "") +
- (options.supportping
- ? `**Support Ping:** ${options.supportping.name}\n`
- : "") +
+ (options.category ? `**Category:** ${options.category.name}\n` : "") +
+ (options.maxtickets ? `**Max Tickets:** ${options.maxtickets}\n` : "") +
+ (options.supportping ? `**Support Ping:** ${options.supportping.name}\n` : "") +
(options.enabled !== null
? `**Enabled:** ${
options.enabled
@@ -201,27 +163,18 @@
if (confirmation.cancelled) return;
if (confirmation.success) {
const toUpdate = {};
- if (options.enabled !== null)
- toUpdate["tickets.enabled"] = options.enabled;
- if (options.category)
- toUpdate["tickets.category"] = options.category.id;
- if (options.maxtickets)
- toUpdate["tickets.maxTickets"] = options.maxtickets;
- if (options.supportping)
- toUpdate["tickets.supportRole"] = options.supportping.id;
+ if (options.enabled !== null) toUpdate["tickets.enabled"] = options.enabled;
+ if (options.category) toUpdate["tickets.category"] = options.category.id;
+ if (options.maxtickets) toUpdate["tickets.maxTickets"] = options.maxtickets;
+ if (options.supportping) toUpdate["tickets.supportRole"] = options.supportping.id;
try {
- await client.database.guilds.write(
- interaction.guild.id,
- toUpdate
- );
+ await client.database.guilds.write(interaction.guild.id, toUpdate);
} catch (e) {
return interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Tickets")
- .setDescription(
- "Something went wrong and the staff notifications channel could not be set"
- )
+ .setDescription("Something went wrong and the staff notifications channel could not be set")
.setStatus("Danger")
.setEmoji("GUILD.TICKET.DELETE")
],
@@ -243,8 +196,7 @@
}
let data = await client.database.guilds.read(interaction.guild.id);
data.tickets.customTypes = (data.tickets.customTypes || []).filter(
- (value: string, index: number, array: string[]) =>
- array.indexOf(value) === index
+ (value: string, index: number, array: string[]) => array.indexOf(value) === index
);
let lastClicked = "";
let embed: EmojiEmbed;
@@ -261,34 +213,18 @@
embed = new EmojiEmbed()
.setTitle("Tickets")
.setDescription(
- `${
- data.enabled ? "" : getEmojiByName("TICKETS.REPORT")
- } **Enabled:** ${
- data.enabled
- ? `${getEmojiByName("CONTROL.TICK")} Yes`
- : `${getEmojiByName("CONTROL.CROSS")} No`
+ `${data.enabled ? "" : getEmojiByName("TICKETS.REPORT")} **Enabled:** ${
+ data.enabled ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
}\n` +
- `${
- data.category ? "" : getEmojiByName("TICKETS.REPORT")
- } **Category:** ${
+ `${data.category ? "" : getEmojiByName("TICKETS.REPORT")} **Category:** ${
data.category ? `<#${data.category}>` : "*None set*"
}\n` +
- `**Max Tickets:** ${
- data.maxTickets ? data.maxTickets : "*No limit*"
- }\n` +
- `**Support Ping:** ${
- data.supportRole
- ? `<@&${data.supportRole}>`
- : "*None set*"
- }\n\n` +
- (data.useCustom && data.customTypes === null
- ? `${getEmojiByName("TICKETS.REPORT")} `
- : "") +
+ `**Max Tickets:** ${data.maxTickets ? data.maxTickets : "*No limit*"}\n` +
+ `**Support Ping:** ${data.supportRole ? `<@&${data.supportRole}>` : "*None set*"}\n\n` +
+ (data.useCustom && data.customTypes === null ? `${getEmojiByName("TICKETS.REPORT")} ` : "") +
`${data.useCustom ? "Custom" : "Default"} types in use` +
"\n\n" +
- `${getEmojiByName(
- "TICKETS.REPORT"
- )} *Indicates a setting stopping tickets from being used*`
+ `${getEmojiByName("TICKETS.REPORT")} *Indicates a setting stopping tickets from being used*`
)
.setStatus("Success")
.setEmoji("GUILD.TICKET.OPEN");
@@ -297,43 +233,24 @@
components: [
new MessageActionRow().addComponents([
new MessageButton()
- .setLabel(
- "Tickets " + (data.enabled ? "enabled" : "disabled")
- )
- .setEmoji(
- getEmojiByName(
- "CONTROL." + (data.enabled ? "TICK" : "CROSS"),
- "id"
- )
- )
+ .setLabel("Tickets " + (data.enabled ? "enabled" : "disabled"))
+ .setEmoji(getEmojiByName("CONTROL." + (data.enabled ? "TICK" : "CROSS"), "id"))
.setStyle(data.enabled ? "SUCCESS" : "DANGER")
.setCustomId("enabled"),
new MessageButton()
- .setLabel(
- lastClicked === "cat"
- ? "Click again to confirm"
- : "Clear category"
- )
+ .setLabel(lastClicked === "cat" ? "Click again to confirm" : "Clear category")
.setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
.setStyle("DANGER")
.setCustomId("clearCategory")
.setDisabled(data.category === null),
new MessageButton()
- .setLabel(
- lastClicked === "max"
- ? "Click again to confirm"
- : "Reset max tickets"
- )
+ .setLabel(lastClicked === "max" ? "Click again to confirm" : "Reset max tickets")
.setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
.setStyle("DANGER")
.setCustomId("clearMaxTickets")
.setDisabled(data.maxTickets === 5),
new MessageButton()
- .setLabel(
- lastClicked === "sup"
- ? "Click again to confirm"
- : "Clear support ping"
- )
+ .setLabel(lastClicked === "sup" ? "Click again to confirm" : "Clear support ping")
.setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
.setStyle("DANGER")
.setCustomId("clearSupportPing")
@@ -360,42 +277,25 @@
break;
}
i.deferUpdate();
- if (
- (i.component as MessageActionRowComponent).customId ===
- "clearCategory"
- ) {
+ if ((i.component as MessageActionRowComponent).customId === "clearCategory") {
if (lastClicked === "cat") {
lastClicked = "";
- await client.database.guilds.write(interaction.guild.id, null, [
- "tickets.category"
- ]);
+ await client.database.guilds.write(interaction.guild.id, null, ["tickets.category"]);
data.category = undefined;
} else lastClicked = "cat";
- } else if (
- (i.component as MessageActionRowComponent).customId ===
- "clearMaxTickets"
- ) {
+ } else if ((i.component as MessageActionRowComponent).customId === "clearMaxTickets") {
if (lastClicked === "max") {
lastClicked = "";
- await client.database.guilds.write(interaction.guild.id, null, [
- "tickets.maxTickets"
- ]);
+ await client.database.guilds.write(interaction.guild.id, null, ["tickets.maxTickets"]);
data.maxTickets = 5;
} else lastClicked = "max";
- } else if (
- (i.component as MessageActionRowComponent).customId ===
- "clearSupportPing"
- ) {
+ } else if ((i.component as MessageActionRowComponent).customId === "clearSupportPing") {
if (lastClicked === "sup") {
lastClicked = "";
- await client.database.guilds.write(interaction.guild.id, null, [
- "tickets.supportRole"
- ]);
+ await client.database.guilds.write(interaction.guild.id, null, ["tickets.supportRole"]);
data.supportRole = undefined;
} else lastClicked = "sup";
- } else if (
- (i.component as MessageActionRowComponent).customId === "send"
- ) {
+ } else if ((i.component as MessageActionRowComponent).customId === "send") {
const ticketMessages = [
{
label: "Create ticket",
@@ -403,13 +303,11 @@
},
{
label: "Issues, questions or feedback?",
- description:
- "Click below to open a ticket and get help from our staff team"
+ description: "Click below to open a ticket and get help from our staff team"
},
{
label: "Contact Us",
- description:
- "Click the button below to speak to us privately"
+ description: "Click the button below to speak to us privately"
}
];
while (true) {
@@ -418,9 +316,7 @@
embeds: [
new EmojiEmbed()
.setTitle("Ticket Button")
- .setDescription(
- "Select a message template to send in this channel"
- )
+ .setDescription("Select a message template to send in this channel")
.setFooter({
text: enabled
? ""
@@ -462,10 +358,7 @@
.setLabel("Back")
.setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
.setStyle("DANGER"),
- new MessageButton()
- .setCustomId("blank")
- .setLabel("Empty")
- .setStyle("SECONDARY"),
+ new MessageButton().setCustomId("blank").setLabel("Empty").setStyle("SECONDARY"),
new MessageButton()
.setCustomId("custom")
.setLabel("Custom")
@@ -480,29 +373,14 @@
} catch (e) {
break;
}
- if (
- (i.component as MessageActionRowComponent).customId ===
- "template"
- ) {
+ if ((i.component as MessageActionRowComponent).customId === "template") {
i.deferUpdate();
await interaction.channel.send({
embeds: [
new EmojiEmbed()
- .setTitle(
- ticketMessages[
- parseInt(
- (i as SelectMenuInteraction)
- .values[0]
- )
- ].label
- )
+ .setTitle(ticketMessages[parseInt((i as SelectMenuInteraction).values[0])].label)
.setDescription(
- ticketMessages[
- parseInt(
- (i as SelectMenuInteraction)
- .values[0]
- )
- ].description
+ ticketMessages[parseInt((i as SelectMenuInteraction).values[0])].description
)
.setStatus("Success")
.setEmoji("GUILD.TICKET.OPEN")
@@ -511,41 +389,28 @@
new MessageActionRow().addComponents([
new MessageButton()
.setLabel("Create Ticket")
- .setEmoji(
- getEmojiByName("CONTROL.TICK", "id")
- )
+ .setEmoji(getEmojiByName("CONTROL.TICK", "id"))
.setStyle("SUCCESS")
.setCustomId("createticket")
])
]
});
break;
- } else if (
- (i.component as MessageActionRowComponent).customId ===
- "blank"
- ) {
+ } else if ((i.component as MessageActionRowComponent).customId === "blank") {
i.deferUpdate();
await interaction.channel.send({
components: [
new MessageActionRow().addComponents([
new MessageButton()
.setLabel("Create Ticket")
- .setEmoji(
- getEmojiByName(
- "TICKETS.SUGGESTION",
- "id"
- )
- )
+ .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id"))
.setStyle("SUCCESS")
.setCustomId("createticket")
])
]
});
break;
- } else if (
- (i.component as MessageActionRowComponent).customId ===
- "custom"
- ) {
+ } else if ((i.component as MessageActionRowComponent).customId === "custom") {
await i.showModal(
new Discord.Modal()
.setCustomId("modal")
@@ -573,9 +438,7 @@
embeds: [
new EmojiEmbed()
.setTitle("Ticket Button")
- .setDescription(
- "Modal opened. If you can't see it, click back and try again."
- )
+ .setDescription("Modal opened. If you can't see it, click back and try again.")
.setStatus("Success")
.setEmoji("GUILD.TICKET.OPEN")
],
@@ -583,9 +446,7 @@
new MessageActionRow().addComponents([
new MessageButton()
.setLabel("Back")
- .setEmoji(
- getEmojiByName("CONTROL.LEFT", "id")
- )
+ .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
.setStyle("PRIMARY")
.setCustomId("back")
])
@@ -603,8 +464,7 @@
}
if (out.fields) {
const title = out.fields.getTextInputValue("title");
- const description =
- out.fields.getTextInputValue("description");
+ const description = out.fields.getTextInputValue("description");
await interaction.channel.send({
embeds: [
new EmojiEmbed()
@@ -617,12 +477,7 @@
new MessageActionRow().addComponents([
new MessageButton()
.setLabel("Create Ticket")
- .setEmoji(
- getEmojiByName(
- "TICKETS.SUGGESTION",
- "id"
- )
- )
+ .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id"))
.setStyle("SUCCESS")
.setCustomId("createticket")
])
@@ -634,17 +489,12 @@
}
}
}
- } else if (
- (i.component as MessageActionRowComponent).customId === "enabled"
- ) {
+ } else if ((i.component as MessageActionRowComponent).customId === "enabled") {
await client.database.guilds.write(interaction.guild.id, {
"tickets.enabled": !data.enabled
});
data.enabled = !data.enabled;
- } else if (
- (i.component as MessageActionRowComponent).customId ===
- "manageTypes"
- ) {
+ } else if ((i.component as MessageActionRowComponent).customId === "manageTypes") {
data = await manageTypes(interaction, data, m as Message);
} else {
break;
@@ -656,11 +506,7 @@
});
};
-async function manageTypes(
- interaction: CommandInteraction,
- data: GuildConfig["tickets"],
- m: Message
-) {
+async function manageTypes(interaction: CommandInteraction, data: GuildConfig["tickets"], m: Message) {
while (true) {
if (data.useCustom) {
const customTypes = data.customTypes;
@@ -671,11 +517,7 @@
.setDescription(
"**Custom types enabled**\n\n" +
"**Types in use:**\n" +
- (customTypes !== null
- ? customTypes
- .map((t) => `> ${t}`)
- .join("\n")
- : "*None set*") +
+ (customTypes !== null ? customTypes.map((t) => `> ${t}`).join("\n") : "*None set*") +
"\n\n" +
(customTypes === null
? `${getEmojiByName(
@@ -712,14 +554,10 @@
.setCustomId("back"),
new MessageButton()
.setLabel("Add new type")
- .setEmoji(
- getEmojiByName("TICKETS.SUGGESTION", "id")
- )
+ .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id"))
.setStyle("PRIMARY")
.setCustomId("addType")
- .setDisabled(
- customTypes !== null && customTypes.length >= 25
- ),
+ .setDisabled(customTypes !== null && customTypes.length >= 25),
new MessageButton()
.setLabel("Switch to default types")
.setStyle("SECONDARY")
@@ -735,12 +573,7 @@
new SelectMenuOption({
label: capitalize(type),
value: type,
- emoji: client.emojis.cache.get(
- getEmojiByName(
- `TICKETS.${type.toUpperCase()}`,
- "id"
- )
- ),
+ emoji: client.emojis.cache.get(getEmojiByName(`TICKETS.${type.toUpperCase()}`, "id")),
default: inUse.includes(type)
})
);
@@ -761,12 +594,7 @@
"**Default types enabled**\n\n" +
"**Types in use:**\n" +
inUse
- .map(
- (t) =>
- `> ${getEmojiByName(
- "TICKETS." + t.toUpperCase()
- )} ${capitalize(t)}`
- )
+ .map((t) => `> ${getEmojiByName("TICKETS." + t.toUpperCase())} ${capitalize(t)}`)
.join("\n")
)
.setStatus("Success")
@@ -835,9 +663,7 @@
embeds: [
new EmojiEmbed()
.setTitle("Tickets > Types")
- .setDescription(
- "Modal opened. If you can't see it, click back and try again."
- )
+ .setDescription("Modal opened. If you can't see it, click back and try again.")
.setStatus("Success")
.setEmoji("GUILD.TICKET.OPEN")
],
@@ -868,11 +694,7 @@
}
toAdd = toAdd.substring(0, 80);
try {
- await client.database.guilds.append(
- interaction.guild.id,
- "tickets.customTypes",
- toAdd
- );
+ await client.database.guilds.append(interaction.guild.id, "tickets.customTypes", toAdd);
} catch {
continue;
}
@@ -885,19 +707,11 @@
}
} else if (i.component.customId === "switchToDefault") {
i.deferUpdate();
- await client.database.guilds.write(
- interaction.guild.id,
- { "tickets.useCustom": false },
- []
- );
+ await client.database.guilds.write(interaction.guild.id, { "tickets.useCustom": false }, []);
data.useCustom = false;
} else if (i.component.customId === "switchToCustom") {
i.deferUpdate();
- await client.database.guilds.write(
- interaction.guild.id,
- { "tickets.useCustom": true },
- []
- );
+ await client.database.guilds.write(interaction.guild.id, { "tickets.useCustom": true }, []);
data.useCustom = true;
} else {
i.deferUpdate();