chomens-bot-js/util/loadPlugins.js

34 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-11-27 02:35:28 -05:00
const fs = require('fs/promises')
const util = require('util')
const path = require('path')
2022-11-08 05:43:24 -05:00
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
2022-11-30 06:01:46 -05:00
* @param {object} rl readline
* @param {object} target proxy target
* @param {object} client proxy client
* @param {boolean} proxy is proxy
* @param {array} clientPacketBlacklist the client packet blacklist
2022-12-07 06:39:37 -05:00
* @param {array} targetPacketBlacklist target packet blacklist
2022-11-15 21:33:16 -05:00
*/
async function loadPlugins (bot, dcclient, config, rl, target, client, proxy, clientPacketBlacklist, targetPacketBlacklist) {
2022-11-30 06:01:46 -05:00
const dir = path.join(__dirname, '..', 'plugins', proxy ? 'proxy' : '')
2022-11-27 02:35:28 -05:00
const plugins = await fs.readdir(dir)
plugins.forEach((plugin) => {
2022-11-27 02:35:28 -05:00
if (!plugin.endsWith('.js')) return
2022-11-17 08:05:47 -05:00
try {
2022-11-27 02:35:28 -05:00
const plug = require(path.join(dir, plugin))
2022-11-30 06:01:46 -05:00
if (!proxy) plug.inject(bot, dcclient, config, rl)
else plug.inject(bot, client, target, config, clientPacketBlacklist, targetPacketBlacklist)
2022-11-17 08:05:47 -05:00
} catch (e) {
2022-11-27 02:35:28 -05:00
console.log(`Plugin ${plugin} is having exception loading the plugin:`)
console.log(util.inspect(e))
2022-11-17 08:05:47 -05:00
}
})
2022-11-08 05:43:24 -05:00
};
2022-11-27 02:35:28 -05:00
module.exports = { loadPlugins }