(interaction)
| 114 | }; |
| 115 | |
| 116 | export async function handleApplicationModal(interaction) { |
| 117 | if (!interaction.isModalSubmit()) return; |
| 118 | |
| 119 | const customId = interaction.customId; |
| 120 | if (!customId.startsWith('app_modal_')) return; |
| 121 | |
| 122 | const roleId = customId.split('_')[2]; |
| 123 | |
| 124 | const applicationRoles = await getApplicationRoles(interaction.client, interaction.guild.id); |
| 125 | const applicationRole = applicationRoles.find(appRole => appRole.roleId === roleId); |
| 126 | |
| 127 | if (!applicationRole) { |
| 128 | return await replyUserError(interaction, { type: ErrorTypes.CONFIGURATION, message: 'Application configuration not found.' }); |
| 129 | } |
| 130 | |
| 131 | const role = interaction.guild.roles.cache.get(roleId); |
| 132 | |
| 133 | if (!role) { |
| 134 | return await replyUserError(interaction, { type: ErrorTypes.USER_INPUT, message: 'Role not found.' }); |
| 135 | } |
| 136 | |
| 137 | const answers = []; |
| 138 | const settings = await getApplicationSettings(interaction.client, interaction.guild.id); |
| 139 | |
| 140 | let questions = settings.questions || ["Why do you want this role?", "What is your experience?"]; |
| 141 | const roleSettings = await getApplicationRoleSettings(interaction.client, interaction.guild.id, roleId); |
| 142 | if (roleSettings.questions && roleSettings.questions.length > 0) { |
| 143 | questions = roleSettings.questions; |
| 144 | } |
| 145 | |
| 146 | for (let i = 0; i < questions.length; i++) { |
| 147 | const answer = interaction.fields.getTextInputValue(`q${i}`); |
| 148 | answers.push({ |
| 149 | question: questions[i], |
| 150 | answer: answer |
| 151 | }); |
| 152 | } |
| 153 | |
| 154 | try { |
| 155 | const application = await ApplicationService.submitApplication(interaction.client, { |
| 156 | guildId: interaction.guild.id, |
| 157 | userId: interaction.user.id, |
| 158 | roleId: roleId, |
| 159 | roleName: applicationRole.name, |
| 160 | username: interaction.user.tag, |
| 161 | avatar: interaction.user.displayAvatarURL(), |
| 162 | answers: answers |
| 163 | }); |
| 164 | |
| 165 | const embed = successEmbed( |
| 166 | 'Application Submitted', |
| 167 | `Your application for **${applicationRole.name}** has been submitted successfully!\n\n` + |
| 168 | `Application ID: \`${application.id}\`\n` + |
| 169 | `You can check the status with \`/apply status id:${application.id}\`` |
| 170 | ); |
| 171 | |
| 172 | await InteractionHelper.safeEditReply(interaction, { embeds: [embed], flags: ["Ephemeral"] }); |
| 173 |
no test coverage detected