mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -05:00
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
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 {object} targetClient proxy target
|
|
* @param {object} client proxy client
|
|
* @param {boolean} proxy is proxy
|
|
*/
|
|
async function loadPlugins(bot, dcclient, config, rl, targetClient, client, proxy) {
|
|
const plugins = await fs.readdir(path.join(__dirname, '..', 'plugins'));
|
|
|
|
if (!proxy) {
|
|
plugins.forEach((plugin) => {
|
|
try {
|
|
const plug = require(path.join(__dirname, '..', 'plugins', plugin));
|
|
plug.inject(bot, dcclient, config, rl);
|
|
} catch (e) {
|
|
console.log(`Plugin ${plugin} is having exception loading the plugin:`);
|
|
console.log(util.inspect(e));
|
|
}
|
|
});
|
|
} else {
|
|
plugins.forEach((plugin) => {
|
|
try {
|
|
const plug = require(path.join(__dirname, '..', 'plugins', plugin));
|
|
if (!plug.proxy) return;
|
|
plug.proxy(bot, client, targetClient, config);
|
|
} catch (e) {
|
|
console.log(`Proxy Plugin ${plugin} is having exception loading the plugin:`);
|
|
console.log(util.inspect(e));
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
module.exports = {loadPlugins};
|