2022-11-27 02:35:28 -05:00
|
|
|
|
const { containsIllegalCharacters } = require('../util/containsIllegalCharacters')
|
|
|
|
|
const { chatPacketListener, parsePlayerMessages } = require('../util/chat')
|
2022-12-10 01:31:01 -05:00
|
|
|
|
const minecraftVersionToNumber = require('../util/minecraftVersionToNumber')
|
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 04:54:50 -05:00
|
|
|
|
bot._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
|
2023-01-23 07:19:49 -05:00
|
|
|
|
for (const subMessage of bot.chatQueue[0].split('\n')) {
|
2022-12-05 02:55:54 -05:00
|
|
|
|
if (!subMessage) return
|
|
|
|
|
let smallMsg
|
|
|
|
|
for (let i = 0; i < subMessage.length; i += config.chat.messageLength) {
|
|
|
|
|
smallMsg = subMessage.substring(i, i + config.chat.messageLength)
|
2022-12-05 04:54:50 -05:00
|
|
|
|
bot._chatQueue.push(smallMsg)
|
2022-12-05 02:55:54 -05:00
|
|
|
|
}
|
2023-01-23 07:19:49 -05:00
|
|
|
|
}
|
2022-12-05 02:55:54 -05:00
|
|
|
|
bot.chatQueue.shift()
|
|
|
|
|
}
|
|
|
|
|
}, 0)
|
|
|
|
|
|
|
|
|
|
const chatQueueInterval = setInterval(function () {
|
2022-12-05 04:54:50 -05:00
|
|
|
|
if (bot._chatQueue.length !== 0) {
|
2022-12-10 01:31:01 -05:00
|
|
|
|
if (minecraftVersionToNumber(bot.version) >= 1.19) {
|
|
|
|
|
// totallynotskidded™️ from mineflayer/lib/plugins/chat.js
|
|
|
|
|
if (bot._chatQueue[0].startsWith('/')) {
|
|
|
|
|
bot.write('chat_command', {
|
|
|
|
|
command: bot._chatQueue[0].substring(1), // removes / from the command
|
|
|
|
|
timestamp: BigInt(Date.now()),
|
|
|
|
|
salt: 0n,
|
|
|
|
|
argumentSignatures: [],
|
|
|
|
|
signedPreview: false
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
bot.write('chat_message', {
|
|
|
|
|
message: bot._chatQueue[0],
|
|
|
|
|
timestamp: BigInt(Date.now()),
|
|
|
|
|
salt: 0,
|
|
|
|
|
signature: Buffer.alloc(0) // the bot will never go online mode i guess so i will just use this
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
bot.write('chat', { message: bot._chatQueue[0] })
|
|
|
|
|
}
|
2022-12-05 04:54:50 -05:00
|
|
|
|
bot._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-12-10 01:31:01 -05:00
|
|
|
|
function listener (packet) {
|
|
|
|
|
chatPacketListener(
|
|
|
|
|
packet,
|
|
|
|
|
bot,
|
|
|
|
|
minecraftVersionToNumber(bot.version) >= 1.19
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
bot._client.on('system_chat', listener)
|
|
|
|
|
bot._client.on('chat', listener)
|
2022-11-10 07:38:14 -05:00
|
|
|
|
|
2022-12-12 03:06:50 -05:00
|
|
|
|
bot.on('message', (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 }
|