(channel, reopener)
| 543 | } |
| 544 | |
| 545 | export 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 |
no test coverage detected