Files
blitzkit/src/commands/help.ts
T

66 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-07-11 19:00:10 +00:00
import {
SlashCommandBuilder,
SlashCommandSubcommandsOnlyBuilder,
} from 'discord.js';
2023-07-11 19:54:57 +00:00
import { COMMANDS_RAW, CommandRegistry } from '../events/interactionCreate';
2023-04-26 14:23:42 +00:00
2023-07-10 19:14:16 +00:00
const RAW_PATH = `https://raw.githubusercontent.com/tresabhi/blitzkrieg/main/docs/`;
2023-07-11 19:00:10 +00:00
const DOCS = {
2023-07-10 19:14:16 +00:00
permissions: 'guide/permissions',
embeds: 'guide/embeds',
about: 'guide/about',
invite: 'guide/invite',
2023-07-11 19:00:10 +00:00
timezones: 'guide/timezones',
2023-07-10 19:14:16 +00:00
};
2023-07-11 19:00:10 +00:00
const DOC_DESCRIPTIONS: Record<keyof typeof DOCS, string> = {
permissions: 'The permissions needed for the bot to function',
embeds: 'How embeds work',
about: 'About the bot',
invite: 'How to invite the bot',
timezones: 'How Blitzkrieg infers and uses your timezone',
};
function addDocsSubcommands(option: SlashCommandSubcommandsOnlyBuilder) {
Object.entries(DOC_DESCRIPTIONS).forEach(([key, value]) => {
option.addSubcommand((sub) => sub.setName(key).setDescription(value));
});
return option;
}
2023-07-10 19:14:16 +00:00
2023-07-05 01:15:18 +00:00
export const helpCommand: CommandRegistry = {
2023-04-26 23:43:43 +00:00
inProduction: true,
2023-04-26 14:23:42 +00:00
inPublic: true,
2023-07-11 19:00:10 +00:00
command: addDocsSubcommands(
new SlashCommandBuilder()
.setName('help')
.setDescription('All the help you need about the bot')
.addSubcommand((option) =>
option
.setName('commands')
.setDescription('List of all commands and their descriptions'),
),
),
2023-04-26 14:23:42 +00:00
2023-08-04 18:24:20 +00:00
async handler(interaction) {
2023-07-10 19:14:16 +00:00
const subcommand = interaction.options.getSubcommand();
if (subcommand === 'commands') {
2023-08-04 18:24:20 +00:00
return `# Commands\n\nBlitzkrieg offers the following commands:\n\n${(
await Promise.all(COMMANDS_RAW)
2023-07-11 18:44:32 +00:00
)
2023-08-04 18:24:20 +00:00
.filter((registry) => registry.inPublic && registry.inProduction)
2023-07-11 18:44:32 +00:00
.map(
(registry) =>
`- \`/${registry.command.name}\`: ${registry.command.description}`,
)
.join('\n')}`;
2023-07-10 19:14:16 +00:00
}
2023-07-11 19:00:10 +00:00
const url = `${RAW_PATH}${DOCS[subcommand as keyof typeof DOCS]}.md`;
2023-07-10 19:14:16 +00:00
const content = fetch(url).then((response) => response.text());
return content;
2023-04-26 14:23:42 +00:00
},
2023-07-05 01:15:18 +00:00
};