TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 1 | import { ActionRowBuilder, CommandInteraction, StringSelectMenuBuilder, ApplicationCommand, ApplicationCommandOptionType } from "discord.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 2 | import { SlashCommandBuilder } from "@discordjs/builders"; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 3 | import client from "../utils/client.js"; |
| 4 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
| 5 | import { LoadingEmbed } from "../utils/defaults.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 6 | |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 7 | const command = new SlashCommandBuilder() |
| 8 | .setName("help") |
| 9 | .setDescription("Shows help for commands"); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 10 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 11 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 12 | const m = await interaction.reply({ embeds: LoadingEmbed, fetchReply: true }); |
| 13 | const commands = client.fetchedCommands; |
| 14 | |
| 15 | const commandRow = new ActionRowBuilder<StringSelectMenuBuilder>() |
| 16 | .addComponents( |
| 17 | commands.map((command) => { |
| 18 | return new StringSelectMenuBuilder() |
| 19 | .setCustomId(command.name) |
| 20 | .setPlaceholder("Select a command") |
| 21 | .addOptions({ |
| 22 | label: command.name, |
| 23 | value: command.name |
| 24 | }) |
| 25 | }) |
| 26 | ); |
| 27 | |
| 28 | let closed = false; |
| 29 | do { |
| 30 | let current: ApplicationCommand | undefined; |
| 31 | const subcommandGroupRow = new ActionRowBuilder<StringSelectMenuBuilder>() |
| 32 | .addComponents( |
| 33 | new StringSelectMenuBuilder() |
| 34 | .setCustomId("subcommandGroupRow") |
| 35 | ); |
| 36 | const subcommandRow = new ActionRowBuilder<StringSelectMenuBuilder>() |
| 37 | .addComponents( |
| 38 | new StringSelectMenuBuilder() |
| 39 | .setCustomId("subcommandRow") |
| 40 | ); |
| 41 | const embed = new EmojiEmbed() |
| 42 | .setTitle("Help") |
| 43 | .setStatus("Success") |
| 44 | .setEmoji("📖") |
| 45 | |
| 46 | if(!current) { |
| 47 | embed.setDescription( |
| 48 | `**${"Help Menu Home"}**\n\n` + |
| 49 | `${"Select a command to get started"}` |
| 50 | ) |
| 51 | } else { |
| 52 | embed.setDescription( |
| 53 | `**${current.name}**\n\n` + |
| 54 | `${current.description}` |
| 55 | ) |
TheCodedProf | 92a003c | 2023-01-25 18:01:21 -0500 | [diff] [blame] | 56 | const subcommands = current.options.filter((option) => option.type === ApplicationCommandOptionType.Subcommand); |
| 57 | const subcommandGroups = current.options.filter((option) => option.type === ApplicationCommandOptionType.SubcommandGroup); |
| 58 | if(subcommandGroups.length > 0) { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 59 | subcommandGroupRow.components[0]! |
| 60 | .addOptions( |
TheCodedProf | 92a003c | 2023-01-25 18:01:21 -0500 | [diff] [blame] | 61 | subcommandGroups.map((option) => { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 62 | return { |
| 63 | label: option.name, |
| 64 | value: option.name |
| 65 | } |
| 66 | }) |
| 67 | ) |
| 68 | } else { |
TheCodedProf | 92a003c | 2023-01-25 18:01:21 -0500 | [diff] [blame] | 69 | if(subcommands.length > 0) { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 70 | subcommandRow.components[0]! |
| 71 | .addOptions( |
TheCodedProf | 92a003c | 2023-01-25 18:01:21 -0500 | [diff] [blame] | 72 | subcommands.map((option) => { |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 73 | return { |
| 74 | label: option.name, |
| 75 | value: option.name |
| 76 | } |
| 77 | }) |
| 78 | ) |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | let cmps = [commandRow]; |
| 83 | if(subcommandGroupRow.components[0]!.options.length > 0) cmps.push(subcommandGroupRow); |
| 84 | if(subcommandRow.components[0]!.options.length > 0) cmps.push(subcommandRow); |
| 85 | |
| 86 | await interaction.editReply({ embeds: [embed], components: cmps }); |
| 87 | |
| 88 | } while (!closed); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 89 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 90 | |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 91 | const check = () => { |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 92 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 93 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 94 | |
| 95 | export { command }; |
| 96 | export { callback }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 97 | export { check }; |