add smth and patch smth
This commit is contained in:
parent
2320953bfa
commit
93ea0c124d
1 changed files with 233 additions and 228 deletions
|
@ -24,7 +24,6 @@ bot.on('systemChat', (packet) => {
|
|||
} else {
|
||||
if (msg !== undefined) bot.emit('custom_systemChat', msg, nocolormsg, jsonmsg);
|
||||
}
|
||||
if (cspy !== undefined) bot.emit('custom_commandspy', cspy);
|
||||
});
|
||||
|
||||
bot.on('playerChat', (packet) => {
|
||||
|
@ -46,32 +45,39 @@ bot.on('playerChat', (packet) => {
|
|||
switch (packet.type) {
|
||||
case 1: // /me text
|
||||
msg = `* ${SenderName} ${formattedMessage}`;
|
||||
nocolorplayermsg = `* ${NoColorSenderName} ${NoColorformattedMessage}`;
|
||||
break;
|
||||
case 2: // someone /tell you text
|
||||
msg = `${SenderName} whispers to you: ${formattedMessage}`;
|
||||
nocolorplayermsg = `${NoColorSenderName} whispers to you: ${NoColorformattedMessage}`;
|
||||
break;
|
||||
case 3: // you /tell someone text
|
||||
msg = `You whisper to ${TargetName}: ${formattedMessage}`;
|
||||
nocolorplayermsg = `You whisper to ${NoColorTargetName}: ${NoColorformattedMessage}`;
|
||||
break;
|
||||
case 4: // player chat
|
||||
// /sudo and vanish send formattedMessage message
|
||||
// normal unsignedContent
|
||||
vmsg = formattedMessage;
|
||||
nocolormsg = NoColorformattedMessage
|
||||
msg = unsignedContent;
|
||||
nocolorplayermsg = NoColorunsignedContent
|
||||
break;
|
||||
case 5: // /say text
|
||||
msg = `[${SenderName}] ${plainMessage ? plainMessage : formattedMessage}`;
|
||||
nocolorplayermsg = `[${NoColorSenderName}] ${plainMessage ? plainMessage : NoColorformattedMessage}`;
|
||||
break;
|
||||
case 6: // /minecraft:teammsg text
|
||||
msg = `${TargetName} <${SenderName}> ${plainMessage}`;
|
||||
nocolorplayermsg = `${NoColorTargetName} <${NoColorSenderName}> ${plainMessage}`;
|
||||
break;
|
||||
default:
|
||||
console.log(`Unknown player_chat packet. Type: ${packet.type}`);
|
||||
console.log(packet)
|
||||
break;
|
||||
}
|
||||
if (msg !== undefined) bot.emit('custom_playerChat', msg, uuid, plainMessage, SenderName, TargetName, formattedMessage, unsignedContent, NoColorSenderName, NoColorTargetName, NoColorformattedMessage, NoColorunsignedContent);
|
||||
if (vmsg !== undefined) bot.emit('custom_systemChat', vmsg, "", "");
|
||||
if (msg !== undefined) bot.emit('custom_playerChat', msg, uuid, plainMessage, SenderName, TargetName, formattedMessage, unsignedContent, NoColorSenderName, NoColorTargetName, NoColorformattedMessage, NoColorunsignedContent, nocolorplayermsg, packet.type);
|
||||
if (vmsg !== undefined) bot.emit('custom_systemChat', vmsg, nocolormsg, "");
|
||||
});
|
||||
|
||||
const ansiColorCodes = {
|
||||
|
@ -102,19 +108,19 @@ function parseMinecraftMessage(component) {
|
|||
|
||||
function extractText(comp) {
|
||||
let text = '';
|
||||
if (comp.text) {
|
||||
if (comp.text && typeof comp.text === 'string' || typeof comp.text === 'number' && comp.text !== undefined && comp.text !== null) {
|
||||
text += comp.text;
|
||||
}
|
||||
if (typeof comp[""] === 'string' || typeof comp[""] === 'number' && comp[""] !== undefined && comp[""] !== null) { // fix if text is {"":0} show false
|
||||
text += comp[""]; // after 1337 years, i found issue at here
|
||||
if (comp[""] && typeof comp[""] === 'string' || typeof comp[""] === 'number' && comp[""] !== undefined && comp[""] !== null) {
|
||||
text += comp[""];
|
||||
}
|
||||
if (typeof comp === 'string' || typeof comp === 'number') {
|
||||
if (comp && typeof comp === 'string' || typeof comp === 'number' && comp !== undefined && comp !== null) {
|
||||
return comp;
|
||||
}
|
||||
|
||||
if (comp.extra) {
|
||||
comp.extra.forEach(subComp => {
|
||||
text += ansiFormatCodes['reset'] + parseMinecraftColor(comp.color) + parseMinecraftFormat(comp) + extractText(subComp) + parseMinecraftColor(comp.color) + parseMinecraftFormat(comp); // it must have better way, but i lazy.
|
||||
text += formatfunction(comp, extractText(subComp));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -123,29 +129,27 @@ function parseMinecraftMessage(component) {
|
|||
if (comp.with) {
|
||||
const withArgs = comp.with.map(arg => extractText(arg));
|
||||
withArgs.forEach((arg, index) => {
|
||||
if (arg.length > 10000) return translateString = ''; // anti tellraw translate crash
|
||||
translateString = translateString.replace('%s', arg + parseMinecraftColor(comp.color) + parseMinecraftFormat(comp)); // i need make formatfunction2(comp, text) ?
|
||||
if (arg.length > 2048) return translateString = ''; // anti tellraw translate crash
|
||||
translateString = translateString.replace('%s', formatfunction(comp, arg));
|
||||
const placeholder = new RegExp(`%${index + 1}\\$s`, 'g'); // create tellraw translate crash
|
||||
translateString = translateString.replace(placeholder, arg + parseMinecraftColor(comp.color) + parseMinecraftFormat(comp));
|
||||
translateString = translateString.replace(placeholder, formatfunction(comp, arg));
|
||||
});
|
||||
}
|
||||
text += translateString;
|
||||
text += formatfunction(comp, translateString);
|
||||
}
|
||||
|
||||
text = formatfunction(comp, text);
|
||||
|
||||
text = parseMinecraftColor(comp.color) + parseMinecraftFormat(comp) + text + ansiFormatCodes['reset'];
|
||||
return text;
|
||||
}
|
||||
|
||||
jsonComponent = extractText(jsonComponent);
|
||||
|
||||
return jsonComponent + ansiFormatCodes['reset'];
|
||||
return extractText(jsonComponent) + ansiFormatCodes['reset'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
function formatfunction(comp, text) {
|
||||
return text = parseMinecraftColor(comp.color) + parseMinecraftFormat(comp) + text + ansiFormatCodes['reset'];
|
||||
if (text === undefined) return '';
|
||||
return text = parseMinecraftColor(comp.color) + parseMinecraftFormat(comp) + text + parseMinecraftColor(comp.color) + parseMinecraftFormat(comp);
|
||||
}
|
||||
|
||||
function parseMinecraftColor(color) {
|
||||
|
@ -168,11 +172,11 @@ function parseMinecraftColor(color) {
|
|||
|
||||
function parseMinecraftFormat(format) {
|
||||
let result = '';
|
||||
if (format.bold) result += ansiFormatCodes['bold'];
|
||||
if (format.italic) result += ansiFormatCodes['italic'];
|
||||
if (format.underlined) result += ansiFormatCodes['underlined'];
|
||||
if (format.strikethrough) result += ansiFormatCodes['strikethrough'];
|
||||
if (format.obfuscated) result += ansiFormatCodes['obfuscated'];
|
||||
if (format.bold && format.bold === 1) result += ansiFormatCodes['bold'];
|
||||
if (format.italic && format.italic === 1) result += ansiFormatCodes['italic'];
|
||||
if (format.underlined && format.underlined === 1) result += ansiFormatCodes['underlined'];
|
||||
if (format.strikethrough && format.strikethrough === 1) result += ansiFormatCodes['strikethrough'];
|
||||
if (format.obfuscated && format.obfuscated === 1) result += ansiFormatCodes['obfuscated'];
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -188,15 +192,15 @@ function parseMinecraftMessageNoColor(component) {
|
|||
function extractText(comp) {
|
||||
let text = '';
|
||||
|
||||
if (comp.text) {
|
||||
if (comp.text && typeof comp.text === 'string' || typeof comp.text === 'number' && comp.text !== undefined && comp.text !== null) {
|
||||
text += comp.text;
|
||||
}
|
||||
if (comp[""]) {
|
||||
if (comp[""] && typeof comp[""] === 'string' || typeof comp[""] === 'number' && comp[""] !== undefined && comp[""] !== null) {
|
||||
text += comp[""];
|
||||
}
|
||||
if (typeof comp === 'string' || typeof comp === 'number') {
|
||||
text += comp;
|
||||
}
|
||||
if (comp && typeof comp === 'string' || typeof comp === 'number' && comp !== undefined && comp !== null) {
|
||||
return comp;
|
||||
}}
|
||||
if (comp.extra) {
|
||||
comp.extra.forEach(subComp => {
|
||||
text += extractText(subComp);
|
||||
|
@ -209,7 +213,7 @@ function parseMinecraftMessageNoColor(component) {
|
|||
withArgs.forEach((arg, index) => {
|
||||
if (arg.length > 10000) return translateString = ''; // anti tellraw translate crash
|
||||
translateString = translateString.replace('%s', arg);
|
||||
const placeholder = new RegExp(`%${index + 1}\\$s`, 'g');
|
||||
const placeholder = new RegExp(`%${index + 1}\\$s`, 'g'); // create tellraw translate crash
|
||||
translateString = translateString.replace(placeholder, arg);
|
||||
|
||||
});
|
||||
|
@ -219,10 +223,11 @@ function parseMinecraftMessageNoColor(component) {
|
|||
|
||||
return text;
|
||||
}
|
||||
|
||||
return extractText(jsonComponent);
|
||||
msgText = extractText(jsonComponent)
|
||||
// msgText = msgText.replace('§', '&')
|
||||
return msgText;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = inject;
|
||||
module.exports = { inject };
|
Loading…
Reference in a new issue