/** * Ticket action row builder – Close, Claim, Escalate (if tier < 3), Deescalate (if tier >= 2). * Used by handlers/buttons.js and handlers/commands.js. */ const { ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionFlagsBits } = require('discord.js'); const { CONFIG } = require('../config'); /** * permissionOverwrites for a Discord-originated ticket channel: deny @everyone, * allow the creating user and the staff ping role. Used by the button and * context-menu creation paths (the email/gmail path differs — no Discord * creator — and builds its own overwrites). * @param {import('discord.js').Guild} guild * @param {string} creatorId - Discord user ID of the ticket creator */ function ticketChannelOverwrites(guild, creatorId) { const allow = [ PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages, PermissionFlagsBits.ReadMessageHistory ]; return [ { id: guild.id, deny: [PermissionFlagsBits.ViewChannel] }, { id: creatorId, allow }, { id: CONFIG.ROLE_ID_TO_PING, allow } ]; } /** * Build the standard ticket action row (Close, Claim, optionally Escalate, optionally Deescalate). * @param {Object} ticket - Ticket with escalationTier (0, 1, 2) and optionally escalated * @returns {ActionRowBuilder} */ function getTicketActionRow(ticket) { const tier = ticket.escalationTier ?? (ticket.escalated ? 1 : 0); const row = new ActionRowBuilder(); row.addComponents( new ButtonBuilder() .setCustomId('close_ticket') .setLabel(CONFIG.BUTTON_LABEL_CLOSE) .setEmoji(CONFIG.BUTTON_EMOJI_CLOSE) .setStyle(ButtonStyle.Secondary), new ButtonBuilder() .setCustomId('claim_ticket') .setLabel(CONFIG.BUTTON_LABEL_CLAIM) .setEmoji(CONFIG.BUTTON_EMOJI_CLAIM) .setStyle(ButtonStyle.Secondary) ); if (tier < 2) { row.addComponents( new ButtonBuilder() .setCustomId('escalate_ticket') .setLabel('Escalate') .setStyle(ButtonStyle.Secondary) ); } if (tier >= 1) { row.addComponents( new ButtonBuilder() .setCustomId('deescalate_ticket') .setLabel('Deescalate') .setStyle(ButtonStyle.Secondary) ); } return row; } module.exports = { getTicketActionRow, ticketChannelOverwrites };