2022-12-05 03:16:48 -05:00
|
|
|
|
|
2022-08-14 05:51:45 -04:00
|
|
|
|
// 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-12-05 02:55:54 -05:00
|
|
|
|
function inject (bot, dcclient, config) {
|
2022-11-27 02:35:28 -05:00
|
|
|
|
bot.chatQueue = []
|
2022-12-05 02:55:54 -05:00
|
|
|
|
const _chatQueue = []
|
2022-11-12 04:34:17 -05:00
|
|
|
|
|
2022-12-05 02:55:54 -05:00
|
|
|
|
const _chatQueueInterval = setInterval(() => {
|
|
|
|
|
if (bot.chatQueue.length !== 0) {
|
|
|
|
|
if (containsIllegalCharacters(bot.chatQueue[0])) {
|
2022-11-27 02:35:28 -05:00
|
|
|
|
bot.chatQueue.shift()
|
2022-12-05 02:55:54 -05:00
|
|
|
|
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()
|
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
|
|
|
|
|
2022-11-30 04:45:20 -05:00
|
|
|
|
bot.on('end', () => {
|
2022-12-05 02:55:54 -05:00
|
|
|
|
clearInterval(chatQueueInterval)
|
|
|
|
|
clearInterval(_chatQueueInterval)
|
2022-11-27 02:35:28 -05:00
|
|
|
|
})
|
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 }
|