2019-09-10 09:21:00 +00:00
|
|
|
import { injectable } from "@ms/container";
|
|
|
|
|
2019-09-07 04:23:15 +00:00
|
|
|
export namespace command {
|
2019-09-10 09:21:00 +00:00
|
|
|
@injectable()
|
2019-09-07 04:23:15 +00:00
|
|
|
export abstract class Command {
|
2019-09-10 09:21:00 +00:00
|
|
|
on(plugin: any, name: string, exec: { cmd: Function, tab?: Function }) {
|
2019-09-07 04:23:15 +00:00
|
|
|
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)
|
|
|
|
}
|
2019-09-19 10:59:00 +00:00
|
|
|
}
|
|
|
|
off(plugin: any, name: string) {
|
|
|
|
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Create Server Command Object
|
|
|
|
*/
|
2019-09-19 10:59:00 +00:00
|
|
|
abstract create(name: string, opts: { name: string });
|
2019-09-07 04:23:15 +00:00
|
|
|
abstract onCommand(plugin: object, command: any, opts: { name: string });
|
|
|
|
abstract onTabComplete(plugin: object, command: any, opts: { name: string });
|
|
|
|
}
|
|
|
|
}
|