From d911e31a68250cd7442836a8b3b67592a61a79dc Mon Sep 17 00:00:00 2001 From: dev-737 <73829355+dev-737@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:05:19 +0530 Subject: [PATCH] feat: simplified setup command --- src/commands/slash/Main/setup.ts | 125 +++++++++++-------------------- src/utils/CustomID.ts | 2 +- 2 files changed, 45 insertions(+), 82 deletions(-) diff --git a/src/commands/slash/Main/setup.ts b/src/commands/slash/Main/setup.ts index bc137dd5..2648c4c2 100644 --- a/src/commands/slash/Main/setup.ts +++ b/src/commands/slash/Main/setup.ts @@ -1,8 +1,7 @@ import BaseCommand from '#main/core/BaseCommand.js'; import { RegisterInteractionHandler } from '#main/decorators/RegisterInteractionHandler.js'; -import { Pagination } from '#main/modules/Pagination.js'; import { HubJoinService } from '#main/services/HubJoinService.js'; -import Constants from '#main/utils/Constants.js'; +import Constants, { emojis } from '#main/utils/Constants.js'; import { CustomID } from '#main/utils/CustomID.js'; import { InfoEmbed } from '#main/utils/EmbedUtils.js'; import { stripIndents } from 'common-tags'; @@ -14,6 +13,7 @@ import { ButtonStyle, ChannelType, ChatInputCommandInteraction, + InteractionContextType, RESTPostAPIChatInputApplicationCommandsJSONBody, } from 'discord.js'; @@ -21,57 +21,32 @@ export default class SetupCommand extends BaseCommand { readonly data: RESTPostAPIChatInputApplicationCommandsJSONBody = { name: 'setup', description: 'Setup the bot for the server', + contexts: [InteractionContextType.Guild], options: [ { - name: 'interchat', + name: 'channel', description: 'The channel to setup the bot in', - type: ApplicationCommandOptionType.Subcommand, - options: [ - { - name: 'channel', - description: 'The channel to setup the bot in', - type: ApplicationCommandOptionType.Channel, - channel_types: [ - ChannelType.GuildText, - ChannelType.PublicThread, - ChannelType.PrivateThread, - ], - required: true, - }, - ], - }, - { - name: 'lobby', - description: 'Learn how to use our userphone-like lobby chat system.', - type: ApplicationCommandOptionType.Subcommand, + type: ApplicationCommandOptionType.Channel, + channel_types: [ChannelType.GuildText, ChannelType.PublicThread, ChannelType.PrivateThread], + required: true, }, ], }; public async execute(interaction: ChatInputCommandInteraction) { - const subcommand = interaction.options.getSubcommand(true); - if (subcommand === 'lobby') await this.setupLobby(interaction); - else if (subcommand === 'interchat') await this.setupHub(interaction); - } - - private async setupLobby(interaction: ChatInputCommandInteraction): Promise { - const embed = new InfoEmbed().setTitle('Lobby Setup').setDescription(stripIndents` - The lobby is a userphone-like chat system where you can chat with random people. What makes it different from other userphone bots is that you can have upto 3 servers in a lobby at once. - ### How to setup: - 1. Type \`c!connect\` or \`c!call\`. - 2. Wait for someone to to join. - 3. Have fun! πŸŽ‰ - ### Want something more? - Try out our multi-server hub chatting using - - -# Note: You are expected to follow our [guidelines](${Constants.Links.Website}/guidelines). If you are found breaking the guidelines, you will be banned from using the bot. - `); - - await interaction.reply({ embeds: [embed] }); - } - - private async setupHub(interaction: ChatInputCommandInteraction): Promise { - if (!interaction.inCachedGuild()) return; + const embed = new InfoEmbed().setDescription( + stripIndents` + ## ${emojis.guide_icon} Interchat Setup - Let\'s get started! + Let's get started with setting up a connection to a hub from a channel in this server. + ### Hub? + A **hub** is a **group**β€”where servers connect to, to chat together. Once you setup the bot in a channel, messages to and from that channel will go to other servers in that hub. + ## Choose a Hub + 1. Click **Official Hub** to join the official InterChat hub. (Recommended) + 2. Or click **Random Hub** to join to a random community hub! + + You and this server are expected to follow the [guidelines](${Constants.Links.Website}/guidelines) when chatting. We hope you enjoy your time on InterChat. πŸŽ‰ + `, + ); const channel = interaction.options.getChannel('channel', true, [ ChannelType.GuildText, @@ -95,40 +70,7 @@ export default class SetupCommand extends BaseCommand { ), ]; - const embed1 = new InfoEmbed().setTitle('Interchat Setup - Let\'s get started!').setDescription( - stripIndents` - A **hub** is a group of servers that you can chat with. It can contain unlimited servers and lets you chat without disconnecting. - - After this setup, you will be able to talk with people that are part of your chosen hub from ${channel}. - `, - ); - const setupEmbed = new InfoEmbed().setDescription(stripIndents` - ### Setup: - 1. Click **Official Hub** to connect to a hub moderated by InterChat staff. - 2. Or click **Random Hub** to connect to a random community owned hub. - - You are expected to follow the [guidelines](${Constants.Links.Website}/guidelines) when chatting. If you are found breaking the guidelines, you will be banned from using the bot. Have fun! πŸŽ‰ - `); - - const finalEmbed = new InfoEmbed().setDescription(stripIndents` - ### Finally: - - Search for community hubs by category here: ${Constants.Links.Website}/hubs - - Create your own hub using \`/hub create\`. - - Join a hub by name or invite by using \`/hub join\`. - - Leave a hub using \`/hub leave\`. - - Use our userphone-like lobby chat using \`/setup lobby\`. - - Thats it! We hope you enjoy your time on InterChat. - -# Need help? Join our [support server](${Constants.Links.SupportInvite}). - `); - - await new Pagination({ hideButtons: { search: true, exit: true, select: true } }) - .addPages([ - { embeds: [embed1] }, - { embeds: [setupEmbed], components }, - { embeds: [finalEmbed], components: [] }, - ]) - .run(interaction); + await interaction.reply({ embeds: [embed], components }); } @RegisterInteractionHandler('setupHub') @@ -159,12 +101,33 @@ export default class SetupCommand extends BaseCommand { return; } + let joinSuccess = false; + if (customId.suffix === 'official') { // NOTE: if hub name ever changes, this will need to be updated - await hubJoinService.joinHub(channel, 'InterChat Central'); + joinSuccess = await hubJoinService.joinHub(channel, 'InterChat Central'); } else if (customId.suffix === 'random') { - await hubJoinService.joinRandomHub(channel); + joinSuccess = await hubJoinService.joinRandomHub(channel); } + + if (!joinSuccess) return; + + const embed1 = new InfoEmbed().setDescription(stripIndents` + ## ${emojis.yes} Setup Complete! + The bot has been setup in ${channel.toString()}. You can now chat with other servers from this channel. πŸŽ‰ + `); + + const embed2 = new InfoEmbed().setDescription(stripIndents` + You can also setup the bot in other channels with a different hub using \`/hub join\`. Pick a hub of your own choosing from a wide list of [public hubs](${Constants.Links.Website}/hubs) made by the community. + `); + + const finalEmbed = new InfoEmbed().setDescription(stripIndents` + If you have any questions or need help, feel free to ask in the [support server](${Constants.Links.SupportInvite}). We also have a [Documentation](${Constants.Links.Website}/docs) page for more information. + + Enjoy your time on InterChat! πŸŽ‰ + `); + + await interaction.followUp({ embeds: [embed1, embed2, finalEmbed], ephemeral: true }); } } diff --git a/src/utils/CustomID.ts b/src/utils/CustomID.ts index 4b6c7aeb..a0720944 100644 --- a/src/utils/CustomID.ts +++ b/src/utils/CustomID.ts @@ -22,7 +22,7 @@ export class CustomID { * @param suffix - The suffix for the custom ID (optional). * @returns CustomID - The CustomID instance for method chaining. */ - setIdentifier(prefix: string, suffix?: string): CustomID { + setIdentifier(prefix: string, suffix?: string): this { this.customId = `${prefix}${suffix ? `:${suffix}` : ''}`; return this; }