2024-02-06 21:45:53 +05:00
|
|
|
const { SlashCommandBuilder, PermissionsBitField, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require("discord.js");
|
2023-07-07 17:34:23 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class CloseTicket extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2023-07-07 17:34:23 +05:00
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("closeticket")
|
|
|
|
.setDescription(client.translate("tickets/closeticket:DESCRIPTION"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("tickets/closeticket:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("tickets/closeticket:DESCRIPTION", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.setDMPermission(false)
|
|
|
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages),
|
|
|
|
dirname: __dirname,
|
|
|
|
ownerOnly: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2023-07-07 17:34:23 +05:00
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
|
|
|
*/
|
2024-02-09 23:26:57 +05:00
|
|
|
async execute(client, interaction) {
|
2023-07-07 17:34:23 +05:00
|
|
|
await interaction.deferReply();
|
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
const guildData = interaction.data.guild;
|
|
|
|
|
2023-07-07 21:13:11 +05:00
|
|
|
if (!interaction.channel.name.includes("support")) return interaction.error("tickets/adduser:NOT_TICKET", null, { ephemeral: true, edit: true });
|
2023-07-07 17:34:23 +05:00
|
|
|
|
2024-02-06 21:45:53 +05:00
|
|
|
const embed = client.embed({
|
|
|
|
title: interaction.translate("tickets/closeticket:CLOSING_TITLE"),
|
|
|
|
description: interaction.translate("tickets/closeticket:CLOSING_DESC"),
|
|
|
|
fields: [
|
2023-07-07 17:34:23 +05:00
|
|
|
{
|
|
|
|
name: interaction.translate("common:TICKET"),
|
|
|
|
value: interaction.channel.name,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: interaction.translate("tickets/closeticket:CLOSING_BY"),
|
2023-07-07 21:13:11 +05:00
|
|
|
value: interaction.user.getUsername(),
|
2023-07-07 17:34:23 +05:00
|
|
|
},
|
2024-02-06 21:45:53 +05:00
|
|
|
],
|
|
|
|
});
|
2023-07-07 17:34:23 +05:00
|
|
|
|
2023-07-07 21:13:11 +05:00
|
|
|
const button = new ButtonBuilder().setCustomId("cancel_closing").setLabel(interaction.translate("common:CANCEL")).setStyle(ButtonStyle.Danger);
|
2023-07-07 17:34:23 +05:00
|
|
|
const row = new ActionRowBuilder().addComponents(button);
|
|
|
|
|
2023-11-04 16:56:10 +05:00
|
|
|
await interaction.editReply({
|
2023-07-07 17:34:23 +05:00
|
|
|
embeds: [embed],
|
|
|
|
components: [row],
|
|
|
|
});
|
|
|
|
|
2023-07-07 21:13:11 +05:00
|
|
|
const filter = i => i.customId === "cancel_closing";
|
2023-07-07 17:34:23 +05:00
|
|
|
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 5000 });
|
|
|
|
|
|
|
|
collector.on("collect", async i => {
|
|
|
|
await i.update({ content: interaction.translate("tickets/closeticket:CLOSING_CANCELED"), components: [] });
|
|
|
|
collector.stop("canceled");
|
|
|
|
});
|
|
|
|
|
|
|
|
collector.on("end", async (_, reason) => {
|
2023-07-07 21:13:11 +05:00
|
|
|
if (reason !== "canceled") {
|
2024-02-09 23:26:57 +05:00
|
|
|
const transcriptionLogs = guildData.plugins.tickets.transcriptionLogs,
|
|
|
|
ticketLogs = guildData.plugins.tickets.ticketLogs;
|
2023-07-07 21:13:11 +05:00
|
|
|
const reversedMessages = (await interaction.channel.messages.fetch()).filter(m => !m.author.bot);
|
2023-07-07 17:34:23 +05:00
|
|
|
const messages = Array.from(reversedMessages.values()).reverse();
|
|
|
|
|
2023-07-07 21:13:11 +05:00
|
|
|
let transcript = "---- TICKET CREATED ----\n";
|
2023-07-07 17:34:23 +05:00
|
|
|
messages.forEach(message => {
|
2023-12-14 18:58:19 +05:00
|
|
|
transcript += `[${client.functions.printDate(client, message.createdTimestamp, null, interaction.getLocale())}] ${message.author.getUsername()}: ${message.content}\n`;
|
2023-07-07 17:34:23 +05:00
|
|
|
});
|
2023-07-07 21:13:11 +05:00
|
|
|
transcript += "---- TICKET CLOSED ----";
|
|
|
|
|
|
|
|
if (transcriptionLogs) interaction.guild.channels.cache.get(transcriptionLogs).send({ content: interaction.translate("tickets/closeticket:TRANSCRIPT", { channel: `<#${interaction.channelId}>` }), files: [{ attachment: Buffer.from(transcript), name: `${interaction.channel.name}.txt` }] });
|
|
|
|
|
|
|
|
if (ticketLogs) {
|
|
|
|
const logChannel = interaction.guild.channels.cache.get(ticketLogs);
|
2024-02-06 21:45:53 +05:00
|
|
|
const logEmbed = client.embed({
|
|
|
|
title: interaction.translate("tickets/createticketembed:TICKET_CLOSED_TITLE"),
|
|
|
|
description: `${interaction.user.toString()} (${interaction.channel.toString()})`,
|
|
|
|
});
|
2023-07-07 21:13:11 +05:00
|
|
|
|
|
|
|
logChannel.send({ embeds: [logEmbed] });
|
|
|
|
}
|
|
|
|
|
|
|
|
interaction.channel.send("Closed!");
|
2023-07-07 17:34:23 +05:00
|
|
|
|
|
|
|
try {
|
2023-07-07 21:13:11 +05:00
|
|
|
await interaction.user.send({
|
|
|
|
content: interaction.translate("tickets/closeticket:TRANSCRIPT", { channel: interaction.channel.name }),
|
|
|
|
files: [{ attachment: Buffer.from(transcript), name: `${interaction.channel.name}.txt` }],
|
|
|
|
});
|
|
|
|
} catch (e) {
|
2024-02-06 21:45:53 +05:00
|
|
|
interaction.reply({ content: interaction.translate("misc:CANT_DM"), ephemeral: true });
|
2023-07-07 17:34:23 +05:00
|
|
|
}
|
|
|
|
|
2023-08-18 22:01:38 +05:00
|
|
|
const member = interaction.guild.members.cache.find(u => u.user.id === interaction.channel.topic);
|
2023-08-08 22:22:06 +05:00
|
|
|
await interaction.channel.permissionOverwrites.edit(member, { ViewChannel: false, SendMessages: null });
|
2023-08-08 17:28:03 +05:00
|
|
|
await interaction.channel.setName(`${interaction.channel.name}-closed`);
|
2023-07-07 17:34:23 +05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
const ticketLogs = guildData.plugins.tickets.ticketLogs;
|
2024-02-06 21:45:53 +05:00
|
|
|
const logEmbed = client.embed({
|
|
|
|
title: interaction.translate("tickets/closeticket:CLOSED_TITLE"),
|
|
|
|
fields: [
|
2023-07-07 17:34:23 +05:00
|
|
|
{
|
|
|
|
name: interaction.translate("common:TICKET"),
|
|
|
|
value: interaction.channel.name,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: interaction.translate("tickets/closeticket:CLOSING_BY"),
|
2023-07-07 21:13:11 +05:00
|
|
|
value: interaction.user.getUsername(),
|
2023-07-07 17:34:23 +05:00
|
|
|
},
|
2024-02-06 21:45:53 +05:00
|
|
|
],
|
|
|
|
});
|
2023-07-07 17:34:23 +05:00
|
|
|
|
|
|
|
if (ticketLogs) interaction.guild.channels.cache.get(ticketLogs).send({ embeds: [logEmbed] });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = CloseTicket;
|