mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-23 15:47:57 -05:00
uncaught disconnect fix (might not work)
this happened for months now and this might fix it (means it could not work, this is not tested because it only happens on webserver)
This commit is contained in:
parent
ed928977aa
commit
4fa570f951
1 changed files with 16 additions and 7 deletions
23
bot.js
23
bot.js
|
@ -36,20 +36,29 @@ async function createBot (server, config, getBots, setNewBot, dcclient, rl) {
|
|||
port: server.port
|
||||
}
|
||||
|
||||
bot._client = mc.createClient(bot.options)
|
||||
bot.visibility = false
|
||||
bot.getBots = getBots
|
||||
|
||||
bot.setMaxListeners(Infinity) // is this bad code?
|
||||
bot._client.setMaxListeners(Infinity) // this too
|
||||
bot.version = bot._client.version
|
||||
bot.write = (name, data) => bot._client.write(name, data)
|
||||
bot.end = (reason = 'end', event) => {
|
||||
bot.emit('end', reason, event)
|
||||
bot.removeAllListeners()
|
||||
bot._client.end()
|
||||
bot._client.removeAllListeners()
|
||||
}
|
||||
bot.visibility = false
|
||||
bot.getBots = getBots
|
||||
|
||||
try {
|
||||
bot._client = mc.createClient(bot.options)
|
||||
} catch (e) {
|
||||
// should i make like if error is only econnrefused and others?
|
||||
// btw this is to prevent uncaught (which does not reconnect the bot)
|
||||
bot.end(e.toString(), 'uncaught but actually no') // will display "Disconnected (uncaught but actually no event): error here"
|
||||
}
|
||||
|
||||
bot.setMaxListeners(Infinity)
|
||||
bot._client.setMaxListeners(Infinity)
|
||||
|
||||
bot.version = bot._client.version
|
||||
bot.write = (name, data) => bot._client.write(name, data)
|
||||
|
||||
await sleep(200)
|
||||
|
||||
|
|
Loading…
Reference in a new issue