fix comp.translate message and validText
This commit is contained in:
parent
0b53449fc8
commit
b585c08317
2 changed files with 26 additions and 30 deletions
|
@ -5,7 +5,7 @@
|
|||
*
|
||||
* Language File Version: 1.21.3
|
||||
*
|
||||
* ChatParser Version: 1426
|
||||
* ChatParser Version: 1529
|
||||
*
|
||||
* Update:
|
||||
* - fix translate
|
||||
|
@ -68,7 +68,7 @@ function processNBTComponent(data) {
|
|||
}
|
||||
}
|
||||
|
||||
function VaildText(comp) {
|
||||
function ValidText(comp) {
|
||||
return (typeof comp === "string" && comp !== "") ||
|
||||
(typeof comp.text === "string" && comp.text !== "") ||
|
||||
(typeof comp.keybind === "string" && comp.keybind !== "") ||
|
||||
|
@ -541,7 +541,7 @@ function parseMinecraftMessage(component) {
|
|||
let NowColor = parseMinecraftColor(comp?.color);
|
||||
let NowFormat = parseMinecraftFormat(comp);
|
||||
|
||||
if (VaildText(comp)) { // Idk, but it work atleast.
|
||||
if (ValidText(comp)) { // Idk, but it work atleast.
|
||||
if (NowFormat.have || prevFormat.have) {
|
||||
if (NowFormat.have) {
|
||||
text += NowFormat.format
|
||||
|
@ -573,14 +573,14 @@ function parseMinecraftMessage(component) {
|
|||
}
|
||||
|
||||
if (comp.translate) {
|
||||
let translateString = lang[comp.translate] || comp.translate;
|
||||
let translateString = Object.hasOwn(lang, comp.translate) ? lang[comp.translate] : comp.translate
|
||||
let DefaultTranslateString = translateString;
|
||||
let fallbackMsg = false;
|
||||
if (comp.fallback && !lang[comp.translate]) fallbackMsg = true;
|
||||
|
||||
try {
|
||||
if (comp.with && !fallbackMsg) {
|
||||
const withArgs = comp.with.map(arg => extractText(arg, NowColor.have ? NowColor : prevColor, NowFormat.have ? NowFormat : prevFormat) + `${VaildText(comp) ? NowFormat.have ? NowFormat.format : prevFormat.format : ""}${VaildText(comp) ? NowColor.have ? NowColor.color : prevColor.color : ""}`);
|
||||
const withArgs = comp.with.map(arg => extractText(arg, NowColor.have ? NowColor : prevColor, NowFormat.have ? NowFormat : prevFormat) + `${ValidText(comp) ? NowFormat.have ? NowFormat.format : prevFormat.format : ""}${ValidText(comp) ? NowColor.have ? NowColor.color : prevColor.color : ""}`);
|
||||
const matches = [...translateString.matchAll(/%(?:(\d+)\$)?([A-Za-z%]|$)/g)]; //
|
||||
if (matches.length === 0) throw new Error("NoPlaceholdersFoundError");
|
||||
|
||||
|
@ -634,9 +634,10 @@ function parseMinecraftMessage(component) {
|
|||
|
||||
if (comp.extra) {
|
||||
if (!Array.isArray(comp.extra)) comp.extra = [comp.extra]
|
||||
comp.extra.forEach(subComp => {
|
||||
text += extractText(subComp, NowColor.have ? NowColor : prevColor, NowFormat.have ? NowFormat : prevFormat) + `${VaildText(comp) ? NowFormat.have ? NowFormat.format : prevFormat.format : ""}${VaildText(comp) ? NowColor.have ? NowColor.color : prevColor.color : ""}`;
|
||||
});
|
||||
|
||||
for (const subComp of comp.extra) {
|
||||
text += extractText(subComp, NowColor.have ? NowColor : prevColor, NowFormat.have ? NowFormat : prevFormat) + `${ValidText(comp) ? NowFormat.have ? NowFormat.format : prevFormat.format : ""}${ValidText(comp) ? NowColor.have ? NowColor.color : prevColor.color : ""}`;
|
||||
};
|
||||
}
|
||||
|
||||
if (shouldReset) {
|
||||
|
@ -667,7 +668,7 @@ function parseMinecraftMessageNoColor(component) {
|
|||
}
|
||||
|
||||
if (comp.translate) {
|
||||
let translateString = lang[comp.translate] || comp.translate;
|
||||
let translateString = Object.hasOwn(lang, comp.translate) ? lang[comp.translate] : comp.translate
|
||||
let DefaultTranslateString = translateString;
|
||||
let fallbackMsg = false;
|
||||
if (comp.fallback && !lang[comp.translate]) fallbackMsg = true;
|
||||
|
@ -729,9 +730,9 @@ function parseMinecraftMessageNoColor(component) {
|
|||
|
||||
if (comp.extra) {
|
||||
if (!Array.isArray(comp.extra)) comp.extra = [comp.extra]
|
||||
comp.extra.forEach(subComp => {
|
||||
for (const subComp of comp.extra) {
|
||||
text += extractText(subComp);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return text;
|
||||
|
@ -751,7 +752,7 @@ function cboutput(component) {
|
|||
let NowColor = parseMinecraftColor(comp?.color);
|
||||
let NowFormat = parseMinecraftFormat(comp);
|
||||
|
||||
if (VaildText(comp)) { // Idk, but it work atleast.
|
||||
if (ValidText(comp)) { // Idk, but it work atleast.
|
||||
if (NowFormat.have || prevFormat.have) {
|
||||
if (NowFormat.have) {
|
||||
text += NowFormat.format
|
||||
|
@ -781,9 +782,9 @@ function cboutput(component) {
|
|||
|
||||
if (comp.extra) {
|
||||
if (!Array.isArray(comp.extra)) comp.extra = [comp.extra]
|
||||
comp.extra.forEach(subComp => {
|
||||
text += extractText(subComp, NowColor.have ? NowColor : prevColor, NowFormat.have ? NowFormat : prevFormat) + `${VaildText(comp) ? NowFormat.have ? NowFormat.format : prevFormat.format : ""}${VaildText(comp) ? NowColor.have ? NowColor.color : prevColor.color : ""}`;
|
||||
});
|
||||
for (const subComp of comp.extra) {
|
||||
text += extractText(subComp, NowColor.have ? NowColor : prevColor, NowFormat.have ? NowFormat : prevFormat) + `${ValidText(comp) ? NowFormat.have ? NowFormat.format : prevFormat.format : ""}${ValidText(comp) ? NowColor.have ? NowColor.color : prevColor.color : ""}`;
|
||||
};
|
||||
}
|
||||
|
||||
if (shouldReset) {
|
||||
|
@ -812,9 +813,9 @@ function cboutputNoColor(component) {
|
|||
|
||||
if (comp.extra) {
|
||||
if (!Array.isArray(comp.extra)) comp.extra = [comp.extra]
|
||||
comp.extra.forEach(subComp => {
|
||||
for (const subComp of comp.extra) {
|
||||
text += extractText(subComp);
|
||||
});
|
||||
};
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
|
21
main.js
21
main.js
|
@ -1,8 +1,8 @@
|
|||
/**
|
||||
* *Info in chat parser*
|
||||
*
|
||||
* Minecraft Version: 1.21.3
|
||||
* ChatParser Version: 1, 1426
|
||||
* Minecraft Version: 1.21.4
|
||||
* ChatParser Version: 1426, 1529
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -12,16 +12,15 @@ const ChatParse = require("./chatparser.js");
|
|||
function createBot() {
|
||||
|
||||
const bot = mc.createClient({
|
||||
// host: '95.216.192.50', // kaboom
|
||||
host: 'chipmunk.land', // Chipmunk
|
||||
host: 'kaboom.pw', // kaboom
|
||||
// host: 'chipmunk.land', // Chipmunk
|
||||
// host: '168.100.225.224', // Neko
|
||||
// host: 'chayapak.chipmunk.land', // chayapak
|
||||
port: 25565,
|
||||
username: 'catparser', // cat
|
||||
version: "1.21.3",
|
||||
username: 'cataparser', // cat
|
||||
version: "1.21.4",
|
||||
hideErrors: true
|
||||
});
|
||||
|
||||
ChatParse.inject(bot); // load catparser function
|
||||
|
||||
bot.on('error', (e) => {
|
||||
|
@ -47,20 +46,16 @@ bot.on('custom_profilelessChat', (message, profilelessChat, packet) => {
|
|||
|
||||
bot.on('custom_systemChat', (message, systemChat, packet) => {
|
||||
console.log(`[SystemChat] ${message}`);
|
||||
console.log(JSON.stringify(systemChat.jsonMsg.message))
|
||||
});
|
||||
|
||||
bot.on('login', () => {
|
||||
})
|
||||
|
||||
/*
|
||||
|
||||
// Kick message and disconnect message
|
||||
bot.on('kick_disconnect', (kick) => {
|
||||
console.log(ChatParse.parseMinecraftMessage(kicked.reason));
|
||||
console.log(ChatParse.parseMinecraftMessage(chatparser.processNBTComponent(kicked.reason)));
|
||||
})
|
||||
bot.on('disconnect', (kick) => {
|
||||
console.log(ChatParse.parseMinecraftMessage(kicked.reason));
|
||||
console.log(ChatParse.parseMinecraftMessage(chatparser.processNBTComponent(kicked.reason)));
|
||||
})
|
||||
bot.on('custom_actionBar', (message, actionBar, packet) => {
|
||||
console.log(`[ActionBar] ${message}`);
|
||||
|
|
Loading…
Reference in a new issue