Skip to content

Commit

Permalink
fix(hub join): fix "invalid connection" bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Jun 12, 2023
1 parent 6c3de66 commit 9231925
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Scripts/hub/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
}
26 changes: 16 additions & 10 deletions src/Scripts/network/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
},
};

0 comments on commit 9231925

Please sign in to comment.