2022-08-14 05:51:45 -04:00
|
|
|
/* eslint-disable max-len */
|
|
|
|
/* eslint-disable require-jsdoc */
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
// const parse = require('../util/text_parser');
|
2022-11-27 02:35:28 -05:00
|
|
|
const { containsIllegalCharacters } = require('../util/containsIllegalCharacters')
|
|
|
|
const { chatPacketListener, parsePlayerMessages } = require('../util/chat')
|
2022-11-16 08:21:19 -05:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
function inject (bot) {
|
|
|
|
bot.chatQueue = []
|
2022-11-12 04:34:17 -05:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
const chatQueue = setInterval(function () {
|
2022-11-17 02:13:08 -05:00
|
|
|
if (bot.chatQueue[0] || bot.chatQueue[0] === '') {
|
2022-11-17 19:46:52 -05:00
|
|
|
try {
|
2022-11-17 20:34:18 -05:00
|
|
|
if (containsIllegalCharacters(bot.chatQueue[0])) {
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.chatQueue.shift()
|
|
|
|
return
|
2022-11-17 20:34:18 -05:00
|
|
|
};
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.write('chat', { message: bot.chatQueue[0] })
|
|
|
|
bot.chatQueue.shift()
|
2022-11-17 19:46:52 -05:00
|
|
|
} catch (e) {
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.console.error(e)
|
2022-11-12 04:34:17 -05:00
|
|
|
}
|
|
|
|
}
|
2022-11-27 02:35:28 -05:00
|
|
|
}, 450)
|
2022-11-12 04:34:17 -05:00
|
|
|
|
|
|
|
bot.chat = (message) => {
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.chatQueue.push(String(message))
|
|
|
|
}
|
2022-11-12 04:34:17 -05:00
|
|
|
|
|
|
|
bot.once('end', () => {
|
2022-11-27 02:35:28 -05:00
|
|
|
clearInterval(chatQueue)
|
|
|
|
})
|
2022-11-12 04:34:17 -05:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
const ChatMessage = require('prismarine-chat')(bot.version)
|
2022-10-18 20:59:58 -04:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
bot._client.on('chat', (packet) => chatPacketListener(packet, ChatMessage, bot))
|
2022-11-10 07:38:14 -05:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.on('parsed_chat', (message, packet) => parsePlayerMessages(message, packet, bot))
|
2022-11-16 08:21:19 -05:00
|
|
|
}
|
2022-11-10 07:38:14 -05:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
module.exports = { inject }
|