meocord
Version:
MeoCord is a lightweight and modular framework for building scalable Discord bots using TypeScript and Discord.js. It simplifies bot development with an extensible architecture, TypeScript-first approach, and powerful CLI tools.
126 lines (125 loc) • 5.34 kB
TypeScript
/**
* MeoCord Framework
* Copyright (C) 2025 Ukasyah Rahmatullah Zada
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import 'reflect-metadata';
import { Message, MessageReaction, type OmitPartialGroupDMChannel, type PartialMessageReaction } from 'discord.js';
import { CommandType } from '../enum/index.js';
import { type ReactionHandlerOptions } from '../interface/index.js';
import { type CommandBuilderConstructor, type CommandInteractionType, type CommandMetadata } from '../interface/command-decorator.interface.js';
/**
* Decorator to register message handlers in the controller.
*
* @param keyword - An optional keyword to filter messages this handler should respond to.
*
* @example
* ```typescript
* @MessageHandler('hello')
* async handleHelloMessage(message: Message) {
* await message.reply('Hello! How can I help you?');
* }
*
* @MessageHandler()
* async handleAnyMessage(message: Message) {
* console.log(`Received a message: ${message.content}`);
* }
* ```
*/
export declare function MessageHandler<T extends OmitPartialGroupDMChannel<Message<boolean>>, R extends void | Promise<void>>(keyword?: string): (target: object, propertyKey: string, _descriptor: TypedPropertyDescriptor<(message: T) => R>) => void;
/**
* Decorator to register reaction handlers in the controller.
*
* @param emoji - Optional emoji name to filter reactions this handler should respond to.
*
* @example
* ```typescript
* @ReactionHandler('👍')
* async handleThumbsUpReaction(reaction: MessageReaction, { user }: ReactionHandlerOptions) {
* console.log(`User ${user.username} reacted with 👍`);
* }
*
* @ReactionHandler()
* async handleAnyReaction(reaction: MessageReaction, { user }: ReactionHandlerOptions) {
* console.log(`User ${user.username} reacted with ${reaction.emoji.name}`);
* }
* ```
*/
export declare function ReactionHandler<T extends MessageReaction | PartialMessageReaction, R extends void | Promise<void>>(emoji?: string): (target: object, propertyKey: string, _descriptor: TypedPropertyDescriptor<(reaction: T, options: ReactionHandlerOptions) => R> | TypedPropertyDescriptor<(reaction: T) => R>) => void;
/**
* Retrieves reaction handlers metadata from a given controller.
*
* @param controller - The controller class instance.
* @returns An array of reaction handler metadata objects.
*/
export declare function getReactionHandlers(controller: any): {
emoji: string | undefined;
method: string;
}[];
/**
* Retrieves message handlers metadata from a given controller.
*
* @param controller - The controller class instance.
* @returns An array of message handler method names.
*/
export declare function getMessageHandlers(controller: any): {
keyword: string | undefined;
method: string;
}[];
/**
* Decorator to register command methods in a controller.
*
* @param commandName - The name or pattern of the command.
* @param builderOrType - A command builder class or a command type from `CommandType`.
*
* @example
* ```typescript
* @Command('help', CommandType.SLASH)
* public async handleHelp(interaction: ChatInputCommandInteraction) {
* await interaction.reply('This is the help command!')
* }
*
* @Command('stats-{id}', CommandType.BUTTON)
* public async handleStats(message: ButtonInteraction, { id }) {
* await message.reply(`Fetching stats for ID: ${id}`);
* }
* ```
*/
export declare function Command<CBC extends CommandType.SLASH | CommandType.CONTEXT_MENU, T extends CommandBuilderConstructor<CBC> | CommandType>(commandName: string, builderOrType: T): <P extends Record<string, any>, R extends Promise<void> | void>(target: object, propertyKey: string, _descriptor: TypedPropertyDescriptor<(interaction: CommandInteractionType<CBC, T>, params: P) => R> | TypedPropertyDescriptor<(interaction: CommandInteractionType<CBC, T>) => R>) => void;
/**
* Retrieves the command map for a given controller.
*
* @param controller - The controller class instance.
* @returns A record containing command metadata indexed by command names.
*/
export declare function getCommandMap<T extends string>(controller: any): Record<string, CommandMetadata<T>[]>;
/**
* Decorator to mark a class as a controller that can later be registered to the App class `(app.ts)` using the `@MeoCord` decorator.
*
* @example
* ```typescript
* @Controller()
* export class PingSlashController {
* constructor(private pingService: PingService) {}
*
* @Command('ping', PingCommandBuilder)
* async ping(interaction: ChatInputCommandInteraction) {
* const response = await this.pingService.handlePing()
* await interaction.reply(response)
* }
* }
* ```
*/
export declare function Controller(): (target: any) => void;