chomens-bot-js/util/loadPlugins.js

27 lines
749 B
JavaScript
Raw Normal View History

2022-11-08 05:43:24 -05:00
const fs = require('fs/promises');
const util = require('util');
const path = require('path');
2022-11-15 21:33:16 -05:00
/**
* load plugins
* @param {object} bot the bot object
* @param {object} dcclient discord client
* @param {object} config the config
* @param {object} rl readline
*/
2022-11-09 07:04:14 -05:00
async function loadPlugins(bot, dcclient, config, rl) {
2022-11-08 05:43:24 -05:00
const plugins = await fs.readdir(path.join(__dirname, '..', 'plugins'));
plugins.forEach((plugin) => {
try {
const plug = require(path.join(__dirname, '..', 'plugins', plugin));
2022-11-09 07:04:14 -05:00
plug.inject(bot, dcclient, config, rl);
2022-11-08 05:43:24 -05:00
} catch (e) {
console.log(`Plugin ${plugin} is having exception loading the plugin:`);
console.log(util.inspect(e));
}
});
};
module.exports = {loadPlugins};