(interaction)
| 578 | } |
| 579 | |
| 580 | export async function handleApplicationReviewModal(interaction) { |
| 581 | if (!interaction.isModalSubmit()) return; |
| 582 | |
| 583 | const customId = interaction.customId; |
| 584 | if (!customId.startsWith('app_review_')) return; |
| 585 | |
| 586 | const [, appId, action] = customId.split('_'); |
| 587 | const reason = interaction.fields.getTextInputValue('reason') || 'No reason provided.'; |
| 588 | const isApprove = action === 'approve'; |
| 589 | |
| 590 | try { |
| 591 | const application = await getApplication(interaction.client, interaction.guild.id, appId); |
| 592 | if (!application) { |
| 593 | return await replyUserError(interaction, { type: ErrorTypes.USER_INPUT, message: 'Application not found.' }); |
| 594 | } |
| 595 | |
| 596 | const status = isApprove ? 'approved' : 'denied'; |
| 597 | await updateApplication(interaction.client, interaction.guild.id, appId, { |
| 598 | status, |
| 599 | reviewer: interaction.user.id, |
| 600 | reviewMessage: reason, |
| 601 | reviewedAt: new Date().toISOString() |
| 602 | }); |
| 603 | |
| 604 | try { |
| 605 | const user = await interaction.client.users.fetch(application.userId); |
| 606 | const reviewStatus = getApplicationStatusPresentation(status); |
| 607 | const dmEmbed = createEmbed( |
| 608 | `${reviewStatus.statusEmoji} Application ${reviewStatus.statusLabel}`, |
| 609 | `Your application for **${application.roleName}** has been **${status}**.\n` + |
| 610 | `**Note:** ${reason}\n\n` + |
| 611 | `Use \`/apply status id:${appId}\` to view details.`, |
| 612 | isApprove ? '#00FF00' : '#FF0000' |
| 613 | ); |
| 614 | |
| 615 | await user.send({ embeds: [dmEmbed] }); |
| 616 | } catch (error) { |
| 617 | logger.error('Error sending DM to user:', error); |
| 618 | } |
| 619 | |
| 620 | if (application.logMessageId && application.logChannelId) { |
| 621 | try { |
| 622 | const logChannel = interaction.guild.channels.cache.get(application.logChannelId); |
| 623 | if (logChannel) { |
| 624 | const logMessage = await logChannel.messages.fetch(application.logMessageId); |
| 625 | if (logMessage) { |
| 626 | const embed = logMessage.embeds[0]; |
| 627 | if (embed) { |
| 628 | const reviewStatus = getApplicationStatusPresentation(status); |
| 629 | const newEmbed = EmbedBuilder.from(embed) |
| 630 | .setColor(isApprove ? '#00FF00' : '#FF0000') |
| 631 | .spliceFields(0, 1, { |
| 632 | name: 'Status', |
| 633 | value: `${reviewStatus.statusEmoji} ${reviewStatus.statusLabel}` |
| 634 | }); |
| 635 | |
| 636 | await logMessage.edit({ |
| 637 | embeds: [newEmbed], |
no test coverage detected