Files
blitzkit/src/commands/about.ts
T

69 lines
2.1 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',
2023-10-01 10:56:03 -05:00
introduction: 'guide/introduction',
2023-07-10 19:14:16 +00:00
invite: 'guide/invite',
2023-07-11 19:00:10 +00:00
timezones: 'guide/timezones',
2023-11-25 20:08:01 -06:00
creators: 'guide/creators',
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',
2023-10-01 10:56:03 -05:00
introduction: 'About the bot',
2023-07-11 19:00:10 +00:00
invite: 'How to invite the bot',
timezones: 'How Blitzkrieg infers and uses your timezone',
2023-11-25 20:08:01 -06:00
creators: 'Who created the bot',
2023-07-11 19:00:10 +00:00
};
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-10-01 10:56:03 -05:00
export const aboutCommand: 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()
2023-10-01 10:56:03 -05:00
.setName('about')
.setDescription('All the info you need about the bot')
2023-07-11 19:00:10 +00:00
.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-10-12 11:45:43 -05:00
.sort((a, b) => (a.command.name < b.command.name ? -1 : 1))
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
};