88 lines
3.0 KiB
JavaScript
88 lines
3.0 KiB
JavaScript
const { CONFIG } = require('../config');
|
|
|
|
/**
|
|
* Create a staff tracking channel for a ticket.
|
|
* Returns the created channel or null if no staff category configured.
|
|
*/
|
|
async function createStaffChannel(guild, ticket, claimerId, channelName) {
|
|
const categoryId = CONFIG.STAFF_CATEGORIES.get(claimerId);
|
|
if (!categoryId) return null;
|
|
|
|
try {
|
|
const { ChannelType } = require('discord.js');
|
|
const staffChan = await guild.channels.create({
|
|
name: channelName,
|
|
type: ChannelType.GuildText,
|
|
parent: categoryId
|
|
});
|
|
|
|
// Build pinned embed with ticket info + jump link to original ticket channel
|
|
const { EmbedBuilder } = require('discord.js');
|
|
const originalChannel = await guild.channels.fetch(ticket.discordThreadId).catch(() => null);
|
|
const jumpLink = originalChannel ? `https://discord.com/channels/${guild.id}/${ticket.discordThreadId}` : null;
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setTitle(`🎫 Ticket #${ticket.ticketNumber}`)
|
|
.setColor(0x5865f2)
|
|
.addFields(
|
|
{ name: 'Customer', value: ticket.senderEmail || 'Unknown', inline: true },
|
|
{ name: 'Game', value: ticket.game || 'Not detected', inline: true },
|
|
{ name: 'Subject', value: ticket.subject || 'No subject', inline: false },
|
|
{ name: 'Original Ticket', value: jumpLink ? `[Jump to ticket](${jumpLink})` : 'Unknown', inline: false }
|
|
)
|
|
.setFooter({ text: `Claimed by ${ticket.claimedBy || 'Unknown'}` })
|
|
.setTimestamp();
|
|
|
|
const pinMsg = await staffChan.send({ embeds: [embed] });
|
|
await pinMsg.pin().catch(() => {});
|
|
|
|
return staffChan;
|
|
} catch (e) {
|
|
console.error('Failed to create staff channel:', e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Ping the staff channel with a customer reply, including jump link and message copy.
|
|
*/
|
|
async function pingStaffChannel(staffChannel, claimerId, originalMessage) {
|
|
if (!staffChannel) return;
|
|
try {
|
|
const jumpLink = `https://discord.com/channels/${originalMessage.guild.id}/${originalMessage.channel.id}/${originalMessage.id}`;
|
|
await staffChannel.send(
|
|
`<@${claimerId}> Customer replied in ticket:\n> ${originalMessage.content.slice(0, 500)}\n[Jump to message](${jumpLink})`
|
|
);
|
|
} catch (e) {
|
|
console.error('Failed to ping staff channel:', e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Move staff channel to a different category.
|
|
*/
|
|
async function moveStaffChannel(staffChannel, categoryId) {
|
|
if (!staffChannel || !categoryId) return;
|
|
try {
|
|
const { enqueueMove } = require('./channelQueue');
|
|
await enqueueMove(staffChannel, categoryId);
|
|
} catch (e) {
|
|
console.error('Failed to move staff channel:', e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Delete the staff tracking channel.
|
|
*/
|
|
async function deleteStaffChannel(guild, staffChannelId) {
|
|
if (!staffChannelId) return;
|
|
try {
|
|
const chan = await guild.channels.fetch(staffChannelId).catch(() => null);
|
|
if (chan) await chan.delete();
|
|
} catch (e) {
|
|
console.error('Failed to delete staff channel:', e);
|
|
}
|
|
}
|
|
|
|
module.exports = { createStaffChannel, pingStaffChannel, moveStaffChannel, deleteStaffChannel };
|