blob: 26d86c5106340a0170fa177571ed47bfb019ea27 [file] [log] [blame]
TheCodedProf1c3ad3c2023-01-25 17:58:36 -05001import { ActionRowBuilder, CommandInteraction, StringSelectMenuBuilder, ApplicationCommand, ApplicationCommandOptionType } from "discord.js";
pineafan4f164f32022-02-26 22:07:12 +00002import { SlashCommandBuilder } from "@discordjs/builders";
TheCodedProf1c3ad3c2023-01-25 17:58:36 -05003import client from "../utils/client.js";
4import EmojiEmbed from "../utils/generateEmojiEmbed.js";
5import { LoadingEmbed } from "../utils/defaults.js";
pineafan4f164f32022-02-26 22:07:12 +00006
PineaFan752af462022-12-31 21:59:38 +00007const command = new SlashCommandBuilder()
8 .setName("help")
9 .setDescription("Shows help for commands");
pineafan4f164f32022-02-26 22:07:12 +000010
pineafan63fc5e22022-08-04 22:04:10 +010011const callback = async (interaction: CommandInteraction): Promise<void> => {
TheCodedProf1c3ad3c2023-01-25 17:58:36 -050012 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 )
TheCodedProf92a003c2023-01-25 18:01:21 -050056 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) {
TheCodedProf1c3ad3c2023-01-25 17:58:36 -050059 subcommandGroupRow.components[0]!
60 .addOptions(
TheCodedProf92a003c2023-01-25 18:01:21 -050061 subcommandGroups.map((option) => {
TheCodedProf1c3ad3c2023-01-25 17:58:36 -050062 return {
63 label: option.name,
64 value: option.name
65 }
66 })
67 )
68 } else {
TheCodedProf92a003c2023-01-25 18:01:21 -050069 if(subcommands.length > 0) {
TheCodedProf1c3ad3c2023-01-25 17:58:36 -050070 subcommandRow.components[0]!
71 .addOptions(
TheCodedProf92a003c2023-01-25 18:01:21 -050072 subcommands.map((option) => {
TheCodedProf1c3ad3c2023-01-25 17:58:36 -050073 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);
pineafan63fc5e22022-08-04 22:04:10 +010089};
pineafan4f164f32022-02-26 22:07:12 +000090
PineaFan0d06edc2023-01-17 22:10:31 +000091const check = () => {
pineafan4f164f32022-02-26 22:07:12 +000092 return true;
pineafan63fc5e22022-08-04 22:04:10 +010093};
pineafan4f164f32022-02-26 22:07:12 +000094
95export { command };
96export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +010097export { check };