ms/packages/api/src/command.ts
MiaoWoo eb6a2a32db feat: add command bean and event bean
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-10 17:21:00 +08:00

26 lines
1.0 KiB
TypeScript

import { injectable } from "@ms/container";
export namespace command {
@injectable()
export abstract class Command {
on(plugin: any, name: string, exec: { cmd: Function, tab?: Function }) {
var cmd = this.create(plugin, { name: name });
console.debug(`插件 ${plugin.description.name} 创建命令 ${name}(${cmd})...`)
if (exec.cmd && typeof exec.cmd === "function") {
this.onCommand(plugin, cmd, exec.cmd)
} else {
throw Error("CommandExec Must be a function... Input: " + exec.cmd)
}
if (exec.tab && typeof exec.tab === "function") {
this.onTabComplete(plugin, cmd, exec.tab)
}
}
/**
* Create Server Command Object
*/
abstract create(plugin: object, opts: { name: string });
abstract onCommand(plugin: object, command: any, opts: { name: string });
abstract onTabComplete(plugin: object, command: any, opts: { name: string });
}
}