mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -05:00
30 lines
977 B
JavaScript
30 lines
977 B
JavaScript
/* eslint-disable max-len */
|
|
const fs = require('fs/promises');
|
|
const util = require('util');
|
|
const path = require('path');
|
|
|
|
/**
|
|
* load plugins
|
|
* @param {object} bot the bot object
|
|
* @param {object} dcclient discord client
|
|
* @param {object} config the config
|
|
* @param {object} rl readline.
|
|
* @param {boolean} oneTime load plugins one time
|
|
*/
|
|
async function loadPlugins(bot, dcclient, config, rl, oneTime) {
|
|
const dir = path.join(__dirname, '..', 'plugins');
|
|
const plugins = await fs.readdir(dir);
|
|
plugins.forEach((plugin) => {
|
|
if (!plugin.endsWith('.js')) return;
|
|
try {
|
|
const plug = require(path.join(dir, plugin));
|
|
if (!oneTime) plug.inject(bot, dcclient, config, rl);
|
|
if (oneTime && plug.oneTimeInject) plug.oneTimeInject(bot, dcclient, config, rl);
|
|
} catch (e) {
|
|
console.log(`Plugin ${plugin} is having exception loading the plugin:`);
|
|
console.log(util.inspect(e));
|
|
}
|
|
});
|
|
};
|
|
|
|
module.exports = {loadPlugins};
|