import { Message } from "discord.js"; export interface CommandDocumentation { description: string; example: string; } export interface CommandOptions { pattern: string | RegExp; documentation?: CommandDocumentation; auth?: boolean; }; export type BotAction = (actionsDone: boolean, m : Message, content: string) => boolean | Promise; export interface ICommand { onStart?(): void | Promise; _botCommands?: IBotCommand[]; _botEvents?: { [action in ActionType]?: BotAction }; BOT_COMMAND?: string; }; export interface IBotCommand extends CommandOptions { action(message: Message, strippedContents: string, matches?: RegExpMatchArray) : void; }; export const BOT_COMMAND_DESCRIPTOR = "BOT_COMMAND"; export function CommandSet(base: T) { base.prototype.BOT_COMMAND = BOT_COMMAND_DESCRIPTOR; } export enum ActionType { MESSAGE, INDIRECT_MENTION, DIRECT_MENTION, POST_MESSAGE } export function Action(type: ActionType) { return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) { if(!target._botEvents) target._botEvents= {}; target._botEvents[type] = descriptor.value; }; } export function Command(opts: CommandOptions) { return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) { if(!target._botCommands) target._botCommands = []; target._botCommands.push({ action: descriptor.value, ...opts }); }; }