blob: 8feeb4b8bd6e327ca3e77affe55ee86bf80bf6fa [file] [log] [blame]
pineafanad54d752022-04-18 19:01:43 +01001import Discord, { MessageButton, MessageActionRow } from "discord.js";
2import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
3import getEmojiByName from "../../utils/getEmojiByName.js";
4import readConfig from "../../utils/readConfig.js";
5
6export default async function (interaction) {
7 // @ts-ignore
8 const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = interaction.client.logger
9
10 let config = await readConfig(interaction.guild.id);
11 let channel = (interaction.channel as Discord.TextChannel)
12 if (config.tickets.category != channel.parent.id) {
13 return interaction.reply({embeds: [new generateEmojiEmbed()
14 .setTitle("Close Ticket")
15 .setDescription("This ticket is not in your tickets category, so cannot be deleted.")
16 .setStatus("Danger")
17 .setEmoji("CONTROL.BLOCKCROSS")
18 ], ephemeral: true});
19 }
20 let status = channel.topic.split(" ")[1];
21 if (status == "Archived") {
22 interaction.reply({embeds: [new generateEmojiEmbed()
23 .setTitle("Close Ticket")
24 .setDescription("This ticket will be deleted in 3 seconds.")
25 .setStatus("Danger")
26 .setEmoji("GUILD.TICKET.CLOSE")
27 ]});
28 setTimeout(async () => {
29 let data = {
30 meta:{
31 type: 'ticketClosed',
32 displayName: 'Ticket Closed',
33 calculateType: true,
34 color: NucleusColors.red,
35 emoji: 'GUILD.TICKET.CLOSE',
36 timestamp: new Date().getTime()
37 },
38 list: {
39 ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
40 closedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
41 closed: entry(new Date().getTime(), renderDelta(new Date().getTime()))
42 },
43 hidden: {
44 guild: interaction.guild.id
45 }
46 }
47 log(data, interaction.client);
48 interaction.channel.delete();
49 }, 3000);
50 return;
51 } else if (status == "Active") {
52 interaction.reply({embeds: [new generateEmojiEmbed()
53 .setTitle("Close Ticket")
54 .setDescription("This ticket will be archived in 3 seconds.")
55 .setStatus("Warning")
56 .setEmoji("GUILD.TICKET.ARCHIVED")
57 ]});
58 setTimeout(async () =>{
59 channel.permissionsFor(await interaction.guild.members.fetch(channel.topic.split(" ")[0])).remove("VIEW_CHANNEL");
60 channel.setTopic(`${channel.topic.split(" ")[0]} Archived`);
61 let data = {
62 meta:{
63 type: 'ticketArchive',
64 displayName: 'Ticket Archived',
65 calculateType: true,
66 color: NucleusColors.yellow,
67 emoji: 'GUILD.TICKET.ARCHIVED',
68 timestamp: new Date().getTime()
69 },
70 list: {
71 ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
72 archivedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
73 archived: entry(new Date().getTime(), renderDelta(new Date().getTime())),
74 ticketChannel: entry(channel.id, renderChannel(channel)),
75 },
76 hidden: {
77 guild: interaction.guild.id
78 }
79 }
80 log(data, interaction.client);
81 await interaction.editReply({embeds: [new generateEmojiEmbed()
82 .setTitle("Close Ticket")
83 .setDescription("This ticket has been archived.\nType `/ticket close` to delete it.")
84 .setStatus("Warning")
85 .setEmoji("GUILD.TICKET.ARCHIVED") // TODO:[Premium] Add a transcript option ||\----/|| <- the bridge we will cross when we come to it
86 ], components: [new MessageActionRow().addComponents([new MessageButton()
87 .setLabel("Close")
88 .setStyle("DANGER")
89 .setCustomId("closeticket")
90 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
91 ])]});
92 }, 3000);
93 return;
94 }
95}
96
97async function purgeByUser(member, guild) {
98 let config = await readConfig(guild.id);
99 if (!config.tickets.category) return;
100 let tickets = guild.channels.cache.get(config.tickets.category);
101 let ticketChannels = tickets.children;
102 let deleted = 0
103 ticketChannels.forEach(element => {
104 if (element.type != "GUILD_TEXT") return;
105 if (element.topic.split(" ")[0] == member) {
106 element.delete();
107 deleted++
108 }
109 });
110 if (deleted) {
111 try {
112 const { log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger
113 let data = {
114 meta:{
115 type: 'ticketPurge',
116 displayName: 'Tickets Purged',
117 calculateType: true,
118 color: NucleusColors.red,
119 emoji: 'GUILD.TICKET.DELETE',
120 timestamp: new Date().getTime()
121 },
122 list: {
123 ticketFor: entry(member, renderUser(member)),
124 deletedBy: entry(null, "Member left server"),
125 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
126 ticketsDeleted: deleted,
127 },
128 hidden: {
129 guild: guild.id
130 }
131 }
132 log(data, member.client);
133 } catch {}
134 }
135}
136
137export { purgeByUser }