/** * Shared transcript rendering for the two close paths * (handlers/buttons.js runFinalClose and handlers/commands/close.js postTranscript). * Pure formatting only — each caller owns its own posting / DB / email side effects. */ const { CONFIG } = require('../config'); /** Render the last 100 messages of a channel as a plaintext transcript. */ async function buildTranscriptText(channel, ticket) { const messages = await channel.messages.fetch({ limit: 100 }); return `TRANSCRIPT: ${ticket.subject}\nUser: ${ticket.senderEmail}\n---\n` + messages .reverse() .map(m => `[${m.createdAt.toLocaleString()}] ${m.author.tag}: ${m.cleanContent}`) .join('\n'); } /** Format a date for the transcript header (US locale, 12h, with time zone). */ function formatDateForTranscript(d) { return new Date(d).toLocaleString('en-US', { month: '2-digit', day: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: true, timeZoneName: 'short' }); } /** Build the transcript-channel message body from DISCORD_TRANSCRIPT_MESSAGE. */ function renderTranscriptHeader(channelName, senderEmail, openedStr, closedStr) { return CONFIG.DISCORD_TRANSCRIPT_MESSAGE .replace(/\{channel_name\}/g, channelName) .replace(/\{email\}/g, senderEmail || '') .replace(/\{date_opened\}/g, openedStr) .replace(/\{date_closed\}/g, closedStr) + `\n\nDate Opened: ${openedStr}\nDate Closed: ${closedStr}`; } module.exports = { buildTranscriptText, formatDateForTranscript, renderTranscriptHeader };