Files
blitzkit/src/commands/about.ts
T

69 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-03-05 09:59:46 -06:00
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
import { translator } from '../core/localization/translator';
2023-07-11 19:54:57 +00:00
import { COMMANDS_RAW, CommandRegistry } from '../events/interactionCreate';
2023-04-26 14:23:42 +00:00
2024-03-05 09:59:46 -06:00
const subcommands = [
'embeds',
'introduction',
'invite',
'timezones',
'creators',
] as const;
type Subcommand = (typeof subcommands)[number];
const DOCS: Record<Subcommand, string> = {
2023-07-10 19:14:16 +00:00
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
};
export const aboutCommand = new Promise<CommandRegistry>(async (resolve) => {
resolve({
inProduction: true,
inPublic: true,
2023-04-26 14:23:42 +00:00
2024-03-05 10:51:14 -06:00
command: createLocalizedCommand('about', [
2024-03-05 09:59:46 -06:00
{ subcommand: 'commands' },
...subcommands.map((subcommand) => ({ subcommand })),
]),
2023-04-26 14:23:42 +00:00
async handler(interaction) {
const subcommand = interaction.options.getSubcommand();
2024-03-05 10:51:14 -06:00
const { t } = translator(interaction.locale);
2023-07-10 19:14:16 +00:00
if (subcommand === 'commands') {
return t`bot.commands.about.subcommands.commands.body${(
await Promise.all(COMMANDS_RAW)
2023-07-11 18:44:32 +00:00
)
.filter((registry) => registry.inPublic && registry.inProduction)
2024-03-05 09:59:46 -06:00
.sort((a, b) =>
(a.command.name_localizations?.[interaction.locale] ??
a.command.name) <
(b.command.name_localizations?.[interaction.locale] ??
b.command.name)
? -1
: 1,
)
.map(
(registry) =>
2024-03-05 09:59:46 -06:00
`- \`/${
registry.command.name_localizations?.[interaction.locale] ??
registry.command.name
}\`: ${
registry.command.description_localizations?.[
interaction.locale
] ?? registry.command.description
}`,
)
.join('\n')}`;
}
2023-07-10 19:14:16 +00:00
2024-04-23 09:57:59 -05:00
const url = `https://raw.githubusercontent.com/tresabhi/blitzkit/main/docs/${DOCS[subcommand as Subcommand]}.md`;
const content = fetch(url).then((response) => response.text());
2023-07-10 19:14:16 +00:00
return content;
},
});
});