From 8236da075a294fa32700c3417e21f90b9e37ebed Mon Sep 17 00:00:00 2001 From: Tarrgon <61888458+Tarrgon@users.noreply.github.com> Date: Tue, 24 Jun 2025 06:23:02 -0400 Subject: [PATCH] Ticket unclaiming --- src/buttons/claim-ticket.ts | 19 ++++++--------- src/buttons/close-ticket.ts | 7 +++++- src/buttons/unclaim-ticket.ts | 45 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 src/buttons/unclaim-ticket.ts diff --git a/src/buttons/claim-ticket.ts b/src/buttons/claim-ticket.ts index 4092620..f006f6b 100644 --- a/src/buttons/claim-ticket.ts +++ b/src/buttons/claim-ticket.ts @@ -8,7 +8,7 @@ export default { const channel = await interaction.channel?.fetch(); if (!channel || !channel.isThread() || !channel.isSendable() || channel.type != ChannelType.PrivateThread) - return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Oops. Something went wrong. Please report this to a staff member.' }); + return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Oops. Something went wrong.' }); if (!interaction.memberPermissions) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'An error has occurred.' }); @@ -19,28 +19,23 @@ export default { const guildSettings = await Database.getGuildSettings(guild.id); if (!guildSettings || !guildSettings.private_help_role_id) - return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Failed to create ticket. Please report this to a staff member.' }); + return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Failed to create ticket.' }); const closeButton = new ButtonBuilder() .setCustomId('close-ticket') .setLabel('Click here if you no longer need help') .setStyle(ButtonStyle.Danger); - const claimButton = new ButtonBuilder() - .setCustomId('claim-ticket') - .setLabel('Claim ticket') - .setDisabled(true) + const unclaimButton = new ButtonBuilder() + .setCustomId('unclaim-ticket') + .setLabel('Unclaim ticket') .setStyle(ButtonStyle.Primary); - const row = new ActionRowBuilder().addComponents(closeButton, claimButton); + const row = new ActionRowBuilder().addComponents(closeButton, unclaimButton); await interaction.message.edit({ content: `${interaction.message.content}\n\nClaimed by: ${interaction.user}`, - components: [row], - allowedMentions: { - users: [interaction.user.id], - roles: [guildSettings.private_help_role_id] - } + components: [row] }); await interaction.reply({ content: `Ticket claimed by ${interaction.user}.` }); diff --git a/src/buttons/close-ticket.ts b/src/buttons/close-ticket.ts index dcfba5c..dbcd210 100644 --- a/src/buttons/close-ticket.ts +++ b/src/buttons/close-ticket.ts @@ -1,4 +1,4 @@ -import { ActionRowBuilder, ButtonInteraction, Client, ModalBuilder, TextInputBuilder, TextInputStyle, MessageFlags, ChannelType } from 'discord.js'; +import { ActionRowBuilder, ButtonInteraction, Client, ModalBuilder, TextInputBuilder, TextInputStyle, MessageFlags, ChannelType, ButtonBuilder, ButtonStyle } from 'discord.js'; import { ticketCooldownMap } from '../shared/ticket-cooldown'; export default { @@ -9,6 +9,11 @@ export default { if (!channel || !channel.isThread() || !channel.isSendable() || channel.type != ChannelType.PrivateThread) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Oops. Something went wrong. Please report this to a staff member.' }); + await interaction.message.edit({ + content: interaction.message.content, + components: [] + }); + await channel.send(`This ticket has been closed by ${interaction.user}`); await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Ticket closed.' }); diff --git a/src/buttons/unclaim-ticket.ts b/src/buttons/unclaim-ticket.ts new file mode 100644 index 0000000..29f887f --- /dev/null +++ b/src/buttons/unclaim-ticket.ts @@ -0,0 +1,45 @@ +import { ActionRowBuilder, ButtonInteraction, Client, ModalBuilder, TextInputBuilder, TextInputStyle, MessageFlags, ChannelType, PermissionFlagsBits, ButtonBuilder, ButtonStyle } from 'discord.js'; +import { ticketCooldownMap } from '../shared/ticket-cooldown'; +import { Database } from '../shared/Database'; + +export default { + name: 'unclaim-ticket', + handler: async function (client: Client, interaction: ButtonInteraction) { + const channel = await interaction.channel?.fetch(); + + if (!channel || !channel.isThread() || !channel.isSendable() || channel.type != ChannelType.PrivateThread) + return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Oops. Something went wrong.' }); + + if (!interaction.memberPermissions) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'An error has occurred.' }); + + if (!interaction.memberPermissions.has(PermissionFlagsBits.ManageMessages)) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'You do not have permission to unclaim this ticket.' }); + + if (!interaction.message.content.split('\n').at(-1)!.includes(`<@${interaction.user.id}>`)) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'You did not claim this ticket.' }); + + const guild = await client.guilds.fetch(interaction.guildId!); + + const guildSettings = await Database.getGuildSettings(guild.id); + + if (!guildSettings || !guildSettings.private_help_role_id) + return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Failed to create ticket.' }); + + const closeButton = new ButtonBuilder() + .setCustomId('close-ticket') + .setLabel('Click here if you no longer need help') + .setStyle(ButtonStyle.Danger); + + const claimButton = new ButtonBuilder() + .setCustomId('claim-ticket') + .setLabel('Claim ticket') + .setStyle(ButtonStyle.Primary); + + const row = new ActionRowBuilder().addComponents(closeButton, claimButton); + + await interaction.message.edit({ + content: interaction.message.content.split('\n').slice(0, -1).join('\n').trim(), + components: [row] + }); + + await interaction.reply({ content: 'Ticket unclaimed.', flags: [MessageFlags.Ephemeral] }); + } +}; \ No newline at end of file