chomens-bot-js/util/loadPlugins.js
2022-11-27 14:35:28 +07:00

28 lines
806 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.
*/
async function loadPlugins (bot, dcclient, config, rl) {
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))
plug.inject(bot, dcclient, config, rl)
} catch (e) {
console.log(`Plugin ${plugin} is having exception loading the plugin:`)
console.log(util.inspect(e))
}
})
};
module.exports = { loadPlugins }