mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -05:00
load files load plugins real11!
This commit is contained in:
parent
d173d980da
commit
380c0ba483
3 changed files with 31 additions and 32 deletions
24
index.js
24
index.js
|
@ -11,8 +11,7 @@ const sleep = require('sleep-promise');
|
|||
const {containsIllegalCharacters} = require('./util/containsIllegalCharacters');
|
||||
const generateEaglerUsername = require('./util/generateEaglerUsername');
|
||||
const {EventEmitter} = require('events');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const {loadPlugins} = require('./util/loadPlugins');
|
||||
const uuid = require('uuid-by-string');
|
||||
const readline = require('node:readline');
|
||||
const {stdin: input, stdout: output} = require('node:process');
|
||||
|
@ -87,26 +86,7 @@ function botThings() {
|
|||
bot.visibility = false;
|
||||
bot.getplayerusername = {};
|
||||
|
||||
// allink's plugin loader
|
||||
const plugins = []; // NOTE: DO NOT CHANGE, PLUGINS ARE LOADED AUTOMATICALLY
|
||||
fs.readdirSync(
|
||||
path.join(__dirname, 'plugins'),
|
||||
).forEach(function(file) { // populate plugins array
|
||||
if (file.endsWith('.js')) {
|
||||
plugins.push(path.join(__dirname, 'plugins', file));
|
||||
}
|
||||
});
|
||||
plugins.forEach(function(plugin) { // load plugins
|
||||
let name = plugin.split('/');
|
||||
name = name[name.length - 1];
|
||||
try {
|
||||
const plug = require(plugin);
|
||||
plug.inject(bot, dcclient, config);
|
||||
} catch (e) {
|
||||
console.log(`Plugin loader: Plugin ${name} is having exception loading the plugin:`);
|
||||
console.log(util.inspect(e));
|
||||
}
|
||||
});
|
||||
loadPlugins(bot, dcclient, config);
|
||||
}
|
||||
|
||||
let messageloggingEnabled = true;
|
||||
|
|
19
util/loadPlugins.js
Normal file
19
util/loadPlugins.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
const fs = require('fs/promises');
|
||||
const util = require('util');
|
||||
const path = require('path');
|
||||
|
||||
async function loadPlugins(bot, dcclient, config) {
|
||||
const plugins = await fs.readdir(path.join(__dirname, '..', 'plugins'));
|
||||
|
||||
plugins.forEach((plugin) => {
|
||||
try {
|
||||
const plug = require(path.join(__dirname, '..', 'plugins', plugin));
|
||||
plug.inject(bot, dcclient, config);
|
||||
} catch (e) {
|
||||
console.log(`Plugin ${plugin} is having exception loading the plugin:`);
|
||||
console.log(util.inspect(e));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {loadPlugins};
|
|
@ -1,20 +1,20 @@
|
|||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function loadPlugins (directory) {
|
||||
const plugins = []
|
||||
function loadPlugins(directory) {
|
||||
const plugins = [];
|
||||
|
||||
for (const filename of fs.readdirSync(directory)) {
|
||||
if (!filename.endsWith('.js')) continue
|
||||
if (!filename.endsWith('.js')) continue;
|
||||
|
||||
const filepath = path.join(directory, filename)
|
||||
const filepath = path.join(directory, filename);
|
||||
|
||||
const plugin = require(filepath)
|
||||
const plugin = require(filepath);
|
||||
|
||||
plugins.push(plugin)
|
||||
plugins.push(plugin);
|
||||
}
|
||||
|
||||
return plugins
|
||||
return plugins;
|
||||
}
|
||||
|
||||
module.exports = loadPlugins
|
||||
module.exports = loadPlugins;
|
||||
|
|
Loading…
Reference in a new issue