simplify: rename CONFIG channels, dedup hasStaffRole, drop enforceEmbedLimit

- Rename CONFIG.TRANSCRIPT_CHAN -> CONFIG.TRANSCRIPT_CHANNEL_ID and
  CONFIG.LOG_CHAN -> CONFIG.LOGGING_CHANNEL_ID across 9 callsites so
  CONFIG keys match their .env names — no more "grep .env, find nothing"
  for new readers
- Replace handlers/commands.js#hasStaffRole with utils.js#isStaff
  (was a verbatim copy)
- Delete utils.js#enforceEmbedLimit and its 2 callsites; both inputs are
  bounded well under the 6000-char Discord embed cap, so the trim was
  defensive code that never fired

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-07 18:45:18 +00:00
parent 840b6bfcf8
commit 83b6b4ae0c
6 changed files with 15 additions and 105 deletions

View File

@@ -19,7 +19,7 @@ const { CONFIG } = require('../config');
const { makeTicketName, resolveCreatorNickname, getOrCreateTicketCategory, cleanupEmptyOverflowCategory, checkTicketCreationRateLimit, toDiscordSafeName } = require('../services/tickets');
const { sendTicketClosedEmail } = require('../services/gmail');
const { getTicketActionRow } = require('../utils/ticketComponents');
const { sanitizeEmbedText, truncateEmbedDescription, enforceEmbedLimit } = require('../utils');
const { sanitizeEmbedText, truncateEmbedDescription } = require('../utils');
const { enqueueRename, enqueueSend } = require('../services/channelQueue');
const { runEscalation, runDeescalation } = require('./commands');
const { pendingCloses } = require('./pendingCloses');
@@ -470,7 +470,7 @@ async function handleConfirmClose(interaction, ticket, sendEmail = true) {
await enqueueSend(interaction.channel, discordCloseContent);
const transcriptChan = await interaction.client.channels
.fetch(CONFIG.TRANSCRIPT_CHAN)
.fetch(CONFIG.TRANSCRIPT_CHANNEL_ID)
.catch(() => null);
let transcriptMsg = null;
@@ -516,7 +516,7 @@ async function handleConfirmClose(interaction, ticket, sendEmail = true) {
}
const logChan = await interaction.client.channels
.fetch(CONFIG.LOG_CHAN)
.fetch(CONFIG.LOGGING_CHANNEL_ID)
.catch(() => null);
if (logChan) {
const closerMention = interaction.user.toString();
@@ -682,7 +682,6 @@ async function handleTicketModal(interaction) {
const actionRow = getTicketActionRow({ escalationTier: 0 });
enforceEmbedLimit([welcomeEmbed, infoEmbed, resourcesEmbed]);
let welcomeMsg;
try {
welcomeMsg = await enqueueSend(channel, {
@@ -709,7 +708,7 @@ async function handleTicketModal(interaction) {
await interaction.deleteReply().catch(() => {});
const logChan = await interaction.client.channels.fetch(CONFIG.LOG_CHAN).catch(() => null);
const logChan = await interaction.client.channels.fetch(CONFIG.LOGGING_CHANNEL_ID).catch(() => null);
if (logChan) {
await enqueueSend(logChan,
`📝 ${channel.name} created by ${interaction.user.tag}`

View File

@@ -11,7 +11,7 @@ const {
} = require('discord.js');
const { mongoose } = require('../db-connection');
const { CONFIG } = require('../config');
const { getPriorityEmoji, replaceVariables } = require('../utils');
const { getPriorityEmoji, replaceVariables, isStaff } = require('../utils');
const { makeTicketName, resolveCreatorNickname, getOrCreateTicketCategory, checkTicketCreationRateLimit } = require('../services/tickets');
const { sendTicketNotificationEmail } = require('../services/gmail');
const { getTicketActionRow } = require('../utils/ticketComponents');
@@ -23,19 +23,6 @@ const { pendingCloses } = require('./pendingCloses');
const Ticket = mongoose.model('Ticket');
const Tag = mongoose.model('Tag');
/**
* True if member has the support role (ROLE_ID_TO_PING) or any ADDITIONAL_STAFF_ROLES.
* Used to restrict commands to staff only; customers cannot use bot commands.
* @param {import('discord.js').GuildMember|null} member
* @returns {boolean}
*/
function hasStaffRole(member) {
if (!member?.roles?.cache) return false;
if (CONFIG.ROLE_ID_TO_PING && member.roles.cache.has(CONFIG.ROLE_ID_TO_PING)) return true;
const additional = CONFIG.ADDITIONAL_STAFF_ROLES || [];
return additional.some(roleId => member.roles.cache.has(roleId));
}
/**
* Reply ephemeral and return true if the interaction is in a guild and the user is not staff (so caller should return).
* @param {import('discord.js').CommandInteraction|import('discord.js').ContextMenuCommandInteraction} interaction
@@ -44,7 +31,7 @@ function hasStaffRole(member) {
async function requireStaffRole(interaction) {
if (!interaction.guild) return false;
if (!CONFIG.ROLE_ID_TO_PING && (!CONFIG.ADDITIONAL_STAFF_ROLES || CONFIG.ADDITIONAL_STAFF_ROLES.length === 0)) return false;
if (hasStaffRole(interaction.member)) return false;
if (isStaff(interaction.member)) return false;
const roleMention = CONFIG.ROLE_ID_TO_PING ? `<@&${CONFIG.ROLE_ID_TO_PING}>` : 'support';
await interaction.reply({
content: `This command is only available to the support team (${roleMention}).`,
@@ -149,7 +136,7 @@ async function runEscalation(interaction, ticket, nextTier, reason) {
}
const logChan = await interaction.client.channels
.fetch(CONFIG.LOG_CHAN)
.fetch(CONFIG.LOGGING_CHANNEL_ID)
.catch(() => null);
if (logChan) {
const ticketType = isDiscordTicket ? 'Discord' : 'Email';
@@ -203,7 +190,7 @@ async function runDeescalation(interaction, ticket) {
.setFooter({ text: interaction.member?.displayName || interaction.user.username });
await interaction.editReply({ embeds: [deescalateEmbed] });
const logChan = await interaction.client.channels.fetch(CONFIG.LOG_CHAN).catch(() => null);
const logChan = await interaction.client.channels.fetch(CONFIG.LOGGING_CHANNEL_ID).catch(() => null);
if (logChan) {
const ticketType = isDiscordTicket ? 'Discord' : 'Email';
await enqueueSend(logChan,
@@ -373,7 +360,7 @@ async function handleCommand(interaction) {
allowedMentions: { parse: ['users'] }
});
const logChan = await interaction.client.channels.fetch(CONFIG.LOG_CHAN).catch(() => null);
const logChan = await interaction.client.channels.fetch(CONFIG.LOGGING_CHANNEL_ID).catch(() => null);
if (logChan) {
await enqueueSend(logChan, {
content: `Ticket ${interaction.channel} transferred from ${interaction.user.tag} to ${member.tag}.\nReason: ${reason}`,
@@ -400,7 +387,7 @@ async function handleCommand(interaction) {
await interaction.channel.setParent(category.id, { lockPermissions: true });
await interaction.reply(`Moved ticket to **${category.name}**.`);
const logChan = await interaction.client.channels.fetch(CONFIG.LOG_CHAN).catch(() => null);
const logChan = await interaction.client.channels.fetch(CONFIG.LOGGING_CHANNEL_ID).catch(() => null);
if (logChan) {
await enqueueSend(logChan,
`Ticket ${interaction.channel} moved to category **${category.name}** by ${interaction.user.tag}`
@@ -530,7 +517,7 @@ async function handleCommand(interaction) {
});
const transcriptChan = await clientRef.channels
.fetch(CONFIG.TRANSCRIPT_CHAN)
.fetch(CONFIG.TRANSCRIPT_CHANNEL_ID)
.catch(() => null);
if (transcriptChan) {