Fix memory leak

This commit is contained in:
Yaode_owo 2025-01-10 12:47:34 -05:00
parent fc0396d9f6
commit 5f12a23894

View file

@ -28,11 +28,15 @@ bot.on('error', (e) => {
if (bot !== undefined) bot.end(e.message);
});
bot.on('end', (reason) => { // Out of memory.
bot.on('end', (reason) => { // Memory leak.
Object.keys(bot._events).forEach((event) => { bot.removeAllListeners(event) })
console.log(`Bot disconnect: ${reason}\nReconnect in 6 seconds...`);
setTimeout(() => {
createBot();
}, 6e3);
setTimeout(() => {
bot = null;
}, 20000); // 20seconds is enough
return;
});
@ -46,6 +50,7 @@ bot.on('custom_profilelessChat', (message, profilelessChat, packet) => {
bot.on('custom_systemChat', (message, systemChat, packet) => {
console.log(`[SystemChat] ${message}`);
console.log(JSON.stringify(systemChat.jsonMsg.message))
});
bot.on('login', () => {