(interaction)
| 481 | } |
| 482 | |
| 483 | async function handleList(interaction) { |
| 484 | const status = interaction.options.getString("status"); |
| 485 | const user = interaction.options.getUser("user"); |
| 486 | const limit = interaction.options.getNumber("limit") || 10; |
| 487 | |
| 488 | const filters = {}; |
| 489 | |
| 490 | if (status) { |
| 491 | filters.status = status; |
| 492 | } else { |
| 493 | filters.status = 'pending'; |
| 494 | } |
| 495 | |
| 496 | let applications = await getApplications( |
| 497 | interaction.client, |
| 498 | interaction.guild.id, |
| 499 | filters, |
| 500 | ); |
| 501 | |
| 502 | if (!user) { |
| 503 | applications = await Promise.all( |
| 504 | applications.map(async (app) => { |
| 505 | try { |
| 506 | await interaction.guild.members.fetch(app.userId); |
| 507 | return app; |
| 508 | } catch { |
| 509 | |
| 510 | await deleteApplication(interaction.client, interaction.guild.id, app.id, app.userId); |
| 511 | return null; |
| 512 | } |
| 513 | }) |
| 514 | ).then(results => results.filter(Boolean)); |
| 515 | } |
| 516 | |
| 517 | if (user) { |
| 518 | applications = applications.filter((app) => app.userId === user.id); |
| 519 | } |
| 520 | |
| 521 | if (applications.length === 0) { |
| 522 | const applicationRoles = await getApplicationRoles(interaction.client, interaction.guild.id); |
| 523 | |
| 524 | if (applicationRoles.length > 0) { |
| 525 | const embed = createEmbed({ |
| 526 | title: "No Applications Found", |
| 527 | description: "No submitted applications found matching the specified criteria.\n\nHowever, the following application roles are configured:" |
| 528 | }); |
| 529 | |
| 530 | applicationRoles.forEach((appRole, index) => { |
| 531 | const role = interaction.guild.roles.cache.get(appRole.roleId); |
| 532 | embed.addFields({ |
| 533 | name: `${index + 1}. ${appRole.name}`, |
| 534 | value: `**Role:** ${role ?`<@&${appRole.roleId}>`: 'Role not found'}\n**Available for applications:** Yes`, |
| 535 | inline: false |
| 536 | }); |
| 537 | }); |
| 538 | |
| 539 | embed.setFooter({ |
| 540 | text: "Users can apply with /apply submit or see available roles with /apply list" |
no test coverage detected