chat queue broke everything, answer revealed.

This commit is contained in:
ChomeNS 2022-11-18 08:34:18 +07:00
parent fb9eae6d52
commit b0cd12c717

View file

@ -7,24 +7,15 @@ const {chatPacketListener, parsePlayerMessages} = require('../util/chat');
function inject(bot) { function inject(bot) {
bot.chatQueue = []; bot.chatQueue = [];
let chatQueueSplitted;
const chatQueue = setInterval(function() { const chatQueue = setInterval(function() {
if (bot.chatQueue[0] || bot.chatQueue[0] === '') { 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() {
if (chatQueueSplitted) {
try { try {
bot.write('chat', {message: chatQueueSplitted[0]}); if (containsIllegalCharacters(bot.chatQueue[0])) {
chatQueueSplitted.shift(); bot.chatQueue.shift();
return;
};
bot.write('chat', {message: bot.chatQueue[0]});
bot.chatQueue.shift(); bot.chatQueue.shift();
} catch (e) { } catch (e) {
bot.console.error(e); bot.console.error(e);
@ -38,7 +29,6 @@ function inject(bot) {
bot.once('end', () => { bot.once('end', () => {
clearInterval(chatQueue); clearInterval(chatQueue);
clearInterval(sendChatQueue);
}); });
let previousMessage; let previousMessage;