fix tell cmd show undefined

This commit is contained in:
Yaode_owo 2024-09-20 12:01:17 -04:00
parent a08eed8457
commit 3b6e21d4c2

View file

@ -21,7 +21,7 @@ bot.on('systemChat', (packet) => {
const cspy = parseCommand(nocolormsg) const cspy = parseCommand(nocolormsg)
if (cspy) bot.emit('custom_Commandspy', msg); if (cspy) bot.emit('custom_Commandspy', msg);
if (jsonmsg === undefined) { // idk, but work if (jsonmsg === undefined) { // idk, but work
if (msg !== undefined) bot.emit('custom_systemChat', msg, nocolormsg, false); if (msg !== undefined) bot.emit('custom_systemChat', msg, nocolormsg, undefined);
} else { } else {
if (msg !== undefined) bot.emit('custom_systemChat', msg, nocolormsg, jsonmsg); if (msg !== undefined) bot.emit('custom_systemChat', msg, nocolormsg, jsonmsg);
} }
@ -49,12 +49,12 @@ bot.on('playerChat', (packet) => {
nocolorplayermsg = `* ${NoColorSenderName} ${NoColorformattedMessage}`; nocolorplayermsg = `* ${NoColorSenderName} ${NoColorformattedMessage}`;
break; break;
case 2: // someone /tell you text case 2: // someone /tell you text
msg = `${SenderName} whispers to you: ${formattedMessage}`; msg = `${SenderName} whispers to you: ${plainMessage ? plainMessage : formattedMessage}`;
nocolorplayermsg = `${NoColorSenderName} whispers to you: ${NoColorformattedMessage}`; nocolorplayermsg = `${NoColorSenderName} whispers to you: ${plainMessage ? plainMessage : NoColorformattedMessage}`;
break; break;
case 3: // you /tell someone text case 3: // you /tell someone text
msg = `You whisper to ${TargetName}: ${formattedMessage}`; msg = `You whisper to ${TargetName}: ${plainMessage ? plainMessage : formattedMessage}`;
nocolorplayermsg = `You whisper to ${NoColorTargetName}: ${NoColorformattedMessage}`; nocolorplayermsg = `You whisper to ${NoColorTargetName}: ${plainMessage ? plainMessage : NoColorformattedMessage}`;
break; break;
case 4: // player chat case 4: // player chat
// /sudo and vanish send formattedMessage message // /sudo and vanish send formattedMessage message
@ -229,6 +229,93 @@ function parseMinecraftMessageNoColor(component) {
return msgText; return msgText;
} }
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
}
bot.parsekickmsg = (component) => {
return kickparser(component);
};
} }
module.exports = { inject }; module.exports = { inject };