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.
51 lines (48 loc) • 1.8 kB
JavaScript
import 'reflect-metadata';
import { injectable } from 'inversify';
import { MetadataKey } from '../enum/metadata-key.enum.js';
/**
* `@MeoCord()` decorator for declaring the MeoCord application class.
*
* This decorator stores the application options as metadata on the class.
* All DI wiring — container creation, client binding, controller/service
* registration — happens inside `MeoCordFactory.create()`, not here.
*
* @param {Object} options - The decorator options.
* @param {ServiceIdentifier[]} options.controllers - The list of controllers to be registered.
* @param {ClientOptions} options.clientOptions - The Discord client options for initializing the bot.
* @param {ActivityOptions[]} [options.activities] - Optional activities for the bot.
* @param {ServiceIdentifier[]} [options.services] - Optional services to be registered.
*
* @example
* ```typescript
* @MeoCord({
* controllers: [PingSlashController],
* clientOptions: {
* intents: [
* GatewayIntentBits.Guilds,
* GatewayIntentBits.GuildMembers,
* GatewayIntentBits.GuildMessages,
* GatewayIntentBits.GuildMessageReactions,
* GatewayIntentBits.MessageContent,
* ],
* partials: [Partials.Message, Partials.Channel, Partials.Reaction],
* },
* activities: [{
* name: `${sample(['Genshin', 'ZZZ'])} with Romeo`,
* type: ActivityType.Playing,
* url: 'https://enka.network/u/824957678/',
* }],
* services: [MyStandaloneService],
* })
* class MyApp {}
* ```
**/ function MeoCord(options) {
return (target)=>{
if (!Reflect.hasMetadata(MetadataKey.Injectable, target)) {
injectable()(target);
}
Reflect.defineMetadata(MetadataKey.AppOptions, options, target);
};
}
export { MeoCord };