mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -05:00
remove onetime inject and revert console
This commit is contained in:
parent
57ccc0b3e1
commit
a835f6afc8
4 changed files with 75 additions and 94 deletions
1
bot.js
1
bot.js
|
@ -51,7 +51,6 @@ async function createBot(server, config, getBots, dcclient, rl) {
|
|||
bot.visibility = false;
|
||||
bot.getBots = getBots;
|
||||
bot.getplayerusername = {};
|
||||
if (typeof bot.messageLogging === 'undefined') bot.messageLogging = true;
|
||||
|
||||
await sleep(200);
|
||||
|
||||
|
|
2
index.js
2
index.js
|
@ -21,8 +21,6 @@ dcclient.on('ready', () => {
|
|||
// await is important cuz the function is async
|
||||
// VVVVV
|
||||
const bot = await createBot(server, config, getBots, dcclient, rl);
|
||||
await loadPlugins(bot, dcclient, config, rl, true);
|
||||
bot.console.setRl(rl);
|
||||
bots.push(bot);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,6 +4,8 @@ const moment = require('moment-timezone');
|
|||
const util = require('util');
|
||||
|
||||
function inject(bot, _dcclient, config, rl) {
|
||||
if (!config.console) return;
|
||||
|
||||
// readline > fix on log
|
||||
function log(...args) {
|
||||
rl.output.write('\x1b[2K\r');
|
||||
|
@ -32,16 +34,9 @@ function inject(bot, _dcclient, config, rl) {
|
|||
};
|
||||
|
||||
bot.on('parsed_chat', (message) => {
|
||||
if (!bot.messageLogging) return;
|
||||
bot.console.log(message.toAnsi());
|
||||
});
|
||||
}
|
||||
|
||||
function oneTimeInject(bot, _dcclient, config, rl) {
|
||||
if (!config.console) return;
|
||||
|
||||
bot.console.setRl = setRl;
|
||||
function setRl(rl) {
|
||||
rl.on('line', function(line) {
|
||||
try {
|
||||
if (line.toLowerCase() === '' ||
|
||||
|
@ -71,14 +66,6 @@ function oneTimeInject(bot, _dcclient, config, rl) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
if (line === '.messagelogging on') {
|
||||
bot.messageLogging = true;
|
||||
return;
|
||||
}
|
||||
if (line === '.messagelogging off') {
|
||||
bot.messageLogging = false;
|
||||
return;
|
||||
}
|
||||
if (line === '.kill') process.exit();
|
||||
|
||||
if (line.startsWith('.')) {
|
||||
|
@ -120,6 +107,5 @@ function oneTimeInject(bot, _dcclient, config, rl) {
|
|||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {inject, oneTimeInject};
|
||||
module.exports = {inject};
|
||||
|
|
|
@ -9,17 +9,15 @@ const path = require('path');
|
|||
* @param {object} dcclient discord client
|
||||
* @param {object} config the config
|
||||
* @param {object} rl readline.
|
||||
* @param {boolean} oneTime load plugins one time
|
||||
*/
|
||||
async function loadPlugins(bot, dcclient, config, rl, oneTime) {
|
||||
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));
|
||||
if (!oneTime) plug.inject(bot, dcclient, config, rl);
|
||||
if (oneTime && plug.oneTimeInject) plug.oneTimeInject(bot, dcclient, config, rl);
|
||||
plug.inject(bot, dcclient, config, rl);
|
||||
} catch (e) {
|
||||
console.log(`Plugin ${plugin} is having exception loading the plugin:`);
|
||||
console.log(util.inspect(e));
|
||||
|
|
Loading…
Reference in a new issue