This commit is contained in:
Yaode_owo 2024-09-20 10:31:24 -04:00
parent ab12b2f68d
commit fbc4675364
2 changed files with 6328 additions and 0 deletions

6219
en_us.json Normal file

File diff suppressed because it is too large Load diff

109
kickparsermsg.js Normal file
View file

@ -0,0 +1,109 @@
const lang = require("./en_us.json");
const msg = {
reason: '{"translate":"multiplayer.disconnect.unverified_username"}'
}
const msg2 = {
"reason": {
"type": "compound",
"value": {
"with": {
"type": "list",
"value": {
"type": "string",
"value": [ "Internal Exception: io.netty.handler.codec.EncoderException: java.io.UTFDataFormatException: encoded string (t§k腻腻腻腻腻...腻腻腻腻§rno) too long: 97869 bytes" ]
}
},
"translate": {
"type": "string",
"value": "disconnect.genericReason"
}
}
}
}
console.log(kickparser(msg));
console.log(kickparser(msg2));
// lazy to make it color
function kickparser(component) {
if (component === undefined) return component;
function kickparserText(comp) {
let text = '';
if (typeof comp === 'string') {
text += comp;
}
if (typeof comp.value === 'string') {
text += comp.value;
}
if (comp.with) {
text += kickparserText(comp.with);
}
if (comp.value) {
[comp.value].forEach(subComp => {
if (typeof subComp === 'string') text += subComp;
text += kickparserText(subComp);
});
}
// how did i write this???
if (comp.translate) {
let translateString = lang[comp.translate.value] || comp.translate.value;
if (typeof translateString === 'string') {
if (comp.with) {
const withArray = Array.isArray(comp.with.value) ? comp.with.value : [comp.with.value];
let formattedString = translateString;
const replacements = [];
withArray.forEach((replacementText) => {
if (replacementText.value) {
const items = Array.isArray(replacementText.value) ? replacementText.value : [replacementText.value];
items.forEach((item) => {
const itemText = kickparserText(item);
if (itemText) replacements.push(itemText);
if (item.with && item.with.value) {
const nestedValues = Array.isArray(item.with.value) ? item.with.value : [item.with.value];
nestedValues.forEach(nestedItem => {
const nestedText = kickparserText(nestedItem);
if (nestedText) replacements.push(nestedText);
});
}
});
}
});
let replacementIndex = 0;
formattedString = formattedString.replace(/%s/g, () => {
return replacementIndex < replacements.length ? replacements[replacementIndex++] : '%s';
});
text += formattedString;
} else {
text += kickparserText(translateString);
}
} else {
throw new Error(`Translation not found for key: ${comp.translate.value}`);
}
}
return text;
}
let result = ''; // Initialize result to an empty string
[component].forEach((comp) => {
if (comp.reason) { // Check if reason is defined
result += kickparserText(comp.reason);
}
});
return result
}