From 3f10357d94d5ab29fe7054e8cdd3a68f3b88d6b0 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Thu, 17 Nov 2022 14:13:08 +0700 Subject: [PATCH] hope this fix the multiple thingy ploblem --- bot.js | 1 + plugins/chat.js | 22 ++++++++++++++++------ plugins/proxy.js | 6 ++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/bot.js b/bot.js index 6a62517..8cea615 100644 --- a/bot.js +++ b/bot.js @@ -49,6 +49,7 @@ async function createBot(server, config, getBots, dcclient) { bot.removeAllListeners(); bot._client.end(); bot._client.removeAllListeners(); + process.removeAllListeners(); }; bot.visibility = false; bot.getBots = getBots; diff --git a/plugins/chat.js b/plugins/chat.js index a823bc6..5a6fce9 100644 --- a/plugins/chat.js +++ b/plugins/chat.js @@ -7,16 +7,25 @@ const {chatPacketListener, parsePlayerMessages} = require('../util/chat'); function inject(bot) { bot.chatQueue = []; + let chatQueueSplitted; const chatQueue = setInterval(function() { + if (bot.chatQueue[0] || bot.chatQueue[0] === '') { + if (containsIllegalCharacters(bot.chatQueue[0])) { + bot.chatQueue.shift(); + return; + }; + chatQueueSplitted = bot.chatQueue[0].match(/.{0,224}/g); + chatQueueSplitted.pop(); + } + }, 20); + + const sendChatQueue = setInterval(function() { try { - if (bot.chatQueue[0] || bot.chatQueue[0] === '') { + if (chatQueueSplitted) { try { - if (containsIllegalCharacters(bot.chatQueue[0])) { - bot.chatQueue.shift(); - return; - }; - bot.write('chat', {message: bot.chatQueue[0].substring(0, 256)}); + bot.write('chat', {message: chatQueueSplitted[0]}); + chatQueueSplitted.shift(); bot.chatQueue.shift(); } catch (e) { bot.console.error(e); @@ -33,6 +42,7 @@ function inject(bot) { bot.once('end', () => { clearInterval(chatQueue); + clearInterval(sendChatQueue); }); let previousMessage; diff --git a/plugins/proxy.js b/plugins/proxy.js index 6e465ac..f226c40 100644 --- a/plugins/proxy.js +++ b/plugins/proxy.js @@ -50,17 +50,23 @@ function inject(bot, dcclient, config) { targetClient.on('end', () => { targetClient.end(); + targetClient.removeAllListeners(); + client.removeAllListeners(); endedTarget = true; }); client.on('end', function() { endedClient = true; targetClient.end(); + targetClient.removeAllListeners(); + client.removeAllListeners(); bot.console.info(`[Proxy] ${client.username} ended`); }); client.on('error', function() { endedClient = true; + targetClient.removeAllListeners(); + client.removeAllListeners(); bot.console.info(`[Proxy] ${client.username} got error`); });