From ed800dbd81dec9371dd751e0edbe0fa9b72d346c Mon Sep 17 00:00:00 2001 From: lanxu Date: Wed, 20 Nov 2019 20:49:21 +0200 Subject: [PATCH] Fixed pluginmanager --- plugins/pluginManager.js | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/plugins/pluginManager.js b/plugins/pluginManager.js index c452cfa..e530d97 100644 --- a/plugins/pluginManager.js +++ b/plugins/pluginManager.js @@ -42,32 +42,28 @@ class PluginManager { }) } - validateResult (resultPromise) { - return new Promise((resolve) => { - let wrapperPromise = new Promise((resolve) => resolve(resultPromise)) - wrapperPromise.then((results) => { - if (!Array.isArray(results)) { - results = [results] - } + async validateResult (resultPromise) { + let results = await resultPromise - let promises = [] - results.forEach((result) => { - let to = 'channel' - let message = result - if (typeof result === 'object' && typeof result.to !== 'undefined') { - to = result.to - message = result.message - } + let promises = [] + if (!Array.isArray(results)) { + results = [results] + } - 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') { publicChat = true } @@ -79,7 +75,7 @@ class PluginManager { let plugin = this.plugins[i] if (plugin.test(input)) { logger.info('* Plugin ' + plugin.name + ' reported hit') - promises.push(this.validateResult(plugin.result(input))) + promises = [...promises, ...await this.validateResult(plugin.result(input))] } } } else { @@ -88,7 +84,7 @@ class PluginManager { if (plugin.test(input)) { logger.info('* Plugin ' + plugin.name + ' reported hit') - promises.push(this.validateResult(plugin.result(input))) + promises = [...promises, ...await this.validateResult(plugin.result(input))] } } }