UNPKG

meocord

Version:

Decorator-based Discord bot framework built on discord.js. Brings NestJS-style controllers, dependency injection, guards, and testing utilities to bot development — with a full CLI and TypeScript-first design.

34 lines (31 loc) 1.35 kB
import 'reflect-metadata'; import { injectable } from 'inversify'; import { MetadataKey } from '../enum/metadata-key.enum.js'; /** * This decorator is used to mark a class as a Discord command builder that later can be registered on the `@Command` decorator. * It defines the command type using metadata and dynamically makes the class injectable if it isn't already. * * @example * ```typescript * @CommandBuilder(CommandType.SLASH) * export class MySlashCommand implements CommandBuilderBase { * build(commandName: string): SlashCommandBuilder { * return new SlashCommandBuilder().setName(commandName).setDescription('A sample slash command') * } * } *``` * * @param commandType - The type of the command, specified from the `CommandType` enum. * @returns A decorator function that makes the target class injectable * and assigns the `commandType` metadata. */ function CommandBuilder(commandType) { return function(target) { // Check if the class is already injectable; if not, make it injectable dynamically if (!Reflect.hasMetadata(MetadataKey.Injectable, target)) { injectable()(target); } // Define the command type metadata for the target class Reflect.defineMetadata(MetadataKey.CommandType, commandType, target); }; } export { CommandBuilder };