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.

52 lines (50 loc) 1.54 kB
/** * MeoCord Framework * Copyright (c) 2025 Ukasyah Rahmatullah Zada * SPDX-License-Identifier: MIT */ /** * Composes multiple class or method decorators into a single decorator. * * @example * ```typescript * export const Protected = () => applyDecorators( * UseGuard(DefaultGuard, GlobalRateLimiterGuard), * ) * * @Controller() * @Protected() * export class PingController {} * ``` */ function applyDecorators(...decorators) { return function(target, propertyKey, descriptor) { for (const decorator of decorators){ if (propertyKey !== undefined && descriptor !== undefined) { decorator(target, propertyKey, descriptor); } else { decorator(target); } } return descriptor; }; } /** * Attaches arbitrary metadata to a class or method. Use alongside `Reflect.getMetadata` to read it back. * * @example * ```typescript * export const Roles = (...roles: string[]) => SetMetadata('roles', roles) * * @Command('admin', CommandType.SLASH) * @Roles('admin', 'moderator') * async adminCommand(interaction: ChatInputCommandInteraction) {} * ``` */ function SetMetadata(metadataKey, metadataValue) { return function(target, propertyKey) { if (propertyKey !== undefined) { Reflect.defineMetadata(metadataKey, metadataValue, target, propertyKey); } else { Reflect.defineMetadata(metadataKey, metadataValue, target); } }; } export { SetMetadata, applyDecorators };