Add support for async plugin load functions
parent
815825de94
commit
0c25afaec2
20
src/main.js
20
src/main.js
|
@ -45,7 +45,10 @@ module.exports = {
|
||||||
console.log('Initializing...');
|
console.log('Initializing...');
|
||||||
initStatus();
|
initStatus();
|
||||||
initBaseMessageHandlers();
|
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('');
|
||||||
console.log('Done! Now listening to DMs.');
|
console.log('Done! Now listening to DMs.');
|
||||||
|
@ -253,7 +256,7 @@ function initBaseMessageHandlers() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initPlugins() {
|
async function initPlugins() {
|
||||||
// Initialize command manager
|
// Initialize command manager
|
||||||
const commands = createCommandManager(bot);
|
const commands = createCommandManager(bot);
|
||||||
|
|
||||||
|
@ -265,7 +268,6 @@ function initPlugins() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load plugins
|
// Load plugins
|
||||||
console.log('Loading plugins');
|
|
||||||
const builtInPlugins = [
|
const builtInPlugins = [
|
||||||
reply,
|
reply,
|
||||||
close,
|
close,
|
||||||
|
@ -293,11 +295,17 @@ function initPlugins() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const pluginApi = getPluginAPI({ bot, knex, config, commands });
|
const pluginApi = getPluginAPI({ bot, knex, config, commands });
|
||||||
plugins.forEach(pluginFn => loadPlugin(pluginFn, pluginApi));
|
for (const plugin of plugins) {
|
||||||
|
await loadPlugin(plugin, pluginApi);
|
||||||
console.log(`Loaded ${plugins.length} plugins (${builtInPlugins.length} built-in plugins, ${plugins.length - builtInPlugins.length} external plugins)`);
|
}
|
||||||
|
|
||||||
if (config.updateNotifications) {
|
if (config.updateNotifications) {
|
||||||
updates.startVersionRefreshLoop();
|
updates.startVersionRefreshLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
loadedCount: plugins.length,
|
||||||
|
builtInCount: builtInPlugins.length,
|
||||||
|
externalCount: plugins.length - builtInPlugins.length,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ module.exports = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
loadPlugin(plugin, api) {
|
async loadPlugin(plugin, api) {
|
||||||
plugin(api);
|
await plugin(api);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue