owobot/util/chatparse_1204.js
7cc5c4f330d47060 9f99a1bbf1 Add error handler to this for some reason
I got a maximum call stack size exceeded error in this code...
2024-07-30 15:40:28 -04:00

21 lines
518 B
JavaScript

const { processNbtMessage } = require('prismarine-chat')
const parse = function (data) {
if (typeof data.type === 'string') {
return JSON.parse(processNbtMessage(data))
} else if (typeof data === 'string') {
return JSON.parse(data)
} else {
return data
}
}
const parse2 = function (_data) {
try {
return parse(_data)
} catch (e) {
console.error(e)
return {
text: 'An error occured while parsing a message. See console for more information.'
}
}
}
module.exports = parse