111 lines
No EOL
3.3 KiB
JavaScript
111 lines
No EOL
3.3 KiB
JavaScript
const mineflayer = require('mineflayer');
|
|
|
|
const bot = mineflayer.createBot({
|
|
host: 'chipmunk.land',
|
|
//host: 'kaboom.pw'
|
|
port: 25565,
|
|
username: 'catparser',
|
|
version: "1.20.4",
|
|
});
|
|
|
|
bot._client.on('player_chat', (packet) => {
|
|
//console.log(JSON.stringify(packet.unsignedChatContent))
|
|
console.log(parseMinecraftMessage(packet.unsignedChatContent));
|
|
});
|
|
|
|
const ansiCodes = {
|
|
'§0': '\x1B[30m', // Black
|
|
'§1': '\x1B[34m', // Dark Blue
|
|
'§2': '\x1B[32m', // Dark Green
|
|
'§3': '\x1B[36m', // Dark Aqua
|
|
'§4': '\x1B[31m', // Dark Red
|
|
'§5': '\x1B[35m', // Dark Purple
|
|
'§6': '\x1B[33m', // Gold
|
|
'§7': '\x1B[37m', // Gray
|
|
'§8': '\x1B[90m', // Dark Gray
|
|
'§9': '\x1B[94m', // Blue
|
|
'§a': '\x1B[92m', // Green
|
|
'§b': '\x1B[96m', // Aqua
|
|
'§c': '\x1B[91m', // Red
|
|
'§d': '\x1B[95m', // Light Purple
|
|
'§e': '\x1B[93m', // Yellow
|
|
'§f': '\x1B[97m', // White
|
|
'§l': '\x1B[1m', // Bold
|
|
'§o': '\x1B[3m', // Italic
|
|
'§n': '\x1B[4m', // Underlined
|
|
'§m': '\x1B[9m', // Strikethrough
|
|
'§k': '\x1B[5m', // Obfuscated
|
|
'§r': '\x1B[0m', // Reset
|
|
'black': '\x1B[30m', // Black
|
|
'dark_blue': '\x1B[34m', // Dark Blue
|
|
'dark_green': '\x1B[32m', // Dark Green
|
|
'dark_aqua': '\x1B[36m', // Dark Aqua
|
|
'dark_red': '\x1B[31m', // Dark Red
|
|
'dark_purple': '\x1B[35m', // Dark Purple
|
|
'gold': '\x1B[33m', // Gold
|
|
'gray': '\x1B[37m', // Gray
|
|
'dark_gray': '\x1B[90m', // Dark Gray
|
|
'blue': '\x1B[94m', // Blue
|
|
'green': '\x1B[92m', // Green
|
|
'aqua': '\x1B[96m', // Aqua
|
|
'red': '\x1B[91m', // Red
|
|
'light_purple': '\x1B[95m', // Light Purple
|
|
'yellow': '\x1B[93m', // Yellow
|
|
'white': '\x1B[97m', // White
|
|
'bold': '\x1B[1m', // Bold
|
|
'italic': '\x1B[3m', // Italic
|
|
'underlined': '\x1B[4m', // Underlined
|
|
'strikethrough': '\x1B[9m', // Strikethrough
|
|
'obfuscated': '\x1B[5m', // Obfuscated
|
|
'reset': '\x1B[0m' // Reset
|
|
};
|
|
|
|
function parseMinecraftMessage(component) {
|
|
function extractText(comp) {
|
|
let text = '';
|
|
if (comp.color && ansiCodes[comp.color.value]) {
|
|
text += ansiCodes[comp.color.value];
|
|
}
|
|
if (comp.bold && comp.bold.value === 1) {
|
|
text += "\x1b[1m"; // Bold
|
|
}
|
|
if (comp.underlined && comp.underlined.value === 1) {
|
|
text += "\x1b[4m"
|
|
}
|
|
if (comp.strikethrough && comp.strikethrough.value === 1) {
|
|
text += "\x1b[9m"
|
|
}
|
|
if (comp.obfuscated && comp.obfuscated.value === 1) {
|
|
text += "\x1b[5m" // useless
|
|
}
|
|
if (comp.text && comp.text.value) {
|
|
text += comp.text.value;
|
|
} else if (!comp.text) {
|
|
text += " ";
|
|
}
|
|
if (comp.extra && comp.extra.value && Array.isArray(comp.extra.value.value)) {
|
|
comp.extra.value.value.forEach(subComp => {
|
|
if (subComp === " ") { text += extractText(subComp)+" "; } else { text += extractText(subComp); };
|
|
});
|
|
}
|
|
if (comp.color && ansiCodes[comp.color.value]) {
|
|
text += ansiCodes['§r'];
|
|
}
|
|
return text;
|
|
}
|
|
|
|
const mainComponents = component.value.extra.value.value;
|
|
let result = '';
|
|
|
|
mainComponents.forEach(comp => {
|
|
if (comp.text || (comp.extra && comp.extra.value && Array.isArray(comp.extra.value.value))) {
|
|
result += extractText(comp);
|
|
} else {
|
|
for (let key in comp) {
|
|
result += comp[key].value;
|
|
}
|
|
}
|
|
});
|
|
|
|
return result;
|
|
} |