/* eslint-disable max-len */ /* eslint-disable require-jsdoc */ // 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) { bot.chatQueue = [] const chatQueue = setInterval(function () { if (bot.chatQueue[0] || bot.chatQueue[0] === '') { try { if (containsIllegalCharacters(bot.chatQueue[0])) { bot.chatQueue.shift() return }; bot.write('chat', { message: bot.chatQueue[0] }) bot.chatQueue.shift() } catch (e) { bot.console.error(e) } } }, 450) bot.chat = (message) => { bot.chatQueue.push(String(message)) } bot.on('end', () => { clearInterval(chatQueue) }) 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 }