From d39b59aa4a8a1dc752fa8f2699e4ff40250f6f2a Mon Sep 17 00:00:00 2001 From: Patrick Gallagher Date: Fri, 1 Oct 2021 00:45:51 -0500 Subject: [PATCH] Add try/catch guards to attempts to delete active vote messages --- src/commands/tenmans.ts | 53 ++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/src/commands/tenmans.ts b/src/commands/tenmans.ts index c0f70ba..07719ed 100644 --- a/src/commands/tenmans.ts +++ b/src/commands/tenmans.ts @@ -99,7 +99,11 @@ abstract class VoteQueueAction< class JoinQueueButtonAction extends StandardQueueAction { async updateQueue(): Promise { - if (tenmansQueue.some(queueUser => this.user.discordId === queueUser.discordId)) { + if ( + tenmansQueue.some( + (queueUser) => this.user.discordId === queueUser.discordId + ) + ) { this.interaction.reply({ content: "Who are you? Copy of me?! You're already in the queue!", ephemeral: true, @@ -158,7 +162,11 @@ class VoteQueueButtonAction extends VoteQueueAction { return false; } - if (tenmansQueue.some(queueUser => this.user.discordId === queueUser.discordId)) { + if ( + tenmansQueue.some( + (queueUser) => this.user.discordId === queueUser.discordId + ) + ) { this.interaction.reply({ content: "Who are you? Copy of me?! You've already voted!", ephemeral: true, @@ -176,18 +184,23 @@ class VoteQueueButtonAction extends VoteQueueAction { if (tenmansQueue.length >= botConfig.minVoteCount) { // Generate proper interactable queue once min votes reached - await activeVoteMessage.delete(); - voteClosingTime = null; - activeVoteMessage = null; + try { + await activeVoteMessage.delete(); - activeTenmansMessage = await queueChannel.send({ - embeds: [createEmbed(time)], - components: [createQueueActionRow(this.queueId)], - }); + voteClosingTime = null; + activeVoteMessage = null; - await queueChannel.send({ - content: `<@${roleId}> that Radianite must be ours! A queue has been created!`, - }); + activeTenmansMessage = await queueChannel.send({ + embeds: [createEmbed(time)], + components: [createQueueActionRow(this.queueId)], + }); + + await queueChannel.send({ + content: `<@${roleId}> that Radianite must be ours! A queue has been created!`, + }); + } catch (e) { + console.error(e); + } return false; } @@ -292,7 +305,11 @@ class TenmansCloseSubcommand extends MessageExecutable { // Teardown - clear current queue tenmansQueue = []; - await activeTenmansMessage?.delete(); + try { + await activeTenmansMessage?.delete(); + } catch (e) { + console.error(e); + } } } @@ -342,9 +359,7 @@ class TenmansVoteSubcommand extends RegisteredUserExecutable const votesStillNeeded = botConfig.minVoteCount - tenmansQueue.length; activeVoteMessage = await queueChannel.send({ - embeds: [ - createVoteEmbed(votesStillNeeded, time, voteClosingTime), - ], + embeds: [createVoteEmbed(votesStillNeeded, time, voteClosingTime)], components: [createVoteQueueActionRow(queueId)], }); @@ -494,7 +509,11 @@ export async function handleVoteCleaning() { if (activeVoteMessage) { // Close vote if it has expired if (voteClosingTime < new Date()) { - await activeVoteMessage.delete(); + try { + await activeVoteMessage.delete(); + } catch (e) { + console.error(e); + } tenmansQueue = []; voteClosingTime = null;