Files
flint/src/core/commands/usage.ts
T
Puechberty Arthur e47cb68bc7 feat: implement command definition, registration, and execution framework
- Add `defineCommand` function to validate and normalize command inputs.
- Introduce `deployApplicationCommands` for deploying slash commands to Discord.
- Create `CommandRegistry` class for managing command registration and retrieval.
- Implement `buildSlashPayload` to construct slash command payloads with localization support.
- Add usage utilities for prefix and slash commands.
- Develop `CommandExecutor` to handle command execution with permission checks and cooldown management.
- Create member message rendering service for welcome and leave messages with customizable templates.
- Introduce presence template variables for dynamic bot status updates.
- Implement template variable utilities for rendering and extracting variables from strings.
2026-04-13 21:10:51 +02:00

45 lines
1.5 KiB
TypeScript

import type { BotCommand, CommandI18nTools, SupportedLang } from "../../types/command.js";
const formatArgToken = (name: string, required: boolean): string => required ? `<${name}>` : `[${name}]`;
export const resolvePrefixTrigger = (
command: BotCommand,
lang: SupportedLang,
defaultLang: SupportedLang,
i18n: CommandI18nTools,
): string => {
const fromLang = i18n.commandTrigger(lang, command.meta.name);
if (fromLang) {
return fromLang;
}
const fromDefault = i18n.commandTrigger(defaultLang, command.meta.name);
if (fromDefault) {
return fromDefault;
}
return command.meta.name;
};
export const resolveSlashName = (command: BotCommand, lang: SupportedLang, i18n: CommandI18nTools): string => {
return i18n.commandName(lang, command.meta.name);
};
export const buildPrefixUsage = (
command: BotCommand,
prefix: string,
lang: SupportedLang,
defaultLang: SupportedLang,
i18n: CommandI18nTools,
): string => {
const trigger = resolvePrefixTrigger(command, lang, defaultLang, i18n);
const args = command.args.map((arg) => formatArgToken(arg.name, arg.required)).join(" ");
return `${prefix}${trigger}${args.length > 0 ? ` ${args}` : ""}`;
};
export const buildSlashUsage = (command: BotCommand, lang: SupportedLang, i18n: CommandI18nTools): string => {
const slashName = resolveSlashName(command, lang, i18n);
const args = command.args.map((arg) => formatArgToken(arg.name, arg.required)).join(" ");
return `/${slashName}${args.length > 0 ? ` ${args}` : ""}`;
};