1
0
Fork 0
mirror of https://github.com/ChomeNS/chomens-bot-mc.git synced 2025-07-13 05:03:55 -04:00
chomens-bot-js/util/loadPlugins.js

34 lines
1.2 KiB
JavaScript
Raw Normal View History

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