123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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<boolean>;
- export interface ICommand {
- onStart?(): void | Promise<void>;
- _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<T extends {new(...params: any[]): {}}>(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(<IBotCommand>{
- action: descriptor.value,
- ...opts
- });
- };
- }
|