Skip to content

Commit

Permalink
fix(hub): fix onboarding marker deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Aug 29, 2023
1 parent 5102b86 commit 2cd3b8a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
5 changes: 2 additions & 3 deletions src/Scripts/hub/join.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChatInputCommandInteraction, ChannelType } from 'discord.js';
import { getDb } from '../../Utils/functions/utils';
import initialize from '../network/initialize';
import createConnection from '../network/createConnection';
import displaySettings from '../network/displaySettings';

export async function execute(interaction: ChatInputCommandInteraction) {
Expand Down Expand Up @@ -111,7 +111,6 @@ export async function execute(interaction: ChatInputCommandInteraction) {
return;
}

// TODO: make an onboarding function and show them rules and stuff
initialize.execute(interaction, hubExists, channel)
createConnection.execute(interaction, hubExists, channel)
.then(success => { if (success) displaySettings.execute(interaction, success.channelId); });
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import { getDb } from '../../Utils/functions/utils';

const onboardingInProgress = new Collection<string, string>();

export = {
export default {
async execute(interaction: ChatInputCommandInteraction, hub: hubs, networkChannel: TextChannel | ThreadChannel) {
const emoji = interaction.client.emotes.normal;

// Check if server is already attempting to join a hub
if (onboardingInProgress.has(networkChannel.id)) {
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!`;
const err = {
content: `${emoji.no} There has already been an attempt to join a hub in ${networkChannel}. Please wait for that to finish before trying again!`,
ephemeral: true,
};
interaction.deferred || interaction.replied
? interaction.followUp(err)
: interaction.reply(err);
Expand All @@ -24,11 +27,11 @@ export = {
onboardingInProgress.set(networkChannel.id, networkChannel.id);

// Show new users rules & info about network
const onboardingStatus = await onboarding.execute(interaction);
if (!onboardingStatus) {
onboardingInProgress.delete(networkChannel.id);
return;
}
const onboardingStatus = await onboarding.execute(interaction, hub.name);
// remove in-progress marker as onboarding has either been cancelled or completed
onboardingInProgress.delete(networkChannel.id);
// if user cancelled onboarding or didn't click any buttons, stop here
if (!onboardingStatus) return;

let createdConnection;
try {
Expand Down Expand Up @@ -73,16 +76,11 @@ export = {
});

const numOfConnections = await connectedList.count({ where: { hub: { id: hub.id } } });
if (numOfConnections > 1) {
await networkChannel?.send(`This channel has been connected with ${hub.name}.`);
}
else {
await networkChannel?.send(`This channel has been connected with ${hub.name}. ${
numOfConnections > 1
? `You are currently with ${numOfConnections - 1} other servers, Enjoy! ${emoji.clipart}`
: `It seems no one else is there currently... *cricket noises* ${emoji.clipart}`
}`);
}
await networkChannel?.send(`This channel has been connected with **${hub.name}**. ${
numOfConnections > 1
? `You are currently with ${numOfConnections - 1} other servers, Enjoy! ${emoji.clipart}`
: `It seems no one else is there currently... *cricket noises* ${emoji.clipart}`
}`);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
catch (err: any) {
Expand All @@ -104,15 +102,14 @@ export = {
return;
}

// dispose of the in-progress marker
onboardingInProgress.delete(networkChannel.id);

interaction.client.sendInNetwork(stripIndents`
A new server has joined us! ${emoji.clipart}
**Server Name:** __${interaction.guild?.name}__
**Member Count:** __${interaction.guild?.memberCount}__
`, { id: hub.id });
return createdConnection; // just a marker to show that the setup was successful

// return the created connection so we can use it in the next step
return createdConnection;
},
};
12 changes: 6 additions & 6 deletions src/Scripts/network/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { colors, rulesEmbed } from '../../Utils/functions/utils';

/* Make user accept and understand important info on first setup */
export default {
async execute(interaction: ChatInputCommandInteraction) {
async execute(interaction: ChatInputCommandInteraction, hubName: string) {
const embed = new EmbedBuilder()
.setTitle('👋 Hey there! Welcome to the InterChat network.')
.setTitle(`👋 Hey there! Welcome to ${hubName}!`)
.setDescription(stripIndents`
To keep things organized, it's recommended to create a separate channel for the network. But don't worry, you can always change this later.
To keep things organized, it's recommended to use a separate channel for just for this hub. But don't worry, you can always change this later.
Before we dive in, take a moment to review our network rules. We want everyone to have a smooth and fun experience.
Before we dive in, take a moment to review our rules. We want everyone to have a smooth and fun experience.
**How it works:** the InterChat Network is like a magic bridge that links channels on different servers. So, you can chat with people from all over!
**How it works:** the InterChat Network is like a magic bridge that links channels on different servers that are with us in this hub. So, you can chat with people from all over!
And hey, if you have any cool ideas for new features, let us know! We're always looking to improve.
Developer Note: And hey, if you have any cool ideas for new features, let us know! We're always looking to improve.
`)
.setColor(colors('chatbot'))
.setFooter({ text: `InterChat Network | Version ${interaction.client.version}` });
Expand Down

0 comments on commit 2cd3b8a

Please sign in to comment.