blob: 7b9d1c237ebd58fdda571fa5a4a348d158ed316a [file] [log] [blame]
pineafan1dc15722022-03-14 21:27:34 +00001import Discord, { CommandInteraction } from "discord.js";
pineafan4f164f32022-02-26 22:07:12 +00002import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
3import { WrappedCheck } from "jshaiku";
pineafan1dc15722022-03-14 21:27:34 +00004import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
5import readConfig from "../../utils/readConfig.js";
6import getEmojiByName from "../../utils/getEmojiByName.js";
pineafan4f164f32022-02-26 22:07:12 +00007
8const command = (builder: SlashCommandSubcommandBuilder) =>
9 builder
10 .setName("close")
11 .setDescription("Closes a ticket")
12
pineafan1dc15722022-03-14 21:27:34 +000013const callback = async (interaction: CommandInteraction) => {
14 // @ts-ignore
15 const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = interaction.client.logger
16
17 let config = await readConfig(interaction.guild.id);
18 let channel = (interaction.channel as Discord.TextChannel)
19 if (config.tickets.category != channel.parent.id) {
20 return interaction.reply({embeds: [new EmojiEmbed()
21 .setTitle("Close Ticket")
22 .setDescription("This ticket is not in your tickets category, so cannot be deleted.")
23 .setStatus("Danger")
24 .setEmoji("CONTROL.BLOCKCROSS")
25 ], ephemeral: true});
26 }
27 let status = channel.topic.split(" ")[1];
28 if (status == "Archived") {
29 interaction.reply({embeds: [new EmojiEmbed()
30 .setTitle("Close Ticket")
31 .setDescription("This ticket will be deleted in 3 seconds.")
32 .setStatus("Danger")
33 .setEmoji("GUILD.TICKET.CLOSE")
34 ]});
35 setTimeout(async () => {
36 let data = {
37 meta:{
38 type: 'ticketClosed',
39 displayName: 'Ticket Closed',
40 calculateType: true,
41 color: NucleusColors.red,
42 emoji: 'GUILD.TICKET.CLOSE',
43 timestamp: new Date().getTime()
44 },
45 list: {
46 ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
47 closedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
48 closedAt: entry(new Date().getTime(), renderDelta(new Date().getTime()))
49 },
50 hidden: {
51 guild: interaction.guild.id
52 }
53 }
54 log(data, interaction.client);
55 interaction.channel.delete();
56 }, 3000);
57 return;
58 } else if (status == "Active") {
59 interaction.reply({embeds: [new EmojiEmbed()
60 .setTitle("Close Ticket")
61 .setDescription("This ticket will be archived in 3 seconds.")
62 .setStatus("Warning")
63 .setEmoji("GUILD.TICKET.ARCHIVED")
64 ]});
65 setTimeout(async () =>{
66 channel.permissionsFor(await interaction.guild.members.fetch(channel.topic.split(" ")[0])).remove("VIEW_CHANNEL");
67 channel.setTopic(`${channel.topic.split(" ")[0]} Archived`);
68 let data = {
69 meta:{
70 type: 'ticketArchive',
71 displayName: 'Ticket Archived',
72 calculateType: true,
73 color: NucleusColors.yellow,
74 emoji: 'GUILD.TICKET.ARCHIVED',
75 timestamp: new Date().getTime()
76 },
77 list: {
78 ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
79 archivedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
80 archivedAt: entry(new Date().getTime(), renderDelta(new Date().getTime())),
81 ticketChannel: entry(channel.id, renderChannel(channel)),
82 },
83 hidden: {
84 guild: interaction.guild.id
85 }
86 }
87 log(data, interaction.client);
88 await interaction.editReply({embeds: [new EmojiEmbed()
89 .setTitle("Close Ticket")
90 .setDescription("This ticket has been archived.\nType `/ticket close` to delete it.")
91 .setStatus("Warning")
92 .setEmoji("GUILD.TICKET.ARCHIVED") // TODO:[Premium] Add a transcript option ||\----/|| <- the bridge we will cross when we come to it
93 ]});
94 }, 3000);
95 return;
96 }
pineafan4f164f32022-02-26 22:07:12 +000097}
98
99const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
100 return true;
101}
102
103export { command };
104export { callback };
105export { check };