FridayNightFunkinBoyfriendBot/src/modules/reconnect.js

24 lines
696 B
JavaScript
Raw Normal View History

2024-07-20 20:27:17 -04:00
const mc = require('minecraft-protocol');
const usernameGen = require("../util/usernameGen");
function reconnect (bot, options, config) {
2024-07-07 15:44:16 -04:00
bot.on('end', () => {
//bot = undefined;
bot._client.removeAllListeners();
//client = undefined;
//bot._client = undefined;
2024-07-07 15:44:16 -04:00
if (bot.reconnectDelay < 0) return
2024-07-20 20:27:17 -04:00
setTimeout(() => {
if (options.usernameGen) {
client = options.client ?? mc.createClient(options, options.username = usernameGen(bot))
2024-07-20 20:27:17 -04:00
} else {
client = options.client ?? mc.createClient(options)
}
bot._client = client
bot.emit('init_client', bot._client)
}, options.reconnectDelay);
2024-07-07 15:44:16 -04:00
})
}
module.exports = reconnect;