feat: added more help commands

This commit is contained in:
TresAbhi committed 2023-07-10 19:14:16 +00:00
1 parent feeb850ca9
commit 463af106be
13 files changed
+174 -66

No files matched your search

+90 -21
View File
@@ -1,36 +1,105 @@
import { SlashCommandBuilder } from 'discord.js';
import discord from '../../discord.json' assert { type: 'json' };
import { client } from '../bot.js';
import {
SlashCommandBuilder,
SlashCommandSubcommandBuilder,
SlashCommandSubcommandGroupBuilder,
} from 'discord.js';
import embedInfo from '../core/discord/embedInfo.js';
import {
COMMANDS_RAW,
CommandRegistry,
guildCommands,
publicCommands,
} from '../events/interactionCreate/index.js';
const RAW_PATH = `https://raw.githubusercontent.com/tresabhi/blitzkrieg/main/docs/`;
const DOCS: Record<string, string> = {
permissions: 'guide/permissions',
embeds: 'guide/embeds',
about: 'guide/about',
invite: 'guide/invite',
};
export const helpCommand: CommandRegistry = {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
.setName('help')
.setDescription('All the help you need about the bot'),
.setDescription('All the help you need about the bot')
.addSubcommand((option) =>
option
.setName('commands')
.setDescription('List of all commands and their descriptions'),
)
.addSubcommand((option) =>
option
.setName('permissions')
.setDescription('The permissions needed for the bot to function'),
)
.addSubcommand((option) =>
option.setName('about').setDescription('About the bot'),
)
.addSubcommand((option) =>
option.setName('embeds').setDescription('How embeds work'),
)
.addSubcommand((option) =>
option.setName('invite').setDescription('How to invite the bot'),
),
handler(interaction) {
return embedInfo(
`${client.user?.username} help`,
`**About**\n${
client.user?.username
} automates many mundane tasks and provide statistics in numerous flexible ways.\n\nMade by TresAbhi from the Skilled [SKLLD] clan.\nGitHub: https://github.com/tresabhi/blitzkrieg\nDiscord server: https://discord.gg/nDt7AjGJQH\nSkilled server: https://discord.gg/ZPvcEG7DS8\n\n**Commands**\n${(interaction.guildId ===
discord.sklld_guild_id
? [...guildCommands, ...publicCommands]
: publicCommands
)
.map((command) => `**/${command.name}**: ${command.description}`)
.join(
'\n',
)}\n\n*I am a new bot; I may make mistakes and go offline unexpectedly from time to time.*`,
);
const subcommand = interaction.options.getSubcommand();
if (subcommand === 'commands') {
return [
`# Commands\n\nBlitzkrieg offers the following commands:`,
embedInfo(
'',
COMMANDS_RAW.filter(
(registry) => registry.inPublic && registry.inProduction,
)
.map((registry) => {
const info = `- \`/${registry.command.name}\`: ${registry.command.description}`;
const subcommandGroups = registry.command.options.filter(
(option) =>
option instanceof SlashCommandSubcommandGroupBuilder,
) as SlashCommandSubcommandGroupBuilder[];
const subcommands = registry.command.options.filter(
(option) => option instanceof SlashCommandSubcommandBuilder,
) as SlashCommandSubcommandBuilder[];
const tree =
subcommandGroups.length > 0
? subcommandGroups
.map((subcommandGroup) => {
const info = ` - \`${subcommandGroup.name}\`: ${subcommandGroup.description}`;
const subcommands = subcommandGroup.options
.map(
(subcommand) =>
` - \`${subcommand.name}\`: ${subcommand.description}`,
)
.join('\n');
return `${info}${
subcommands ? `\n${subcommands}` : ''
}`;
})
.join('\n')
: subcommands
.map(
(subcommand) =>
` - \`${subcommand.name}\`: ${subcommand.description}`,
)
.join('\n');
return `${info}${tree ? `\n${tree}` : ''}`;
})
.join('\n'),
),
];
}
const url = `${RAW_PATH}${DOCS[subcommand]}.md`;
const content = fetch(url).then((response) => response.text());
return content;
},
};