Skip to content

Commit

Permalink
feat: close ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
DaStormer committed Mar 12, 2024
1 parent 14833a7 commit 5d5fc71
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
29 changes: 29 additions & 0 deletions bot/interactions/components/buttons/close.js
Original file line number Diff line number Diff line change
@@ -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;
37 changes: 37 additions & 0 deletions bot/interactions/slashcommands/close.js
Original file line number Diff line number Diff line change
@@ -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;
Empty file.
17 changes: 15 additions & 2 deletions managers/TicketsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5d5fc71

Please sign in to comment.