mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-30 02:55:44 -05:00
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
/* 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.once('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};
|