From 9231925413de072c34325e602c14f5abeabc1853 Mon Sep 17 00:00:00 2001 From: dev-737 <73829355+dev-737@users.noreply.github.com> Date: Mon, 12 Jun 2023 08:49:41 +0530 Subject: [PATCH] fix(hub join): fix "invalid connection" bug --- src/Scripts/hub/join.ts | 4 ++-- src/Scripts/network/initialize.ts | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Scripts/hub/join.ts b/src/Scripts/hub/join.ts index eb0834fe..56c64888 100644 --- a/src/Scripts/hub/join.ts +++ b/src/Scripts/hub/join.ts @@ -111,6 +111,6 @@ export async function execute(interaction: ChatInputCommandInteraction) { } // TODO: make an onboarding function and show them rules and stuff - await initialize.execute(interaction, hubExists, channel); - await displaySettings.execute(interaction, channel.id); + initialize.execute(interaction, hubExists, channel) + .then(success => { if (success) displaySettings.execute(interaction, channel.id); }); } diff --git a/src/Scripts/network/initialize.ts b/src/Scripts/network/initialize.ts index 28159015..f72ed7aa 100644 --- a/src/Scripts/network/initialize.ts +++ b/src/Scripts/network/initialize.ts @@ -12,17 +12,16 @@ export = { async execute(interaction: ChatInputCommandInteraction, hub: hubs, networkChannel: GuildTextBasedChannel) { const emoji = interaction.client.emotes.normal; - const interactionReply = interaction.deferred || interaction.replied - ? interaction.followUp - : interaction.reply; - + // Check if server is already attempting to join a hub if (onboardingInProgress.has(networkChannel.id)) { - await interactionReply(`${emoji.no} Another setup for ${networkChannel} is already in progress.`); + const err = `${emoji.no} There has already been an attempt to join a hub in ${networkChannel}. Please wait for that to finish before trying again!`; + interaction.deferred || interaction.replied + ? interaction.followUp(err) + : interaction.reply(err); return; } - // Mark this setup as in-progress so server can't setup twice - onboardingInProgress.set(interaction.channelId, interaction.channelId); - + // Mark this as in-progress so server can't join twice + onboardingInProgress.set(networkChannel.id, networkChannel.id); // Show new users rules & info about network const onboardingStatus = await onboarding.execute(interaction); @@ -67,10 +66,16 @@ export = { catch (err: any) { logger.error(err); if (err.message === 'Missing Permissions' || err.message === 'Missing Access') { - interactionReply(`${emoji.no} Please make sure you have granted me \`Manage Webhooks\` and \`View Channel\` permissions for the selected channel.`); + const errMsg = `${emoji.no} Please make sure you have granted me \`Manage Webhooks\` and \`View Channel\` permissions for the selected channel.`; + interaction.deferred || interaction.replied + ? interaction.followUp(errMsg) + : interaction.reply(errMsg); } else { - interactionReply(`An error occurred while connecting to the InterChat network! \`\`\`js\n${err.message}\`\`\``); + const errMsg = `An error occurred while connecting to the InterChat network! \`\`\`js\n${err.message}\`\`\``; + interaction.deferred || interaction.replied + ? interaction.followUp(errMsg) + : interaction.reply(errMsg); } onboardingInProgress.delete(networkChannel.id); disconnect(networkChannel.id); @@ -83,5 +88,6 @@ export = { **Server Name:** __${interaction.guild?.name}__ **Member Count:** __${interaction.guild?.memberCount}__ `, { id: hub.id }); + return true; // just a marker to show that the setup was successful }, };