pineafan | 1dc1572 | 2022-03-14 21:27:34 +0000 | [diff] [blame] | 1 | import Discord, { CommandInteraction } from "discord.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 2 | import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
| 3 | import { WrappedCheck } from "jshaiku"; |
pineafan | 1dc1572 | 2022-03-14 21:27:34 +0000 | [diff] [blame] | 4 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
| 5 | import readConfig from "../../utils/readConfig.js"; |
| 6 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 7 | |
| 8 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 9 | builder |
| 10 | .setName("close") |
| 11 | .setDescription("Closes a ticket") |
| 12 | |
pineafan | 1dc1572 | 2022-03-14 21:27:34 +0000 | [diff] [blame] | 13 | const 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 | } |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | export { command }; |
| 104 | export { callback }; |
| 105 | export { check }; |