Fixed pluginmanager

This commit is contained in:
lanxu 2019-11-20 20:49:21 +02:00
parent d386c9d242
commit ed800dbd81

View File

@ -42,15 +42,14 @@ class PluginManager {
}) })
} }
validateResult (resultPromise) { async validateResult (resultPromise) {
return new Promise((resolve) => { let results = await resultPromise
let wrapperPromise = new Promise((resolve) => resolve(resultPromise))
wrapperPromise.then((results) => { let promises = []
if (!Array.isArray(results)) { if (!Array.isArray(results)) {
results = [results] results = [results]
} }
let promises = []
results.forEach((result) => { results.forEach((result) => {
let to = 'channel' let to = 'channel'
let message = result let message = result
@ -59,15 +58,12 @@ class PluginManager {
message = result.message message = result.message
} }
promises.push(new Promise({ to, message })) promises.push(new Promise((resolve) => resolve({ to, message })))
})
resolve(promises)
})
}) })
return promises
} }
testPlugins (input, publicChat) { async testPlugins (input, publicChat) {
if (typeof publicChat === 'undefined') { if (typeof publicChat === 'undefined') {
publicChat = true publicChat = true
} }
@ -79,7 +75,7 @@ class PluginManager {
let plugin = this.plugins[i] let plugin = this.plugins[i]
if (plugin.test(input)) { if (plugin.test(input)) {
logger.info('* Plugin ' + plugin.name + ' reported hit') logger.info('* Plugin ' + plugin.name + ' reported hit')
promises.push(this.validateResult(plugin.result(input))) promises = [...promises, ...await this.validateResult(plugin.result(input))]
} }
} }
} else { } else {
@ -88,7 +84,7 @@ class PluginManager {
if (plugin.test(input)) { if (plugin.test(input)) {
logger.info('* Plugin ' + plugin.name + ' reported hit') logger.info('* Plugin ' + plugin.name + ' reported hit')
promises.push(this.validateResult(plugin.result(input))) promises = [...promises, ...await this.validateResult(plugin.result(input))]
} }
} }
} }