diff --git a/src/Scripts/hub/join.ts b/src/Scripts/hub/join.ts index 19ad14a5..0114e653 100644 --- a/src/Scripts/hub/join.ts +++ b/src/Scripts/hub/join.ts @@ -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) { @@ -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); }); } diff --git a/src/Scripts/network/initialize.ts b/src/Scripts/network/createConnection.ts similarity index 81% rename from src/Scripts/network/initialize.ts rename to src/Scripts/network/createConnection.ts index ebc0795e..8c53c5c3 100644 --- a/src/Scripts/network/initialize.ts +++ b/src/Scripts/network/createConnection.ts @@ -8,13 +8,16 @@ import { getDb } from '../../Utils/functions/utils'; const onboardingInProgress = new Collection(); -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); @@ -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 { @@ -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) { @@ -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; }, }; diff --git a/src/Scripts/network/onboarding.ts b/src/Scripts/network/onboarding.ts index be923257..5e713661 100644 --- a/src/Scripts/network/onboarding.ts +++ b/src/Scripts/network/onboarding.ts @@ -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}` });