From a88c9944326734e13af4a19facf3ecddd90c710c Mon Sep 17 00:00:00 2001 From: PadBro Date: Sun, 28 Dec 2025 12:55:58 +0100 Subject: [PATCH] fix(application): timeout after leave --- commands/utils/apply/index.js | 14 ++- events/application.js | 165 ++++++++++++++++++++++------------ 2 files changed, 119 insertions(+), 60 deletions(-) diff --git a/commands/utils/apply/index.js b/commands/utils/apply/index.js index 5fbaaed..b3c27cd 100644 --- a/commands/utils/apply/index.js +++ b/commands/utils/apply/index.js @@ -51,7 +51,7 @@ export const handleApplication = async (interaction, applicationId) => { 'Thank you for starting an application process' ); } catch (e) { - Logger.error('cannot send direct message: ' + e); + Logger.error('Cannot send direct message: ' + e); await interaction.editReply({ embeds: [closedDmEmbed], flags: MessageFlags.Ephemeral, @@ -194,9 +194,15 @@ const handleError = async ( .setTitle(`Error`) .setDescription(errorMessage) .setColor('#ce361e'); - await channel.send({ - embeds: [embed], - }); + try { + await channel.send({ + embeds: [embed], + }); + } catch (e) { + Logger.error( + 'An error occourred sending the error message to the user: ' + e + ); + } if (logError) { Logger.error(logMessage); } diff --git a/events/application.js b/events/application.js index 4bbe77a..9b03951 100644 --- a/events/application.js +++ b/events/application.js @@ -15,6 +15,8 @@ import { loadMessage } from '../utils/loadMessage.js'; import Paginate from '../commands/utils/paginate.js'; import dayjs from 'dayjs'; import { handleApplication } from '../commands/utils/apply/index.js'; +import { replyError } from '../utils/replyError.js'; +import Logger from '../utils/logger.js'; export const applicationHandler = async (interaction) => { if (interaction.isModalSubmit()) { @@ -40,19 +42,35 @@ const handleModal = async (interaction) => { const reason = interaction.fields.getTextInputValue('reason'); if (action === 'acceptWithReason') { - await interaction.reply({ - content: 'Accepting application', - flags: MessageFlags.Ephemeral, - }); - acceptApplicationSubmission(id, interaction.user.id, null, reason); - } - - if (action === 'denyWithReason') { - await interaction.reply({ - content: 'Denying application', - flags: MessageFlags.Ephemeral, - }); - denyApplicationSubmission(id, interaction.user.id, null, reason); + await interaction.deferReply({ flags: MessageFlags.Ephemeral }); + try { + await acceptApplicationSubmission(id, interaction.user.id, null, reason); + await interaction.followUp({ + content: 'Application accepted', + flags: MessageFlags.Ephemeral, + }); + } catch (e) { + handleError( + interaction, + 'Could not accept application. Please report to the staff team', + `An error occoured while accepting submission ${id}: ${e}` + ); + } + } else if (action === 'denyWithReason') { + await interaction.deferReply({ flags: MessageFlags.Ephemeral }); + try { + await denyApplicationSubmission(id, interaction.user.id, null, reason); + await interaction.followUp({ + content: 'Application denied', + flags: MessageFlags.Ephemeral, + }); + } catch (e) { + handleError( + interaction, + 'Could not deny application. Please report to the staff team', + `An error occoured while denying submission ${id}: ${e}` + ); + } } }; @@ -67,22 +85,36 @@ const handleButtons = async (interaction) => { const id = match[2]; // id if (action === 'accept') { - await interaction.reply({ - content: 'Accepting application', - flags: MessageFlags.Ephemeral, - }); - acceptApplicationSubmission(id, interaction.user.id); - } - - if (action === 'deny') { - await interaction.reply({ - content: 'Denying application', - flags: MessageFlags.Ephemeral, - }); - denyApplicationSubmission(id, interaction.user.id); - } - - if (action === 'acceptWithReason') { + await interaction.deferReply({ flags: MessageFlags.Ephemeral }); + try { + await acceptApplicationSubmission(id, interaction.user.id); + await interaction.followUp({ + content: 'Application accepted', + flags: MessageFlags.Ephemeral, + }); + } catch (e) { + handleError( + interaction, + 'Could not accept application. Please report to the staff team', + `An error occoured while accepting submission ${id}: ${e}` + ); + } + } else if (action === 'deny') { + await interaction.deferReply({ flags: MessageFlags.Ephemeral }); + try { + await denyApplicationSubmission(id, interaction.user.id); + await interaction.followUp({ + content: 'Application denied', + flags: MessageFlags.Ephemeral, + }); + } catch (e) { + handleError( + interaction, + 'Could not deny application. Please report to the staff team', + `An error occoured while denying submission ${id}: ${e}` + ); + } + } else if (action === 'acceptWithReason') { const modal = new ModalBuilder() .setCustomId(`applicationSubmission-acceptWithReason-${id}`) .setTitle('Accept application with reason'); @@ -96,9 +128,7 @@ const handleButtons = async (interaction) => { modal.addComponents(answerActionRow); await interaction.showModal(modal); - } - - if (action === 'denyWithReason') { + } else if (action === 'denyWithReason') { const modal = new ModalBuilder() .setCustomId(`applicationSubmission-denyWithReason-${id}`) .setTitle('Deny application with reason'); @@ -112,13 +142,9 @@ const handleButtons = async (interaction) => { modal.addComponents(answerActionRow); await interaction.showModal(modal); - } - - if (action === 'start') { + } else if (action === 'start') { handleApplication(interaction, id); - } - - if (action === 'history') { + } else if (action === 'history') { await interaction.deferReply({ flags: MessageFlags.Ephemeral }); const history = await getApplicationSubmissionHistory(id); @@ -199,26 +225,53 @@ const handleSelectMenu = async (interaction) => { const templateId = interaction.values[0]; if (action === 'acceptTemplate') { - await interaction.reply({ - content: 'Accepting application', - flags: MessageFlags.Ephemeral, - }); - acceptApplicationSubmission( - applicationSubmissionid, - interaction.user.id, - templateId - ); + await interaction.deferReply({ flags: MessageFlags.Ephemeral }); + try { + await acceptApplicationSubmission( + applicationSubmissionid, + interaction.user.id, + templateId + ); + await interaction.followUp({ + content: 'Application accepted', + flags: MessageFlags.Ephemeral, + }); + } catch (e) { + handleError( + interaction, + 'Could not accept application. Please report to the staff team', + `An error occoured while accepting submission ${applicationSubmissionid}: ${e}` + ); + } + } else if (action === 'denyTemplate') { + await interaction.deferReply({ flags: MessageFlags.Ephemeral }); + try { + await denyApplicationSubmission( + applicationSubmissionid, + interaction.user.id, + templateId + ); + await interaction.followUp({ + content: 'Application denied', + flags: MessageFlags.Ephemeral, + }); + } catch (e) { + handleError( + interaction, + 'Could not deny application. Please report to the staff team', + `An error occoured while denying submission ${applicationSubmissionid}: ${e}` + ); + } } +}; - if (action === 'denyTemplate') { - await interaction.reply({ - content: 'Denying application', - flags: MessageFlags.Ephemeral, - }); - denyApplicationSubmission( - applicationSubmissionid, - interaction.user.id, - templateId +const handleError = async (interaction, errorMessage, logMessage) => { + try { + replyError(interaction, errorMessage); + } catch (e) { + Logger.error( + 'An error occourred sending the error message to the user: ' + e ); } + Logger.error(logMessage); };