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:
ChomeNS 2023-01-24 17:14:47 +07:00
parent ed928977aa
commit 4fa570f951

23
bot.js
View file

@ -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)