2017-10-25 21:12:38 +02:00
|
|
|
'use strict';
|
|
|
|
|
2017-11-23 02:01:52 +01:00
|
|
|
const fs = require('fs'),
|
|
|
|
path = require('path');
|
2017-10-25 21:12:38 +02:00
|
|
|
|
|
|
|
function getPlugins(srcpath) {
|
|
|
|
return fs.readdirSync(srcpath);
|
|
|
|
}
|
2017-11-23 02:01:52 +01:00
|
|
|
let plugin_directory = path.join(__dirname, 'modules');
|
2017-10-25 21:12:38 +02:00
|
|
|
let plugins = getPlugins(plugin_directory);
|
|
|
|
|
|
|
|
exports.init = function init() {
|
|
|
|
load_plugins();
|
|
|
|
};
|
|
|
|
|
|
|
|
function load_plugins() {
|
2017-11-23 02:01:52 +01:00
|
|
|
const dbot = require('./bot.js');
|
2017-10-25 21:12:38 +02:00
|
|
|
let commandCount = 0;
|
|
|
|
let otherFunc = 0;
|
|
|
|
for (let i = 0; i < plugins.length; i++) {
|
|
|
|
let plugin;
|
|
|
|
try {
|
|
|
|
plugin = require(`${plugin_directory}/${plugins[i]}`);
|
|
|
|
} catch (err) {
|
|
|
|
console.log(`Improper setup of the '${plugins[i]}' plugin. : ${err}`);
|
|
|
|
}
|
|
|
|
if (plugin) {
|
2017-11-23 02:01:52 +01:00
|
|
|
if ('commands' in plugin) {
|
2017-10-25 21:12:38 +02:00
|
|
|
for (let j = 0; j < plugin.commands.length; j++) {
|
|
|
|
if (plugin.commands[j] in plugin) {
|
|
|
|
dbot.addCommand(plugin.commands[j], plugin[plugin.commands[j]]);
|
|
|
|
commandCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-23 02:01:52 +01:00
|
|
|
if ('custom' in plugin) {
|
2017-10-25 21:12:38 +02:00
|
|
|
for (let j = 0; j < plugin.custom.length; j++) {
|
|
|
|
if (plugin.custom[j] in plugin) {
|
|
|
|
dbot.addCustomFunc(plugin[plugin.custom[j]]);
|
|
|
|
otherFunc++;
|
|
|
|
}
|
|
|
|
}
|
2017-11-23 02:01:52 +01:00
|
|
|
}
|
2017-10-25 21:12:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log(`Loaded ${dbot.commandCount()} chat commands and ${otherFunc} custom functions.`);
|
|
|
|
}
|