Yet another Fluxer bot built with TypeScript and Bun
at develop 22 lines 720 B view raw
1import "reflect-metadata"; 2import type { ArgSchema } from "@/args"; 3import { MODULE_COMMANDS_KEY } from "@/base/ModuleBase"; 4 5export interface CommandMeta { 6 name: string; 7 aliases?: string[]; 8 description: string; 9 args?: ArgSchema; 10} 11 12export const COMMAND_META_KEY = Symbol("fluxer:command"); 13 14export function Command(meta: CommandMeta): MethodDecorator { 15 return (_target, methodName) => { 16 if (typeof methodName !== "string") return; 17 const commands: Array<{ methodName: string; meta: CommandMeta }> = 18 Reflect.getMetadata(MODULE_COMMANDS_KEY, _target.constructor) ?? []; 19 commands.push({ methodName, meta }); 20 Reflect.defineMetadata(MODULE_COMMANDS_KEY, commands, _target.constructor); 21 }; 22}