Fixed pluginmanager

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

View File

@ -42,32 +42,28 @@ 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) => {
if (!Array.isArray(results)) {
results = [results]
}
let promises = [] let promises = []
results.forEach((result) => { if (!Array.isArray(results)) {
let to = 'channel' results = [results]
let message = result }
if (typeof result === 'object' && typeof result.to !== 'undefined') {
to = result.to
message = result.message
}
promises.push(new Promise({ to, message })) results.forEach((result) => {
}) let to = 'channel'
let message = result
if (typeof result === 'object' && typeof result.to !== 'undefined') {
to = result.to
message = result.message
}
resolve(promises) promises.push(new Promise((resolve) => resolve({ to, message })))
})
}) })
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))]
} }
} }
} }