i have not committed in years
diff --git a/src/commands/ticket/close.ts b/src/commands/ticket/close.ts
index 7b9d1c2..237623d 100644
--- a/src/commands/ticket/close.ts
+++ b/src/commands/ticket/close.ts
@@ -1,9 +1,7 @@
-import Discord, { CommandInteraction } from "discord.js";
+import { CommandInteraction } from "discord.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { WrappedCheck } from "jshaiku";
-import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
-import readConfig from "../../utils/readConfig.js";
-import getEmojiByName from "../../utils/getEmojiByName.js";
+import close from "../../automations/tickets/delete.js";
const command = (builder: SlashCommandSubcommandBuilder) =>
builder
@@ -11,89 +9,7 @@
.setDescription("Closes a ticket")
const callback = async (interaction: CommandInteraction) => {
- // @ts-ignore
- const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = interaction.client.logger
-
- let config = await readConfig(interaction.guild.id);
- let channel = (interaction.channel as Discord.TextChannel)
- if (config.tickets.category != channel.parent.id) {
- return interaction.reply({embeds: [new EmojiEmbed()
- .setTitle("Close Ticket")
- .setDescription("This ticket is not in your tickets category, so cannot be deleted.")
- .setStatus("Danger")
- .setEmoji("CONTROL.BLOCKCROSS")
- ], ephemeral: true});
- }
- let status = channel.topic.split(" ")[1];
- if (status == "Archived") {
- interaction.reply({embeds: [new EmojiEmbed()
- .setTitle("Close Ticket")
- .setDescription("This ticket will be deleted in 3 seconds.")
- .setStatus("Danger")
- .setEmoji("GUILD.TICKET.CLOSE")
- ]});
- setTimeout(async () => {
- let data = {
- meta:{
- type: 'ticketClosed',
- displayName: 'Ticket Closed',
- calculateType: true,
- color: NucleusColors.red,
- emoji: 'GUILD.TICKET.CLOSE',
- timestamp: new Date().getTime()
- },
- list: {
- ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
- closedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
- closedAt: entry(new Date().getTime(), renderDelta(new Date().getTime()))
- },
- hidden: {
- guild: interaction.guild.id
- }
- }
- log(data, interaction.client);
- interaction.channel.delete();
- }, 3000);
- return;
- } else if (status == "Active") {
- interaction.reply({embeds: [new EmojiEmbed()
- .setTitle("Close Ticket")
- .setDescription("This ticket will be archived in 3 seconds.")
- .setStatus("Warning")
- .setEmoji("GUILD.TICKET.ARCHIVED")
- ]});
- setTimeout(async () =>{
- channel.permissionsFor(await interaction.guild.members.fetch(channel.topic.split(" ")[0])).remove("VIEW_CHANNEL");
- channel.setTopic(`${channel.topic.split(" ")[0]} Archived`);
- let data = {
- meta:{
- type: 'ticketArchive',
- displayName: 'Ticket Archived',
- calculateType: true,
- color: NucleusColors.yellow,
- emoji: 'GUILD.TICKET.ARCHIVED',
- timestamp: new Date().getTime()
- },
- list: {
- ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
- archivedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
- archivedAt: entry(new Date().getTime(), renderDelta(new Date().getTime())),
- ticketChannel: entry(channel.id, renderChannel(channel)),
- },
- hidden: {
- guild: interaction.guild.id
- }
- }
- log(data, interaction.client);
- await interaction.editReply({embeds: [new EmojiEmbed()
- .setTitle("Close Ticket")
- .setDescription("This ticket has been archived.\nType `/ticket close` to delete it.")
- .setStatus("Warning")
- .setEmoji("GUILD.TICKET.ARCHIVED") // TODO:[Premium] Add a transcript option ||\----/|| <- the bridge we will cross when we come to it
- ]});
- }, 3000);
- return;
- }
+ await close(interaction);
}
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
diff --git a/src/commands/ticket/create.ts b/src/commands/ticket/create.ts
index 4f58aa0..6567c49 100644
--- a/src/commands/ticket/create.ts
+++ b/src/commands/ticket/create.ts
@@ -1,15 +1,7 @@
-import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
+import { CommandInteraction } from "discord.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { WrappedCheck } from "jshaiku";
-import { tickets, toHexArray, toHexInteger } from "../../utils/calculate.js";
-import readConfig from "../../utils/readConfig.js";
-import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
-import getEmojiByName from "../../utils/getEmojiByName.js";
-
-function capitalize(s: string) {
- s = s.replace(/([A-Z])/g, ' $1');
- return s.length < 3 ? s.toUpperCase() : s[0].toUpperCase() + s.slice(1).toLowerCase();
-}
+import create from "../../automations/tickets/create.js";
const command = (builder: SlashCommandSubcommandBuilder) =>
builder
@@ -18,155 +10,7 @@
.addStringOption(option => option.setName("message").setDescription("The content of the ticket").setRequired(false))
const callback = async (interaction: CommandInteraction) => {
- // @ts-ignore
- const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = interaction.client.logger
-
- let config = await readConfig(interaction.guild.id);
- if (!config.tickets.enabled || !config.tickets.category) {
- return await interaction.reply({embeds: [new EmojiEmbed()
- .setTitle("Tickets are disabled")
- .setDescription("Please enable tickets in the configuration to use this command.")
- .setStatus("Danger")
- .setEmoji("CONTROL.BLOCKCROSS")
- ], ephemeral: true});
- }
- let category = interaction.guild.channels.cache.get(config.tickets.category) as Discord.CategoryChannel;
- let count = 0;
- category.children.forEach(element => {
- if (!(element.type == "GUILD_TEXT")) return;
- if ((element as Discord.TextChannel).topic.includes(`${interaction.member.user.id}`)) {
- if ((element as Discord.TextChannel).topic.endsWith("Active")) {
- count++;
- }
- }
- });
- if (count >= config.tickets.maxTickets) {
- return await interaction.reply({embeds: [new EmojiEmbed()
- .setTitle("Create Ticket")
- .setDescription(`You have reached the maximum amount of tickets (${config.tickets.maxTickets}). Please close one of your active tickets before creating a new one.`)
- .setStatus("Danger")
- .setEmoji("CONTROL.BLOCKCROSS")
- ], ephemeral: true});
- }
- let ticketTypes
- if (config.tickets.customTypes) ticketTypes = config.tickets.customTypes;
- else if (config.tickets.types) ticketTypes = toHexArray(config.tickets.types, tickets);
- else ticketTypes = [];
- let chosenType;
- if (ticketTypes.length > 0) {
- let splitFormattedTicketTypes = [];
- let formattedTicketTypes = [];
- formattedTicketTypes = ticketTypes.map(type => {
- return new MessageButton()
- .setLabel(capitalize(type))
- .setStyle("PRIMARY")
- .setCustomId(type)
- .setEmoji(getEmojiByName(("TICKETS." + type.toString().toUpperCase()), "id"));
- });
- for (let i = 0; i < formattedTicketTypes.length; i += 4) {
- splitFormattedTicketTypes.push(new MessageActionRow().addComponents(formattedTicketTypes.slice(i, i + 4)));
- }
- let m = await interaction.reply({embeds: [new EmojiEmbed()
- .setTitle("Create Ticket")
- .setDescription("Please select a ticket type")
- .setStatus("Success")
- .setEmoji("GUILD.TICKET.OPEN")
- ], ephemeral: true, fetchReply: true, components: splitFormattedTicketTypes});
- let component;
- try {
- component = await (m as Discord.Message).awaitMessageComponent({time: 2.5 * 60 * 1000});
- } catch (e) {
- return;
- }
- component.deferUpdate();
- chosenType = component.customId;
- } else {
- chosenType = null
- await interaction.reply({embeds: [new EmojiEmbed()
- .setTitle("Create Ticket")
- .setEmoji("GUILD.TICKET.OPEN")
- ], ephemeral: true})
- }
- let overwrites = [{
- id: interaction.member,
- allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
- type: "member"
- }] as Discord.OverwriteResolvable[];
- if (config.tickets.supportRole != null) {
- overwrites.push({
- id: interaction.guild.roles.cache.get(config.tickets.supportRole),
- allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
- type: "role"
- })
- }
-
- let c;
- try {
- c = await interaction.guild.channels.create(interaction.member.user.username, {
- type: "GUILD_TEXT",
- topic: `${interaction.member.user.id} Active`,
- parent: config.tickets.category,
- nsfw: false,
- permissionOverwrites: (overwrites as Discord.OverwriteResolvable[]),
- reason: "Creating ticket"
- })
- } catch (e) {
- return await interaction.editReply({embeds: [new EmojiEmbed()
- .setTitle("Create Ticket")
- .setDescription("Failed to create ticket")
- .setStatus("Danger")
- .setEmoji("CONTROL.BLOCKCROSS")
- ]});
- }
- try {
- await c.send(
- {
- content: (`<@${interaction.member.user.id}>` + (config.tickets.supportRole != null ? ` • <@&${config.tickets.supportRole}>` : "")),
- allowedMentions: {
- users: [(interaction.member as Discord.GuildMember).id],
- roles: (config.tickets.supportRole != null ? [config.tickets.supportRole] : [])
- }
- }
- )
- let content = interaction.options.getString("message") || "";
- if (content) content = `**Message:**\n> ${content}\n`;
- await c.send({ embeds: [new EmojiEmbed()
- .setTitle("New Ticket")
- .setDescription(
- `Ticket created by <@${interaction.member.user.id}>\n` +
- `**Support type:** ${chosenType != null ? (getEmojiByName("TICKETS." + chosenType.toUpperCase()) + " " + capitalize(chosenType)) : "General"}\n` +
- `**Ticket ID:** \`${c.id}\`\n${content}\n` +
- `Type \`/ticket close\` to archive this ticket.`,
- )
- .setStatus("Success")
- .setEmoji("GUILD.TICKET.OPEN")
- ]})
- let data = {
- meta:{
- type: 'ticketCreate',
- displayName: 'Ticket Created',
- calculateType: true,
- color: NucleusColors.green,
- emoji: 'GUILD.TICKET.OPEN',
- timestamp: new Date().getTime()
- },
- list: {
- ticketFor: entry(interaction.member.user.id, renderUser(interaction.member.user)),
- createdAt: entry(new Date().getTime(), renderDelta(new Date().getTime())),
- ticketChannel: entry(c.id, renderChannel(c)),
- },
- hidden: {
- guild: interaction.guild.id
- }
- }
- log(data, interaction.client);
- } catch (e) { console.log(e)}
- await interaction.editReply({embeds: [new EmojiEmbed()
- .setTitle("Create Ticket")
- .setDescription(`Ticket created. You can view it here: <#${c.id}>`)
- .setStatus("Success")
- .setEmoji("GUILD.TICKET.OPEN")
- ], components: []});
+ await create(interaction)
}
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {