Add support for async plugin load functions

cshd
Dragory 2020-07-14 00:17:31 +03:00
parent 815825de94
commit 0c25afaec2
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
2 changed files with 16 additions and 8 deletions

View File

@ -45,7 +45,10 @@ module.exports = {
console.log('Initializing...');
initStatus();
initBaseMessageHandlers();
initPlugins();
console.log('Loading plugins...');
const pluginResult = await initPlugins();
console.log(`Loaded ${pluginResult.loadedCount} plugins (${pluginResult.builtInCount} built-in plugins, ${pluginResult.externalCount} external plugins)`);
console.log('');
console.log('Done! Now listening to DMs.');
@ -253,7 +256,7 @@ function initBaseMessageHandlers() {
});
}
function initPlugins() {
async function initPlugins() {
// Initialize command manager
const commands = createCommandManager(bot);
@ -265,7 +268,6 @@ function initPlugins() {
}
// Load plugins
console.log('Loading plugins');
const builtInPlugins = [
reply,
close,
@ -293,11 +295,17 @@ function initPlugins() {
}
const pluginApi = getPluginAPI({ bot, knex, config, commands });
plugins.forEach(pluginFn => loadPlugin(pluginFn, pluginApi));
console.log(`Loaded ${plugins.length} plugins (${builtInPlugins.length} built-in plugins, ${plugins.length - builtInPlugins.length} external plugins)`);
for (const plugin of plugins) {
await loadPlugin(plugin, pluginApi);
}
if (config.updateNotifications) {
updates.startVersionRefreshLoop();
}
return {
loadedCount: plugins.length,
builtInCount: builtInPlugins.length,
externalCount: plugins.length - builtInPlugins.length,
};
}

View File

@ -24,7 +24,7 @@ module.exports = {
};
},
loadPlugin(plugin, api) {
plugin(api);
async loadPlugin(plugin, api) {
await plugin(api);
}
};