fix: command registry error

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-09-24 10:33:16 +08:00
parent 9c137574f5
commit afd04ed972
8 changed files with 46 additions and 41 deletions

View File

@@ -1,5 +1,5 @@
import { command, plugin, server } from '@ccms/api'
import { provideSingleton, postConstruct, inject } from '@ccms/container'
import { provideSingleton, inject } from '@ccms/container'
import { getPluginCommandMetadata, getPluginTabCompleterMetadata } from './utils'
@provideSingleton(PluginCommandManager)
@@ -17,13 +17,19 @@ export class PluginCommandManager {
private registryCommand(pluginInstance: plugin.Plugin) {
let cmds = getPluginCommandMetadata(pluginInstance)
let tabs = getPluginTabCompleterMetadata(pluginInstance)
for (const [_, cmd] of cmds) {
for (const cmd of cmds) {
let tab = tabs.get(cmd.name)
if (!this.ServerChecker.check(cmd.servers)) { continue }
this.CommandManager.on(pluginInstance, cmd.name, {
if (!this.ServerChecker.check(cmd.servers)) {
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
continue
}
let exec = {
cmd: pluginInstance[cmd.executor].bind(pluginInstance),
tab: tab ? pluginInstance[tab.executor].bind(pluginInstance) : undefined
})
}
for (let command of [cmd.name, ...cmd.alias]) {
this.CommandManager.on(pluginInstance, command, exec)
}
}
}