Bugfixes
This commit is contained in:
parent
4c99aa3d4b
commit
c3fa4ae039
4 changed files with 51 additions and 48 deletions
|
@ -16,7 +16,7 @@ module.exports = {
|
|||
b._client.on('profileless_chat', (data) => {
|
||||
if (data.type === 4) {
|
||||
const json = parse1204(data.message)
|
||||
const parsed = parse(json)[1]
|
||||
const parsed = parse(json).plain
|
||||
const split = parsed.split(': ')
|
||||
const chatName = split.splice(0, 1)[0]
|
||||
const username = b.findRealName(chatName)
|
||||
|
@ -34,15 +34,15 @@ module.exports = {
|
|||
},
|
||||
type: 'profileless',
|
||||
uuid: '00000000-0000-0000-0000-000000000000',
|
||||
message: parse(parse1204(data.message))[1],
|
||||
username: parse(parse1204(data.name))[1]
|
||||
message: parse(parse1204(data.message)).plain,
|
||||
username: parse(parse1204(data.name)).plain
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
b._client.on('player_chat', (data) => {
|
||||
if (data.type === 4) {
|
||||
b.emit('chat', { json: parse1204(data.unsignedChatContent), type: 'player', uuid: data.senderUuid, message: data.plainMessage, username: parse(parse1204(data.networkName))[1] })
|
||||
b.emit('chat', { json: parse1204(data.unsignedChatContent), type: 'player', uuid: data.senderUuid, message: data.plainMessage, username: parse(parse1204(data.networkName)).plain })
|
||||
} else {
|
||||
b.emit('chat', {
|
||||
json: {
|
||||
|
@ -55,14 +55,14 @@ module.exports = {
|
|||
},
|
||||
type: 'player',
|
||||
uuid: data.senderUuid,
|
||||
message: parse(data.plainMessage)[1],
|
||||
username: parse(parse1204(data.networkName))[1]
|
||||
message: parse(data.plainMessage).plain,
|
||||
username: parse(parse1204(data.networkName)).plain
|
||||
})
|
||||
}
|
||||
})
|
||||
b._client.on('system_chat', (data) => {
|
||||
const json = parse1204(data.content)
|
||||
const parsed = parse(json)[1]
|
||||
const parsed = parse(json).plain
|
||||
const split = parsed.split(': ')
|
||||
const chatName = split.splice(0, 1)[0]
|
||||
const username = b.findRealName(chatName)
|
||||
|
@ -80,10 +80,10 @@ module.exports = {
|
|||
})
|
||||
b.on('chat', (data) => {
|
||||
const msg = parse(data.json)
|
||||
if (msg[1].endsWith('\n\n\n\n\nThe chat has been cleared')) return
|
||||
if (msg[1].startsWith('Command set: ')) return
|
||||
b.emit('plainchat', msg[1])
|
||||
console2.write(`[${b.id}] [${data.type}] ${msg[0]}\x1b[0m`)
|
||||
if (msg.plain.endsWith('\n\n\n\n\nThe chat has been cleared')) return
|
||||
if (msg.plain.startsWith('Command set: ')) return
|
||||
b.emit('plainchat', msg.plain)
|
||||
console2.write(`[${b.id}] [${data.type}] ${msg.console}\x1b[0m`)
|
||||
const fullCommand = data.message
|
||||
|
||||
for (const i in b.prefix) {
|
||||
|
|
|
@ -13,11 +13,11 @@ module.exports = {
|
|||
uuid = data.data[i].UUID
|
||||
}
|
||||
if (data.data[i].player && data.data[i].player.name !== undefined) {
|
||||
buffer2[uuid] = { realName: data.data[i].player.name, displayName: parse(parse1204(data.data[i].displayName))[1] }
|
||||
buffer2[uuid] = { realName: data.data[i].player.name, displayName: parse(parse1204(data.data[i].displayName)).plain }
|
||||
} else if (data.data[i].name !== undefined) {
|
||||
buffer2[uuid] = { realName: data.data[i].name, displayName: parse(parse1204(data.data[i].displayName))[1] }
|
||||
buffer2[uuid] = { realName: data.data[i].name, displayName: parse(parse1204(data.data[i].displayName)).plain }
|
||||
} else if (data.data[i].displayName !== undefined) {
|
||||
buffer2[uuid] = { displayName: parse(parse1204(data.data[i].displayName))[1] }
|
||||
buffer2[uuid] = { displayName: parse(parse1204(data.data[i].displayName)).plain }
|
||||
}
|
||||
}
|
||||
for (const uuid in buffer2) {
|
||||
|
|
|
@ -8,7 +8,7 @@ const lang = settings.defaultLang
|
|||
class ConsoleCommand {
|
||||
constructor (cmd, index2) {
|
||||
this.send = () => {} // not needed for console
|
||||
this.reply = text => process.stdout.write(parse(text)[0] + '\n')
|
||||
this.reply = text => process.stdout.write(parse(text).console + '\n')
|
||||
this.uuid = 'dde5a2a6-ebdd-4bbb-8eac-f75b10c10446_console' // hard-coded because uuid does not exist at console
|
||||
this.username = 'Owner'
|
||||
this.nickname = 'Console'
|
||||
|
|
|
@ -30,17 +30,17 @@ const hexColorParser = (color) => {
|
|||
return out + `38;2;${redChannel};${greenChannel};${blueChannel}m`
|
||||
}
|
||||
const processColor = (col, rcol) => {
|
||||
const out = ['', '']
|
||||
let out;
|
||||
if (col === 'reset') {
|
||||
out[0] = rcol[0]
|
||||
out = rcol
|
||||
} else if (col.startsWith('#')) {
|
||||
out[0] = hexColorParser(col)
|
||||
out = hexColorParser(col)
|
||||
} else {
|
||||
out[0] = consoleColors[col]
|
||||
out = consoleColors[col]
|
||||
}
|
||||
return out
|
||||
}
|
||||
const parse = function (_data, l = 0, resetColor = [consoleColors.reset]) {
|
||||
const parse = function (_data, l = 0, resetColor = consoleColors.reset) {
|
||||
if (l >= 12) {
|
||||
return ['', '', '']
|
||||
}
|
||||
|
@ -55,21 +55,25 @@ const parse = function (_data, l = 0, resetColor = [consoleColors.reset]) {
|
|||
data = _data
|
||||
}
|
||||
let nkt = false
|
||||
const out = ['', '', ''] // console plain minecraft
|
||||
const out = {
|
||||
console: "", // Console formatting using ANSI escape codes for colors
|
||||
plain: "", // Plain formatting with no colors
|
||||
minecraft: "" // Minecraft section sign formatting
|
||||
}
|
||||
if (data['']) {
|
||||
data.text = data['']
|
||||
nkt = true
|
||||
}
|
||||
if (data.color) {
|
||||
if (data.color === 'reset') {
|
||||
out[0] += resetColor[0]
|
||||
out.console += resetColor
|
||||
} else if (data.color.startsWith('#')) {
|
||||
out[0] += hexColorParser(data.color)
|
||||
out.console += hexColorParser(data.color)
|
||||
} else {
|
||||
out[0] += consoleColors[data.color]
|
||||
out.console += consoleColors[data.color]
|
||||
}
|
||||
} else {
|
||||
out[0] += resetColor[0]
|
||||
out.console += resetColor
|
||||
}
|
||||
if (data.text) {
|
||||
let _text = data.text
|
||||
|
@ -77,12 +81,11 @@ const parse = function (_data, l = 0, resetColor = [consoleColors.reset]) {
|
|||
_text = _text.toString()
|
||||
}
|
||||
if (nkt) {
|
||||
out[0] += resetColor[0]
|
||||
out[2] += resetColor[1]
|
||||
out.console += resetColor
|
||||
}
|
||||
out[0] += _text.replaceAll('\x1b', '').replaceAll('\x0e', '') // Remove escape codes and [SO] from console format
|
||||
out[1] += _text
|
||||
out[2] += _text
|
||||
out.console += _text.replaceAll('\x1b', '').replaceAll('\x0e', '') // Remove escape codes and [SO] from console format
|
||||
out.plain += _text
|
||||
out.minecraft += _text
|
||||
}
|
||||
if (data.translate) {
|
||||
let trans = data.translate.replace(/%%/g, '\ue123').replaceAll('\x1b', '').replaceAll('\x0e', '') // Remove escape codes from console format
|
||||
|
@ -95,26 +98,26 @@ const parse = function (_data, l = 0, resetColor = [consoleColors.reset]) {
|
|||
}
|
||||
for (const i in data.with) {
|
||||
const j2 = parse(data.with[i], l + 1, data.color ? processColor(data.color, resetColor) : resetColor)
|
||||
trans = trans.replace(/%s/, j2[0].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
trans2 = trans2.replace(/%s/, j2[1].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
trans3 = trans3.replace(/%s/, j2[2].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
trans = trans.replaceAll(`%${+i + 1}$s`, j2[0].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
trans2 = trans2.replaceAll(`%${+i + 1}$s`, j2[1].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
trans3 = trans3.replaceAll(`%${+i + 1}$s`, j2[2].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
trans = trans.replace(/%s/, j2.console.replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
trans2 = trans2.replace(/%s/, j2.plain.replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
trans3 = trans3.replace(/%s/, j2.minecraft.replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
trans = trans.replaceAll(`%${+i + 1}$s`, j2.console.replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
trans2 = trans2.replaceAll(`%${+i + 1}$s`, j2.plain.replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
trans3 = trans3.replaceAll(`%${+i + 1}$s`, j2.minecraft.replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
}
|
||||
out[0] += trans.replace(/\ue123/g, '%').replace(/\ue124/g, '%s').replace(/\ue125/g, '$s')
|
||||
out[1] += trans2.replace(/\ue123/g, '%').replace(/\ue124/g, '%s').replace(/\ue125/g, '$s')
|
||||
out[2] += trans3.replace(/\ue123/g, '%').replace(/\ue124/g, '%s').replace(/\ue125/g, '$s')
|
||||
out.console += trans.replace(/\ue123/g, '%').replace(/\ue124/g, '%s').replace(/\ue125/g, '$s')
|
||||
out.plain += trans2.replace(/\ue123/g, '%').replace(/\ue124/g, '%s').replace(/\ue125/g, '$s')
|
||||
out.minecraft += trans3.replace(/\ue123/g, '%').replace(/\ue124/g, '%s').replace(/\ue125/g, '$s')
|
||||
}
|
||||
if (data.extra) {
|
||||
for (const i in data.extra) {
|
||||
const parsed = parse(data.extra[i], l, data.color ? processColor(data.color, resetColor) : resetColor)
|
||||
out[0] += parsed[0]
|
||||
out[1] += parsed[1]
|
||||
out[2] += parsed[2]
|
||||
out.console += parsed.console
|
||||
out.plain += parsed.plain
|
||||
out.minecraft += parsed.minecraft
|
||||
}
|
||||
}
|
||||
out[0] += resetColor[0]
|
||||
out.console += resetColor
|
||||
return out
|
||||
}
|
||||
const parse2 = function (_data, l, resetColor) {
|
||||
|
@ -122,11 +125,11 @@ const parse2 = function (_data, l, resetColor) {
|
|||
return parse(_data)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return [
|
||||
'\x1B[0m\x1B[38;2;255;85;85mAn error occured while parsing a message. See console for more information.\nJSON that caused the error: ' + JSON.stringify(_data),
|
||||
'An error occured while parsing a message. See console for more information. JSON that caused the error: ' + JSON.stringify(_data),
|
||||
'§cAn error occured while parsing a message. See console for more information. JSON that caused the error: ' + JSON.stringify(_data)
|
||||
]
|
||||
return {
|
||||
console: '\x1B[0m\x1B[38;2;255;85;85mAn error occured while parsing a message. See console for more information.\nJSON that caused the error: ' + JSON.stringify(_data),
|
||||
plain: 'An error occured while parsing a message. See console for more information. JSON that caused the error: ' + JSON.stringify(_data),
|
||||
minecraft: '§cAn error occured while parsing a message. See console for more information. JSON that caused the error: ' + JSON.stringify(_data)
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = parse2
|
||||
|
|
Loading…
Reference in a new issue