blob: 1985a0800b95bf4b77fa132875564f104c7feba1 [file] [log] [blame]
pineafan813bdf42022-07-24 10:39:10 +01001import Discord, { MessageButton, MessageActionRow } from "discord.js";
2import client from "../../utils/client.js";
3import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
4import getEmojiByName from "../../utils/getEmojiByName.js";
5
6export default async function (interaction) {
7 const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger
8
9 let config = await client.database.guilds.read(interaction.guild.id);
10 let thread = false; let threadChannel
11 if (interaction.channel instanceof Discord.ThreadChannel) thread = true; threadChannel = interaction.channel as Discord.ThreadChannel
12 let channel = (interaction.channel as Discord.TextChannel)
13 if (!channel.parent || config.tickets.category != channel.parent.id || (thread ? (threadChannel.parent.parent.id != config.tickets.category) : false)) {
14 return interaction.reply({embeds: [new EmojiEmbed()
15 .setTitle("Deleting Ticket...")
16 .setDescription("This ticket is not in your tickets category, so cannot be deleted. You cannot run close in a thread.")
17 .setStatus("Danger")
18 .setEmoji("CONTROL.BLOCKCROSS")
19 ], ephemeral: true});
20 }
21 let status = channel.topic.split(" ")[1];
22 if (status == "Archived") {
23 await interaction.reply({embeds: [new EmojiEmbed()
24 .setTitle("Delete Ticket")
25 .setDescription("Your ticket is being deleted...")
26 .setStatus("Danger")
27 .setEmoji("GUILD.TICKET.CLOSE")
28 ]});
29 let data = {
30 meta:{
31 type: 'ticketDeleted',
32 displayName: 'Ticket Deleted',
33 calculateType: "ticketUpdate",
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 deletedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
41 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
42 },
43 hidden: {
44 guild: interaction.guild.id
45 }
46 }
47 log(data);
48 interaction.channel.delete();
49 return;
50 } else if (status == "Active") {
51 await interaction.reply({embeds: [new EmojiEmbed()
52 .setTitle("Close Ticket")
53 .setDescription("Your ticket is being closed...")
54 .setStatus("Warning")
55 .setEmoji("GUILD.TICKET.ARCHIVED")
56 ]});
57 let overwrites = [
58 {
59 id: channel.topic.split(" ")[0],
60 deny: ["VIEW_CHANNEL"],
61 type: "member"
62 },
63 {
64 id: interaction.guild.id,
65 deny: ["VIEW_CHANNEL"],
66 type: "role"
67 }
68 ] as Discord.OverwriteResolvable[];
69 if (config.tickets.supportRole != null) {
70 overwrites.push({
71 id: interaction.guild.roles.cache.get(config.tickets.supportRole),
72 allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
73 type: "role"
74 })
75 }
76 channel.edit({permissionOverwrites: overwrites})
77 channel.setTopic(`${channel.topic.split(" ")[0]} Archived`);
78 let data = {
79 meta:{
80 type: 'ticketClosed',
81 displayName: 'Ticket Closed',
82 calculateType: "ticketUpdate",
83 color: NucleusColors.yellow,
84 emoji: 'GUILD.TICKET.ARCHIVED',
85 timestamp: new Date().getTime()
86 },
87 list: {
88 ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
89 closedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
90 closed: entry(new Date().getTime(), renderDelta(new Date().getTime())),
91 ticketChannel: entry(channel.id, renderChannel(channel)),
92 },
93 hidden: {
94 guild: interaction.guild.id
95 }
96 }
97 log(data);
98 await interaction.editReply({embeds: [new EmojiEmbed()
99 .setTitle("Close Ticket")
100 .setDescription("This ticket has been closed.\nType `/ticket close` again to delete it.\n\nNote: Check `/privacy` for details about transcripts.")
101 .setStatus("Warning")
102 .setEmoji("GUILD.TICKET.ARCHIVED")
103 ], components: [
104 new MessageActionRow().addComponents([
105 new MessageButton()
106 .setLabel("Delete")
107 .setStyle("DANGER")
108 .setCustomId("closeticket")
109 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
110 ].concat(client.database.premium.hasPremium(interaction.guild.id) ? [
111 new MessageButton()
112 .setLabel("Create Transcript and Delete")
113 .setStyle("PRIMARY")
114 .setCustomId("createtranscript")
115 .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
116 ] : []))
117 ]});
118 return;
119 }
120}
121
122async function purgeByUser(member, guild) {
123 let config = await client.database.guilds.read(guild.id);
124 if (!config.tickets.category) return;
125 let tickets = guild.channels.cache.get(config.tickets.category);
126 if (!tickets) return;
127 let ticketChannels = tickets.children;
128 let deleted = 0
129 ticketChannels.forEach(element => {
130 if (element.type != "GUILD_TEXT") return;
131 if (element.topic.split(" ")[0] == member) {
132 try { element.delete(); } catch {}
133 deleted++
134 }
135 });
136 if (deleted) {
137 try {
138 const { log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger
139 let data = {
140 meta:{
141 type: 'ticketPurge',
142 displayName: 'Tickets Purged',
143 calculateType: "ticketUpdate",
144 color: NucleusColors.red,
145 emoji: 'GUILD.TICKET.DELETE',
146 timestamp: new Date().getTime()
147 },
148 list: {
149 ticketFor: entry(member, renderUser(member)),
150 deletedBy: entry(null, "Member left server"),
151 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
152 ticketsDeleted: deleted,
153 },
154 hidden: {
155 guild: guild.id
156 }
157 }
158 log(data);
159 } catch {}
160 }
161}
162
163export { purgeByUser }