diff --git a/bot/interactions/components/buttons/close.js b/bot/interactions/components/buttons/close.js index e69de29..0e908e1 100644 --- a/bot/interactions/components/buttons/close.js +++ b/bot/interactions/components/buttons/close.js @@ -0,0 +1,29 @@ +const Component = require("../../../../structures/base/BaseComponent"); + +class CloseButton extends Component { + constructor(client) { + super(client, { + name: "close", + category: "mentor", + cooldown: 5, + }); + } + + /** + * @param {import("discord.js").ButtonInteraction} interaction + */ + async run(interaction) { + + if (!this.MentorQ.tickets.isActive(interaction.guild)) + return interaction.reply({ embeds: [this.MentorQ.util.errorEmbed("The MentorQ system is not active. Contact a server admin to complete setup process.")], ephemeral: true }); + + await this.MentorQ.tickets.close(interaction.member, interaction.message.channel); + + interaction.reply({ embeds: [this.MentorQ.util.successEmbed(`Ticket ${interaction.message.channel.toString()} has been closed.`)] }); + + return; + + } +} + +module.exports = CloseButton; \ No newline at end of file diff --git a/bot/interactions/slashcommands/close.js b/bot/interactions/slashcommands/close.js index e69de29..24b2c0c 100644 --- a/bot/interactions/slashcommands/close.js +++ b/bot/interactions/slashcommands/close.js @@ -0,0 +1,37 @@ +const SlashCommand = require("../../../structures/base/BaseSlashCommand"); + +class CloseSlashCommand extends SlashCommand { + constructor(client) { + super(client, { + name: "close", + category: "mentor", + cooldown: 5, + guildRequired: true, + commandData: { + description: "Close the current ticket.", + }, + }); + } + + /** + * @param {import("discord.js").CommandInteraction} interaction + */ + async run(interaction) { + + if (!this.MentorQ.tickets.isActive(interaction.guild)) + return interaction.reply({ embeds: [this.MentorQ.util.errorEmbed("The MentorQ system is not active. Contact a server admin to complete setup process.")], ephemeral: true }); + + const ticket = interaction.channel; + if (!ticket.isThread() || ticket.ownerId !== this.MentorQ.user.id || ticket.parentId !== this.MentorQ.tickets.getRequestsChannel()?.id) + return interaction.reply({ embeds: [this.MentorQ.util.errorEmbed("This is not a valid MentorQ ticket!")], ephemeral: true }); + + await this.MentorQ.tickets.close(interaction.member, ticket); + + interaction.reply({ embeds: [this.MentorQ.util.successEmbed(`Ticket ${ticket.toString()} has been closed.`)] }); + + return; + + } +} + +module.exports = CloseSlashCommand; \ No newline at end of file diff --git a/bot/interactions/slashcommands/help.js b/bot/interactions/slashcommands/help.js deleted file mode 100644 index e69de29..0000000 diff --git a/managers/TicketsManager.js b/managers/TicketsManager.js index e07e487..00eba52 100644 --- a/managers/TicketsManager.js +++ b/managers/TicketsManager.js @@ -97,9 +97,22 @@ class TicketsManager { return ticket.toString(); } - // close(ticketChannel) { + /** + * Archive and lock a ticket thread channel. + * @param {import("discord.js").GuildMember} mentor + * @param {import("discord.js").ThreadChannel} ticketChannel + */ + async close(mentor, ticketChannel) { + if (ticketChannel.archived && ticketChannel.locked) return true; + + await ticketChannel.setArchived(true, `Closed by: ${mentor.user.tag}`); + await ticketChannel.setLocked(true, `Closed by: ${mentor.user.tag}`); - // } + const member = await this.MentorQ.util.fetchMember(mentor.guild, ticketChannel.name.split("-")[1]); + if (member) member.send({ embeds: [this.MentorQ.util.infoEmbed(`Your mentor ticket ${ticketChannel.toString()} has been **CLOSED** by ${mentor.user.tag}.`)] }).catch(() => { }); + + return true; + } /** * Cancel a pending mentor request in the queue.