fix: command tab complate error

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-09-24 15:27:34 +08:00
parent fb8a11ea05
commit ed14d317f4
2 changed files with 7 additions and 7 deletions

View File

@ -13,7 +13,7 @@ export namespace command {
*/ */
on(plugin: plugin.Plugin, name: string, exec: { cmd: Function, tab?: Function }) { on(plugin: plugin.Plugin, name: string, exec: { cmd: Function, tab?: Function }) {
var cmd = this.create(plugin, name) var cmd = this.create(plugin, name)
if (!cmd) { throw Error("") } if (!cmd) { throw Error(`Plugin ${plugin.description.name} can't create Command ${name}!`) }
console.debug(i18n.translate("ms.api.command.register", { plugin: plugin.description.name, name, cmd })) console.debug(i18n.translate("ms.api.command.register", { plugin: plugin.description.name, name, cmd }))
if (exec.cmd && typeof exec.cmd === "function") { if (exec.cmd && typeof exec.cmd === "function") {
this.onCommand(plugin, cmd, exec.cmd) this.onCommand(plugin, cmd, exec.cmd)

View File

@ -18,17 +18,17 @@ export class PluginCommandManager {
let cmds = getPluginCommandMetadata(pluginInstance) let cmds = getPluginCommandMetadata(pluginInstance)
let tabs = getPluginTabCompleterMetadata(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)) { if (!this.ServerChecker.check(cmd.servers)) {
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`) console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
continue 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]) { for (let command of [cmd.name, ...cmd.alias]) {
this.CommandManager.on(pluginInstance, command, exec) this.CommandManager.on(pluginInstance, command, {
cmd: pluginInstance[cmd.executor].bind(pluginInstance),
tab: tabs.has(command) ?
pluginInstance[tabs.get(command).executor].bind(pluginInstance) :
console.debug(`[${pluginInstance.description.name}] command ${cmd.name} is not registry tabCompleter`)
})
} }
} }
} }