MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / reopenTicket

Function reopenTicket

src/services/ticket.js:545–672  ·  view source on GitHub ↗
(channel, reopener)

Source from the content-addressed store, hash-verified

543}
544
545export async function reopenTicket(channel, reopener) {
546 try {
547 const ticketData = await getTicketData(channel.guild.id, channel.id);
548 if (!ticketData) {
549 return { success: false, error: 'This is not a ticket channel' };
550 }
551
552 if (ticketData.status !== 'closed') {
553 return {
554 success: false,
555 error: 'This ticket is not currently closed'
556 };
557 }
558
559 const config = await getGuildConfig(channel.client, channel.guild.id);
560 const openCategoryId = config.ticketCategoryId || null;
561 let movedToOpenCategory = false;
562 let openCategoryMoveFailed = false;
563
564 ticketData.status = 'open';
565 ticketData.closedBy = null;
566 ticketData.closedAt = null;
567 ticketData.closeReason = null;
568
569 await saveTicketData(channel.guild.id, channel.id, ticketData);
570
571 if (openCategoryId && channel.parentId !== openCategoryId) {
572 const openCategory = channel.guild.channels.cache.get(openCategoryId)
573 || await channel.guild.channels.fetch(openCategoryId).catch(() => null);
574
575 if (openCategory?.type === ChannelType.GuildCategory) {
576 try {
577 await channel.setParent(openCategoryId, { lockPermissions: false });
578 movedToOpenCategory = true;
579 } catch (moveError) {
580 openCategoryMoveFailed = true;
581 logger.warn(`Could not move reopened ticket ${channel.id} to open category ${openCategoryId}: ${moveError.message}`);
582 }
583 } else {
584 openCategoryMoveFailed = true;
585 logger.warn(`Configured open ticket category is invalid for guild ${channel.guild.id}: ${openCategoryId}`);
586 }
587 }
588
589 try {
590 const user = await channel.guild.members.fetch(ticketData.userId).catch(() => null);
591 if (user) {
592 await channel.permissionOverwrites.create(user, {
593 ViewChannel: true,
594 SendMessages: true,
595 ReadMessageHistory: true,
596 AttachFiles: true
597 });
598 }
599 } catch (error) {
600 logger.warn(`Could not restore access for user ${ticketData.userId}:`, error.message);
601 }
602

Callers 1

executeFunction · 0.85

Calls 8

getTicketDataFunction · 0.90
getGuildConfigFunction · 0.90
saveTicketDataFunction · 0.90
createEmbedFunction · 0.90
ensureTypedServiceErrorFunction · 0.90
buildTicketControlRowFunction · 0.85
editMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected