// eslint-disable-next-line no-undef // const parse = require('../util/text_parser'); const { containsIllegalCharacters } = require('../util/containsIllegalCharacters') const { chatPacketListener, parsePlayerMessages } = require('../util/chat') function inject (bot, dcclient, config) { bot.chatQueue = [] const _chatQueue = [] const _chatQueueInterval = setInterval(() => { if (bot.chatQueue.length !== 0) { if (containsIllegalCharacters(bot.chatQueue[0])) { bot.chatQueue.shift() return }; // totallynotskidded™️ from mineflayer/lib/plugins/chat.js bot.chatQueue[0].split('\n').forEach((subMessage) => { if (!subMessage) return let smallMsg for (let i = 0; i < subMessage.length; i += config.chat.messageLength) { smallMsg = subMessage.substring(i, i + config.chat.messageLength) _chatQueue.push(smallMsg) } }) bot.chatQueue.shift() } }, 0) const chatQueueInterval = setInterval(function () { if (_chatQueue.length !== 0) { bot.write('chat', { message: _chatQueue[0] }) _chatQueue.shift() } }, 450) bot.chat = (message) => { bot.chatQueue.push(String(message)) } bot.on('end', () => { clearInterval(chatQueueInterval) clearInterval(_chatQueueInterval) }) const ChatMessage = require('prismarine-chat')(bot.version) bot._client.on('chat', (packet) => chatPacketListener(packet, ChatMessage, bot)) bot.on('parsed_chat', (message, packet) => parsePlayerMessages(message, packet, bot)) } module.exports = { inject }