commands/settings/tickets + commands/settings/verify

pull/17/head
TheCodedProf 3 years ago
parent 60781dd875
commit 59772f8423

@ -13,10 +13,14 @@ import Discord, {
StringSelectMenuBuilder, StringSelectMenuBuilder,
Role, Role,
StringSelectMenuInteraction, StringSelectMenuInteraction,
TextInputComponent, ButtonStyle,
ButtonStyle TextInputBuilder,
ButtonComponent,
StringSelectMenuComponent,
ModalSubmitInteraction,
APIMessageComponentEmoji
} from "discord.js"; } from "discord.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { SlashCommandSubcommandBuilder, StringSelectMenuOptionBuilder } from "@discordjs/builders";
import { ChannelType } from "discord-api-types/v9"; import { ChannelType } from "discord-api-types/v9";
import client from "../../utils/client.js"; 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";
@ -78,7 +82,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
if (options.category) { if (options.category) {
let channel: GuildChannel | null; let channel: GuildChannel | null;
try { try {
channel = await interaction.guild.channels.fetch(options.category.id); channel = await interaction.guild.channels.fetch(options.category.id) as GuildChannel;
} catch { } catch {
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
@ -145,7 +149,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
} }
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("GUILD.TICKET.ARCHIVED", "GUILD.TICKET.CLOSE") .setEmoji("GUILD.TICKET.ARCHIVED")
.setTitle("Tickets") .setTitle("Tickets")
.setDescription( .setDescription(
(options.category ? `**Category:** ${options.category.name}\n` : "") + (options.category ? `**Category:** ${options.category.name}\n` : "") +
@ -161,6 +165,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
"\nAre you sure you want to apply these settings?" "\nAre you sure you want to apply these settings?"
) )
.setColor("Warning") .setColor("Warning")
.setFailedMessage("Cancelled", "Warning", "GUILD.TICKET.CLOSE") // TODO: Set Actual Message
.setInverted(true) .setInverted(true)
.send(true); .send(true);
if (confirmation.cancelled) return; if (confirmation.cancelled) return;
@ -202,8 +207,8 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
(value: string, index: number, array: string[]) => array.indexOf(value) === index (value: string, index: number, array: string[]) => array.indexOf(value) === index
); );
let lastClicked = ""; let lastClicked = "";
let embed: EmojiEmbed; let embed: EmojiEmbed = new EmojiEmbed();
data = { let compiledData = {
enabled: data.tickets.enabled, enabled: data.tickets.enabled,
category: data.tickets.category, category: data.tickets.category,
maxTickets: data.tickets.maxTickets, maxTickets: data.tickets.maxTickets,
@ -214,19 +219,19 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}; };
let timedOut = false; let timedOut = false;
while (!timedOut) { while (!timedOut) {
embed = new EmojiEmbed() embed
.setTitle("Tickets") .setTitle("Tickets")
.setDescription( .setDescription(
`${data.enabled ? "" : getEmojiByName("TICKETS.REPORT")} **Enabled:** ${ `${compiledData.enabled ? "" : getEmojiByName("TICKETS.REPORT")} **Enabled:** ${
data.enabled ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No` compiledData.enabled ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
}\n` + }\n` +
`${data.category ? "" : getEmojiByName("TICKETS.REPORT")} **Category:** ${ `${compiledData.category ? "" : getEmojiByName("TICKETS.REPORT")} **Category:** ${
data.category ? `<#${data.category}>` : "*None set*" compiledData.category ? `<#${compiledData.category}>` : "*None set*"
}\n` + }\n` +
`**Max Tickets:** ${data.maxTickets ? data.maxTickets : "*No limit*"}\n` + `**Max Tickets:** ${compiledData.maxTickets ? compiledData.maxTickets : "*No limit*"}\n` +
`**Support Ping:** ${data.supportRole ? `<@&${data.supportRole}>` : "*None set*"}\n\n` + `**Support Ping:** ${compiledData.supportRole ? `<@&${compiledData.supportRole}>` : "*None set*"}\n\n` +
(data.useCustom && data.customTypes === null ? `${getEmojiByName("TICKETS.REPORT")} ` : "") + (compiledData.useCustom && compiledData.customTypes === null ? `${getEmojiByName("TICKETS.REPORT")} ` : "") +
`${data.useCustom ? "Custom" : "Default"} types in use` + `${compiledData.useCustom ? "Custom" : "Default"} types in use` +
"\n\n" + "\n\n" +
`${getEmojiByName("TICKETS.REPORT")} *Indicates a setting stopping tickets from being used*` `${getEmojiByName("TICKETS.REPORT")} *Indicates a setting stopping tickets from being used*`
) )
@ -235,32 +240,32 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
m = (await interaction.editReply({ m = (await interaction.editReply({
embeds: [embed], embeds: [embed],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Tickets " + (data.enabled ? "enabled" : "disabled")) .setLabel("Tickets " + (compiledData.enabled ? "enabled" : "disabled"))
.setEmoji(getEmojiByName("CONTROL." + (data.enabled ? "TICK" : "CROSS"), "id")) .setEmoji(getEmojiByName("CONTROL." + (compiledData.enabled ? "TICK" : "CROSS"), "id"))
.setStyle(data.enabled ? ButtonStyle.Success : ButtonStyle.Danger) .setStyle(compiledData.enabled ? ButtonStyle.Success : ButtonStyle.Danger)
.setCustomId("enabled"), .setCustomId("enabled"),
new ButtonBuilder() new ButtonBuilder()
.setLabel(lastClicked === "cat" ? "Click again to confirm" : "Clear category") .setLabel(lastClicked === "cat" ? "Click again to confirm" : "Clear category")
.setEmoji(getEmojiByName("CONTROL.CROSS", "id")) .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
.setStyle(ButtonStyle.Danger) .setStyle(ButtonStyle.Danger)
.setCustomId("clearCategory") .setCustomId("clearCategory")
.setDisabled(data.category === null), .setDisabled(compiledData.category === null),
new ButtonBuilder() new ButtonBuilder()
.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")) .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
.setStyle(ButtonStyle.Danger) .setStyle(ButtonStyle.Danger)
.setCustomId("clearMaxTickets") .setCustomId("clearMaxTickets")
.setDisabled(data.maxTickets === 5), .setDisabled(compiledData.maxTickets === 5),
new ButtonBuilder() new ButtonBuilder()
.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")) .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
.setStyle(ButtonStyle.Danger) .setStyle(ButtonStyle.Danger)
.setCustomId("clearSupportPing") .setCustomId("clearSupportPing")
.setDisabled(data.supportRole === null) .setDisabled(compiledData.supportRole === null)
]), ]),
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Manage types") .setLabel("Manage types")
.setEmoji(getEmojiByName("TICKETS.OTHER", "id")) .setEmoji(getEmojiByName("TICKETS.OTHER", "id"))
@ -285,25 +290,25 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
continue; continue;
} }
i.deferUpdate(); i.deferUpdate();
if ((i.component as Component).customId === "clearCategory") { if ((i.component as ButtonComponent).customId === "clearCategory") {
if (lastClicked === "cat") { if (lastClicked === "cat") {
lastClicked = ""; 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; compiledData.category = null;
} else lastClicked = "cat"; } else lastClicked = "cat";
} else if ((i.component as Component).customId === "clearMaxTickets") { } else if ((i.component as ButtonComponent).customId === "clearMaxTickets") {
if (lastClicked === "max") { if (lastClicked === "max") {
lastClicked = ""; 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; compiledData.maxTickets = 5;
} else lastClicked = "max"; } else lastClicked = "max";
} else if ((i.component as Component).customId === "clearSupportPing") { } else if ((i.component as ButtonComponent).customId === "clearSupportPing") {
if (lastClicked === "sup") { if (lastClicked === "sup") {
lastClicked = ""; 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; compiledData.supportRole = null;
} else lastClicked = "sup"; } else lastClicked = "sup";
} else if ((i.component as Component).customId === "send") { } else if ((i.component as ButtonComponent).customId === "send") {
const ticketMessages = [ const ticketMessages = [
{ {
label: "Create ticket", label: "Create ticket",
@ -321,7 +326,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
let innerTimedOut = false; let innerTimedOut = false;
let templateSelected = false; let templateSelected = false;
while (!innerTimedOut && !templateSelected) { while (!innerTimedOut && !templateSelected) {
const enabled = data.enabled && data.category !== null; const enabled = compiledData.enabled && compiledData.category !== null;
await interaction.editReply({ await interaction.editReply({
embeds: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
@ -336,7 +341,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("GUILD.ROLES.CREATE") .setEmoji("GUILD.ROLES.CREATE")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
new StringSelectMenuBuilder() new StringSelectMenuBuilder()
.setOptions( .setOptions(
ticketMessages.map( ticketMessages.map(
@ -362,7 +367,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setMinValues(1) .setMinValues(1)
.setPlaceholder("Select a message template") .setPlaceholder("Select a message template")
]), ]),
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setCustomId("back") .setCustomId("back")
.setLabel("Back") .setLabel("Back")
@ -387,7 +392,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
innerTimedOut = true; innerTimedOut = true;
continue; continue;
} }
if ((i.component as Component).customId === "template") { if ((i.component as StringSelectMenuComponent).customId === "template") {
i.deferUpdate(); i.deferUpdate();
await interaction.channel!.send({ await interaction.channel!.send({
embeds: [ embeds: [
@ -400,7 +405,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("GUILD.TICKET.OPEN") .setEmoji("GUILD.TICKET.OPEN")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Create Ticket") .setLabel("Create Ticket")
.setEmoji(getEmojiByName("CONTROL.TICK", "id")) .setEmoji(getEmojiByName("CONTROL.TICK", "id"))
@ -411,11 +416,11 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
templateSelected = true; templateSelected = true;
continue; continue;
} else if ((i.component as Component).customId === "blank") { } else if ((i.component as ButtonComponent).customId === "blank") {
i.deferUpdate(); i.deferUpdate();
await interaction.channel!.send({ await interaction.channel!.send({
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Create Ticket") .setLabel("Create Ticket")
.setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id")) .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id"))
@ -426,27 +431,27 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
templateSelected = true; templateSelected = true;
continue; continue;
} else if ((i.component as Component).customId === "custom") { } else if ((i.component as ButtonComponent).customId === "custom") {
await i.showModal( await i.showModal(
new Discord.Modal() new Discord.ModalBuilder()
.setCustomId("modal") .setCustomId("modal")
.setTitle("Enter embed details") .setTitle("Enter embed details")
.addComponents( .addComponents(
new ActionRowBuilder<TextInputComponent>().addComponents( new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputComponent() new TextInputBuilder()
.setCustomId("title") .setCustomId("title")
.setLabel("Title") .setLabel("Title")
.setMaxLength(256) .setMaxLength(256)
.setRequired(true) .setRequired(true)
.setStyle("SHORT") .setStyle(Discord.TextInputStyle.Short)
), ),
new ActionRowBuilder<TextInputComponent>().addComponents( new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputComponent() new TextInputBuilder()
.setCustomId("description") .setCustomId("description")
.setLabel("Description") .setLabel("Description")
.setMaxLength(4000) .setMaxLength(4000)
.setRequired(true) .setRequired(true)
.setStyle("PARAGRAPH") .setStyle(Discord.TextInputStyle.Paragraph)
) )
) )
); );
@ -459,7 +464,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("GUILD.TICKET.OPEN") .setEmoji("GUILD.TICKET.OPEN")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Back") .setLabel("Back")
.setEmoji(getEmojiByName("CONTROL.LEFT", "id")) .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
@ -479,10 +484,11 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
innerTimedOut = true; innerTimedOut = true;
continue; continue;
} }
out = out as ModalSubmitInteraction;
if (out.fields) { if (out.fields) {
const title = out.fields.getTextInputValue("title"); const title = out.fields.getTextInputValue("title");
const description = out.fields.getTextInputValue("description"); const description = out.fields.getTextInputValue("description");
await interaction.channel.send({ await interaction.channel!.send({
embeds: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
.setTitle(title) .setTitle(title)
@ -491,7 +497,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("GUILD.TICKET.OPEN") .setEmoji("GUILD.TICKET.OPEN")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Create Ticket") .setLabel("Create Ticket")
.setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id")) .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id"))
@ -504,17 +510,17 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
} }
} }
} }
} else if ((i.component as Component).customId === "enabled") { } else if ((i.component as ButtonComponent).customId === "enabled") {
await client.database.guilds.write(interaction.guild.id, { await client.database.guilds.write(interaction.guild.id, {
"tickets.enabled": !data.enabled "tickets.enabled": !compiledData.enabled
}); });
data.enabled = !data.enabled; compiledData.enabled = !compiledData.enabled;
} else if ((i.component as Component).customId === "manageTypes") { } else if ((i.component as ButtonComponent).customId === "manageTypes") {
data = await manageTypes(interaction, data, m as Message); data = await manageTypes(interaction, data, m as Message); //TODO: Fix this
} }
} }
await interaction.editReply({ await interaction.editReply({
embeds: [embed.setFooter({ text: "Message timed out" })], embeds: [ embed.setFooter({ text: "Message timed out" })],
components: [] components: []
}); });
}; };
@ -545,7 +551,7 @@ async function manageTypes(interaction: CommandInteraction, data: GuildConfig["t
], ],
components: (customTypes components: (customTypes
? [ ? [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<StringSelectMenuBuilder | ButtonBuilder>().addComponents([
new Discord.StringSelectMenuBuilder() new Discord.StringSelectMenuBuilder()
.setCustomId("removeTypes") .setCustomId("removeTypes")
.setPlaceholder("Select types to remove") .setPlaceholder("Select types to remove")
@ -561,7 +567,7 @@ async function manageTypes(interaction: CommandInteraction, data: GuildConfig["t
] ]
: [] : []
).concat([ ).concat([
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Back") .setLabel("Back")
.setEmoji(getEmojiByName("CONTROL.LEFT", "id")) .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
@ -582,18 +588,18 @@ async function manageTypes(interaction: CommandInteraction, data: GuildConfig["t
}); });
} else { } else {
const inUse = toHexArray(data.types, ticketTypes); const inUse = toHexArray(data.types, ticketTypes);
const options = []; const options: StringSelectMenuOptionBuilder[] = [];
ticketTypes.forEach((type) => { ticketTypes.forEach((type) => {
options.push( options.push(
new StringSelectMenuOption({ new StringSelectMenuOptionBuilder({
label: capitalize(type), label: capitalize(type),
value: type, value: type,
emoji: client.emojis.cache.get(getEmojiByName(`TICKETS.${type.toUpperCase()}`, "id")), emoji: client.emojis.cache.get(getEmojiByName(`TICKETS.${type.toUpperCase()}`, "id")) as APIMessageComponentEmoji,
default: inUse.includes(type) default: inUse.includes(type)
}) })
); );
}); });
const selectPane = new ActionRowBuilder().addComponents([ const selectPane = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
new Discord.StringSelectMenuBuilder() new Discord.StringSelectMenuBuilder()
.addOptions(options) .addOptions(options)
.setCustomId("types") .setCustomId("types")
@ -617,7 +623,7 @@ async function manageTypes(interaction: CommandInteraction, data: GuildConfig["t
], ],
components: [ components: [
selectPane, selectPane,
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Back") .setLabel("Back")
.setEmoji(getEmojiByName("CONTROL.LEFT", "id")) .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
@ -641,40 +647,40 @@ async function manageTypes(interaction: CommandInteraction, data: GuildConfig["t
timedOut = true; timedOut = true;
continue; continue;
} }
if (i.component.customId === "types") { if ((i.component as StringSelectMenuComponent).customId === "types") {
i.deferUpdate(); i.deferUpdate();
const types = toHexInteger(i.values, ticketTypes); const types = toHexInteger((i as StringSelectMenuInteraction).values, ticketTypes);
await client.database.guilds.write(interaction.guild.id, { await client.database.guilds.write(interaction.guild!.id, {
"tickets.types": types "tickets.types": types
}); });
data.types = types; data.types = types;
} else if (i.component.customId === "removeTypes") { } else if ((i.component as StringSelectMenuComponent).customId === "removeTypes") {
i.deferUpdate(); i.deferUpdate();
const types = i.values; const types = (i as StringSelectMenuInteraction).values;
let customTypes = data.customTypes; let customTypes = data.customTypes;
if (customTypes) { if (customTypes) {
customTypes = customTypes.filter((t) => !types.includes(t)); customTypes = customTypes.filter((t) => !types.includes(t));
customTypes = customTypes.length > 0 ? customTypes : null; customTypes = customTypes.length > 0 ? customTypes : null;
await client.database.guilds.write(interaction.guild.id, { await client.database.guilds.write(interaction.guild!.id, {
"tickets.customTypes": customTypes "tickets.customTypes": customTypes
}); });
data.customTypes = customTypes; data.customTypes = customTypes;
} }
} else if (i.component.customId === "addType") { } else if ((i.component as ButtonComponent).customId === "addType") {
await i.showModal( await i.showModal(
new Discord.Modal() new Discord.ModalBuilder()
.setCustomId("modal") .setCustomId("modal")
.setTitle("Enter a name for the new type") .setTitle("Enter a name for the new type")
.addComponents( .addComponents(
new ActionRowBuilder<TextInputComponent>().addComponents( new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputComponent() new TextInputBuilder()
.setCustomId("type") .setCustomId("type")
.setLabel("Name") .setLabel("Name")
.setMaxLength(100) .setMaxLength(100)
.setMinLength(1) .setMinLength(1)
.setPlaceholder('E.g. "Server Idea"') .setPlaceholder('E.g. "Server Idea"')
.setRequired(true) .setRequired(true)
.setStyle("SHORT") .setStyle(Discord.TextInputStyle.Short)
) )
) )
); );
@ -687,7 +693,7 @@ async function manageTypes(interaction: CommandInteraction, data: GuildConfig["t
.setEmoji("GUILD.TICKET.OPEN") .setEmoji("GUILD.TICKET.OPEN")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Back") .setLabel("Back")
.setEmoji(getEmojiByName("CONTROL.LEFT", "id")) .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
@ -700,12 +706,13 @@ async function manageTypes(interaction: CommandInteraction, data: GuildConfig["t
try { try {
out = await modalInteractionCollector( out = await modalInteractionCollector(
m, m,
(m) => m.channel.id === interaction.channel.id, (m) => m.channel!.id === interaction.channel!.id,
(m) => m.customId === "addType" (m) => m.customId === "addType"
); );
} catch (e) { } catch (e) {
continue; continue;
} }
out = out as ModalSubmitInteraction;
if (out.fields) { if (out.fields) {
let toAdd = out.fields.getTextInputValue("type"); let toAdd = out.fields.getTextInputValue("type");
if (!toAdd) { if (!toAdd) {
@ -713,7 +720,7 @@ async function manageTypes(interaction: CommandInteraction, data: GuildConfig["t
} }
toAdd = toAdd.substring(0, 80); toAdd = toAdd.substring(0, 80);
try { try {
await client.database.guilds.append(interaction.guild.id, "tickets.customTypes", toAdd); await client.database.guilds.append(interaction.guild!.id, "tickets.customTypes", toAdd);
} catch { } catch {
continue; continue;
} }
@ -724,13 +731,13 @@ async function manageTypes(interaction: CommandInteraction, data: GuildConfig["t
} else { } else {
continue; continue;
} }
} else if (i.component.customId === "switchToDefault") { } else if ((i.component as ButtonComponent).customId === "switchToDefault") {
i.deferUpdate(); 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; data.useCustom = false;
} else if (i.component.customId === "switchToCustom") { } else if ((i.component as ButtonComponent).customId === "switchToCustom") {
i.deferUpdate(); 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; data.useCustom = true;
} else { } else {
i.deferUpdate(); i.deferUpdate();

@ -4,15 +4,17 @@ import Discord, {
Interaction, Interaction,
Message, Message,
ActionRowBuilder, ActionRowBuilder,
Component,
ButtonBuilder, ButtonBuilder,
MessageComponentInteraction, MessageComponentInteraction,
SelectMenuBuilder,
ModalSubmitInteraction, ModalSubmitInteraction,
Role, Role,
SelectMenuInteraction, ButtonStyle,
TextInputComponent, StringSelectMenuBuilder,
ButtonStyle StringSelectMenuComponent,
TextInputBuilder,
EmbedBuilder,
StringSelectMenuInteraction,
ButtonComponent
} from "discord.js"; } from "discord.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import confirmationMessage from "../../utils/confirmationMessage.js"; import confirmationMessage from "../../utils/confirmationMessage.js";
@ -36,10 +38,10 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
ephemeral: true, ephemeral: true,
fetchReply: true fetchReply: true
})) as Message; })) as Message;
if (interaction.options.getRole("role")) { if (interaction.options.get("role")?.role) {
let role: Role; let role: Role;
try { try {
role = interaction.options.getRole("role") as Role; role = interaction.options.get("role")?.role as Role;
} catch { } catch {
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
@ -64,10 +66,11 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
} }
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("GUILD.ROLES.EDIT", "GUILD.ROLES.DELETE") .setEmoji("GUILD.ROLES.EDIT")
.setTitle("Verify Role") .setTitle("Verify Role")
.setDescription(`Are you sure you want to set the verify role to <@&${role.id}>?`) .setDescription(`Are you sure you want to set the verify role to <@&${role.id}>?`)
.setColor("Warning") .setColor("Warning")
.setFailedMessage("No changes were made", "Warning", "GUILD.ROLES.DELETE")
.setInverted(true) .setInverted(true)
.send(true); .send(true);
if (confirmation.cancelled) return; if (confirmation.cancelled) return;
@ -140,7 +143,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("GUILD.ROLES.CREATE") .setEmoji("GUILD.ROLES.CREATE")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setCustomId("clear") .setCustomId("clear")
.setLabel(clicks ? "Click again to confirm" : "Reset role") .setLabel(clicks ? "Click again to confirm" : "Reset role")
@ -166,14 +169,14 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
continue; continue;
} }
i.deferUpdate(); i.deferUpdate();
if ((i.component as Component).customId === "clear") { if ((i.component as ButtonComponent).customId === "clear") {
clicks += 1; clicks += 1;
if (clicks === 2) { if (clicks === 2) {
clicks = 0; clicks = 0;
await client.database.guilds.write(interaction.guild.id, null, ["verify.role", "verify.enabled"]); await client.database.guilds.write(interaction.guild.id, null, ["verify.role", "verify.enabled"]);
role = undefined; role = null;
} }
} else if ((i.component as Component).customId === "send") { } else if ((i.component as ButtonComponent).customId === "send") {
const verifyMessages = [ const verifyMessages = [
{ {
label: "Verify", label: "Verify",
@ -203,8 +206,8 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("GUILD.ROLES.CREATE") .setEmoji("GUILD.ROLES.CREATE")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
new SelectMenuBuilder() new StringSelectMenuBuilder()
.setOptions( .setOptions(
verifyMessages.map( verifyMessages.map(
( (
@ -229,7 +232,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setMinValues(1) .setMinValues(1)
.setPlaceholder("Select a message template") .setPlaceholder("Select a message template")
]), ]),
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setCustomId("back") .setCustomId("back")
.setLabel("Back") .setLabel("Back")
@ -254,20 +257,20 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
innerTimedOut = true; innerTimedOut = true;
continue; continue;
} }
if ((i.component as Component).customId === "template") { if ((i.component as StringSelectMenuComponent).customId === "template") {
i.deferUpdate(); i.deferUpdate();
await interaction.channel!.send({ await interaction.channel!.send({
embeds: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
.setTitle(verifyMessages[parseInt((i as SelectMenuInteraction).values[0]!)]!.label) .setTitle(verifyMessages[parseInt((i as StringSelectMenuInteraction).values[0]!)]!.label)
.setDescription( .setDescription(
verifyMessages[parseInt((i as SelectMenuInteraction).values[0]!)]!.description verifyMessages[parseInt((i as StringSelectMenuInteraction).values[0]!)]!.description
) )
.setStatus("Success") .setStatus("Success")
.setEmoji("CONTROL.BLOCKTICK") .setEmoji("CONTROL.BLOCKTICK")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Verify") .setLabel("Verify")
.setEmoji(getEmojiByName("CONTROL.TICK", "id")) .setEmoji(getEmojiByName("CONTROL.TICK", "id"))
@ -278,11 +281,11 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
templateSelected = true; templateSelected = true;
continue; continue;
} else if ((i.component as Component).customId === "blank") { } else if ((i.component as ButtonComponent).customId === "blank") {
i.deferUpdate(); i.deferUpdate();
await interaction.channel!.send({ await interaction.channel!.send({
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Verify") .setLabel("Verify")
.setEmoji(getEmojiByName("CONTROL.TICK", "id")) .setEmoji(getEmojiByName("CONTROL.TICK", "id"))
@ -293,27 +296,27 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
templateSelected = true; templateSelected = true;
continue; continue;
} else if ((i.component as Component).customId === "custom") { } else if ((i.component as ButtonComponent).customId === "custom") {
await i.showModal( await i.showModal(
new Discord.Modal() new Discord.ModalBuilder()
.setCustomId("modal") .setCustomId("modal")
.setTitle("Enter embed details") .setTitle("Enter embed details")
.addComponents( .addComponents(
new ActionRowBuilder<TextInputComponent>().addComponents( new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputComponent() new TextInputBuilder()
.setCustomId("title") .setCustomId("title")
.setLabel("Title") .setLabel("Title")
.setMaxLength(256) .setMaxLength(256)
.setRequired(true) .setRequired(true)
.setStyle("SHORT") .setStyle(Discord.TextInputStyle.Short)
), ),
new ActionRowBuilder<TextInputComponent>().addComponents( new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputComponent() new TextInputBuilder()
.setCustomId("description") .setCustomId("description")
.setLabel("Description") .setLabel("Description")
.setMaxLength(4000) .setMaxLength(4000)
.setRequired(true) .setRequired(true)
.setStyle("PARAGRAPH") .setStyle(Discord.TextInputStyle.Paragraph)
) )
) )
); );
@ -326,7 +329,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("GUILD.TICKET.OPEN") .setEmoji("GUILD.TICKET.OPEN")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Back") .setLabel("Back")
.setEmoji(getEmojiByName("CONTROL.LEFT", "id")) .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
@ -360,7 +363,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("CONTROL.BLOCKTICK") .setEmoji("CONTROL.BLOCKTICK")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setLabel("Verify") .setLabel("Verify")
.setEmoji(getEmojiByName("CONTROL.TICK", "id")) .setEmoji(getEmojiByName("CONTROL.TICK", "id"))
@ -379,7 +382,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
} }
} }
await interaction.editReply({ await interaction.editReply({
embeds: [m.embeds[0]!.setFooter({ text: "Message closed" })], embeds: [new EmbedBuilder(m.embeds[0]!.data).setFooter({ text: "Message closed" })],
components: [] components: []
}); });
}; };

Loading…
Cancel
Save