mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-27 01:25:33 -05:00
add \n and >256 length support for chat
This commit is contained in:
parent
e0d29d0d9e
commit
9986dd31ed
4 changed files with 33 additions and 17 deletions
|
@ -16,7 +16,10 @@ module.exports = {
|
|||
version: '1.18.2'
|
||||
},
|
||||
console: true,
|
||||
useChat: false,
|
||||
chat: {
|
||||
useChat: false,
|
||||
messageLength: 100
|
||||
},
|
||||
core: {
|
||||
layers: 3,
|
||||
refillInterval: 1000 * 60,
|
||||
|
|
|
@ -5,21 +5,33 @@
|
|||
const { containsIllegalCharacters } = require('../util/containsIllegalCharacters')
|
||||
const { chatPacketListener, parsePlayerMessages } = require('../util/chat')
|
||||
|
||||
function inject (bot) {
|
||||
function inject (bot, dcclient, config) {
|
||||
bot.chatQueue = []
|
||||
const _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] })
|
||||
const _chatQueueInterval = setInterval(() => {
|
||||
if (bot.chatQueue.length !== 0) {
|
||||
if (containsIllegalCharacters(bot.chatQueue[0])) {
|
||||
bot.chatQueue.shift()
|
||||
} catch (e) {
|
||||
bot.console.error(e)
|
||||
}
|
||||
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()
|
||||
}
|
||||
}, 450)
|
||||
|
||||
|
@ -28,7 +40,8 @@ function inject (bot) {
|
|||
}
|
||||
|
||||
bot.on('end', () => {
|
||||
clearInterval(chatQueue)
|
||||
clearInterval(chatQueueInterval)
|
||||
clearInterval(_chatQueueInterval)
|
||||
})
|
||||
|
||||
const ChatMessage = require('prismarine-chat')(bot.version)
|
||||
|
|
|
@ -14,7 +14,7 @@ function inject (bot, dcclient, config) {
|
|||
},
|
||||
run (command) {
|
||||
try {
|
||||
if (config.useChat &&
|
||||
if (config.chat.useChat &&
|
||||
command.startsWith('minecraft:tellraw @a ') &&
|
||||
!command.includes('Console') &&
|
||||
!command.includes('Discord')
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* @return {boolean} allowed
|
||||
*/
|
||||
function isAllowedCharacter (character) {
|
||||
return character !== '\xa7' && character >= ' ' && character !== '\x7f'
|
||||
return character !== '\xa7' && character !== '\x7f'
|
||||
}
|
||||
/**
|
||||
* mc chat check if contains illegal chars.
|
||||
|
@ -16,4 +16,4 @@ function containsIllegalCharacters (string) {
|
|||
for (let i = 0; i < string.length; i++) if (!isAllowedCharacter(string[i])) return true
|
||||
}
|
||||
|
||||
module.exports = { containsIllegalCharacters }
|
||||
module.exports = { containsIllegalCharacters, isAllowedCharacter }
|
||||
|
|
Loading…
Reference in a new issue