mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -05:00
fix ploblem with bots on reconnect + improve!!!
This commit is contained in:
parent
eab8afe146
commit
3b0a7ebadb
2 changed files with 14 additions and 14 deletions
17
bot.js
17
bot.js
|
@ -21,12 +21,13 @@ const mineflayer = require('mineflayer');
|
|||
|
||||
/**
|
||||
* makes the bot
|
||||
* @param {Object} server the server object used in the config
|
||||
* @param {Object} config the config file
|
||||
* @param {Array} bots bots array (used in index.js, look in there)
|
||||
* @param {object} server the server object used in the config
|
||||
* @param {object} config the config file
|
||||
* @param {Function} getBots get bots function in index.js
|
||||
* @param {Class} dcclient discord client
|
||||
* @return {object} the bot object
|
||||
*/
|
||||
async function createBot(server, config, bots, dcclient) {
|
||||
async function createBot(server, config, getBots, dcclient) {
|
||||
const bot = new EventEmitter();
|
||||
bot.options = {
|
||||
username: /* process.argv[2] */ server.host === 'mc.chomens41793.ga' ?
|
||||
|
@ -49,6 +50,7 @@ async function createBot(server, config, bots, dcclient) {
|
|||
bot._client.removeAllListeners();
|
||||
};
|
||||
bot.visibility = false;
|
||||
bot.getBots = getBots;
|
||||
bot.getplayerusername = {};
|
||||
if (typeof bot.messageLogging === 'undefined') bot.messageLogging = true;
|
||||
|
||||
|
@ -56,9 +58,6 @@ async function createBot(server, config, bots, dcclient) {
|
|||
|
||||
loadPlugins(bot, dcclient, config, rl);
|
||||
|
||||
bot.getBots = () => bots;
|
||||
bots.push(bot);
|
||||
|
||||
const channel = dcclient.channels.cache.get(config.discord.servers[bot.options.host]);
|
||||
|
||||
bot.playersAddedPlayers = {};
|
||||
|
@ -161,7 +160,7 @@ async function createBot(server, config, bots, dcclient) {
|
|||
|
||||
setTimeout(() => {
|
||||
bot.end();
|
||||
createBot(server, config, bots, dcclient);
|
||||
createBot(server, config, getBots, dcclient);
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
|
@ -189,6 +188,8 @@ async function createBot(server, config, bots, dcclient) {
|
|||
// channel.send('uncaught ```\n' + util.inspect(error) + '\n```');
|
||||
// bot.emit('end', 'uncaughtException', 'process: uncaughtException');
|
||||
});
|
||||
|
||||
return bot;
|
||||
};
|
||||
|
||||
module.exports = {createBot};
|
||||
|
|
11
index.js
11
index.js
|
@ -1,8 +1,3 @@
|
|||
/* eslint-disable max-len */
|
||||
/* eslint-disable no-var */
|
||||
/* eslint-disable prefer-rest-params */
|
||||
/* eslint-disable no-tabs */
|
||||
/* eslint-disable no-undef */
|
||||
const config = require('./config');
|
||||
const {createBot} = require('./bot');
|
||||
const {
|
||||
|
@ -25,7 +20,11 @@ const bots = [];
|
|||
|
||||
dcclient.on('ready', () => {
|
||||
config.servers.forEach(async (server) => {
|
||||
createBot(server, config, bots, dcclient);
|
||||
const getBots = () => bots;
|
||||
// await is important cuz the function is async
|
||||
// VVVVV
|
||||
const bot = await createBot(server, config, getBots, dcclient);
|
||||
bots.push(bot);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue