Spaces:
Paused
Paused
Update bot.js
Browse files
bot.js
CHANGED
|
@@ -165,18 +165,53 @@ function createBot() {
|
|
| 165 |
return results;
|
| 166 |
}
|
| 167 |
|
| 168 |
-
//
|
| 169 |
-
function
|
| 170 |
try {
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
}
|
| 181 |
}
|
| 182 |
|
|
@@ -214,14 +249,12 @@ function createBot() {
|
|
| 214 |
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
| 215 |
try {
|
| 216 |
if (typeof bot.activateEntityAt === "function") {
|
| 217 |
-
// activateEntityAt öncelikli
|
| 218 |
try {
|
| 219 |
bot.activateEntityAt(entity, entity.position);
|
| 220 |
logger.info(`safeActivateEntityPreferAt: activateEntityAt çağrıldı id:${entity.id} attempt:${attempt}`);
|
| 221 |
return true;
|
| 222 |
} catch (err) {
|
| 223 |
logger.warn(`safeActivateEntityPreferAt: activateEntityAt hata id:${entity.id} attempt:${attempt} err:${err && err.message ? err.message : err}`);
|
| 224 |
-
// denemeye devam
|
| 225 |
}
|
| 226 |
}
|
| 227 |
|
|
@@ -235,7 +268,6 @@ function createBot() {
|
|
| 235 |
}
|
| 236 |
}
|
| 237 |
|
| 238 |
-
// Eğer ikisi de yoksa hata ver
|
| 239 |
logger.warn("safeActivateEntityPreferAt: bot.activateEntityAt/activateEntity bulunamadı.");
|
| 240 |
return false;
|
| 241 |
} catch (err) {
|
|
@@ -285,7 +317,6 @@ function createBot() {
|
|
| 285 |
const nbt = slot.nbt;
|
| 286 |
if (!nbt) return null;
|
| 287 |
|
| 288 |
-
// Olası lore yolları
|
| 289 |
const possibleLorePaths = [
|
| 290 |
["value", "display", "value", "Lore", "value"],
|
| 291 |
["value", "display", "value", "Lore"],
|
|
@@ -333,7 +364,6 @@ function createBot() {
|
|
| 333 |
|
| 334 |
if (!loreCandidate) return null;
|
| 335 |
|
| 336 |
-
// JSON ise parse et
|
| 337 |
let plainText = loreCandidate;
|
| 338 |
try {
|
| 339 |
const maybe = JSON.parse(loreCandidate);
|
|
@@ -351,14 +381,12 @@ function createBot() {
|
|
| 351 |
// JSON değilse olduğu gibi kullan
|
| 352 |
}
|
| 353 |
|
| 354 |
-
// X/Y formatı ara
|
| 355 |
const xyMatch = plainText.match(/(\d{1,4})\s*\/\s*(\d{1,4})/);
|
| 356 |
if (xyMatch) {
|
| 357 |
const x = Number(xyMatch[1]);
|
| 358 |
if (!Number.isNaN(x)) return x;
|
| 359 |
}
|
| 360 |
|
| 361 |
-
// İlk sayı
|
| 362 |
const numMatch = plainText.match(/(\d{1,4})/);
|
| 363 |
if (numMatch) {
|
| 364 |
const n = Number(numMatch[1]);
|
|
@@ -612,16 +640,8 @@ function createBot() {
|
|
| 612 |
bot.on("windowOpen", function (window) {
|
| 613 |
try {
|
| 614 |
// window.title bazen ChatMessage veya obje olabilir; güvenli string'e çevir
|
| 615 |
-
let titleStr =
|
| 616 |
-
|
| 617 |
-
if (typeof window.title === "string") titleStr = window.title;
|
| 618 |
-
else if (window.title && typeof window.title.toString === "function") titleStr = window.title.toString();
|
| 619 |
-
else titleStr = String(window.title || "");
|
| 620 |
-
} catch (e) {
|
| 621 |
-
titleStr = String(window.title || "");
|
| 622 |
-
}
|
| 623 |
-
|
| 624 |
-
logger.info(`[${config["bot-account"]["username"]}] windowOpen başlığı: ${titleStr}`);
|
| 625 |
|
| 626 |
// Esnek panel eşlemesi (küçük harfe çevirerek "besleyici" kelimesini arar)
|
| 627 |
const panelMatch = (titleStr && (titleStr.toLowerCase().includes("besleyici") || titleStr.includes("ʙᴇsʟᴇʏiᴄi")));
|
|
@@ -644,7 +664,9 @@ function createBot() {
|
|
| 644 |
|
| 645 |
// Detaylı inspect logu: yapıyı görmemiz için çok önemli
|
| 646 |
try {
|
| 647 |
-
|
|
|
|
|
|
|
| 648 |
} catch (e) {
|
| 649 |
logger.info(`[${config["bot-account"]["username"]}] beefSlot inspect alınamadı.`);
|
| 650 |
}
|
|
|
|
| 165 |
return results;
|
| 166 |
}
|
| 167 |
|
| 168 |
+
// window.title parse ve beefSlot inspect yardımcıları
|
| 169 |
+
function parseWindowTitleToString(titleObj) {
|
| 170 |
try {
|
| 171 |
+
if (!titleObj) return "";
|
| 172 |
+
if (typeof titleObj === "string") return titleObj;
|
| 173 |
+
if (titleObj && typeof titleObj.toString === "function") {
|
| 174 |
+
const s = titleObj.toString();
|
| 175 |
+
if (s && s !== "[object Object]") return s;
|
| 176 |
+
}
|
| 177 |
+
if (typeof titleObj === "object") {
|
| 178 |
+
if (typeof titleObj.text === "string" && titleObj.text.trim().length > 0) return titleObj.text;
|
| 179 |
+
if (Array.isArray(titleObj.extra) && titleObj.extra.length > 0) {
|
| 180 |
+
for (const e of titleObj.extra) {
|
| 181 |
+
if (!e) continue;
|
| 182 |
+
if (typeof e === "string" && e.trim()) return e;
|
| 183 |
+
if (e && typeof e.text === "string" && e.text.trim()) return e.text;
|
| 184 |
+
try {
|
| 185 |
+
const s = e.toString();
|
| 186 |
+
if (s && s !== "[object Object]") return s;
|
| 187 |
+
} catch (e2) {}
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
try {
|
| 191 |
+
return JSON.stringify(titleObj);
|
| 192 |
+
} catch (e) {
|
| 193 |
+
return String(titleObj);
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
return String(titleObj);
|
| 197 |
+
} catch (err) {
|
| 198 |
+
try { return String(titleObj); } catch (e) { return ""; }
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
function inspectBeefSlot(slot) {
|
| 203 |
+
try {
|
| 204 |
+
if (!slot) return { inspected: "slot=null", nbtSummary: "nbt=null" };
|
| 205 |
+
const inspected = util.inspect(slot, { depth: 6 });
|
| 206 |
+
let nbtSummary = "nbt=null";
|
| 207 |
+
try {
|
| 208 |
+
if (slot.nbt) {
|
| 209 |
+
nbtSummary = util.inspect(slot.nbt, { depth: 6 });
|
| 210 |
+
}
|
| 211 |
+
} catch (e) {}
|
| 212 |
+
return { inspected, nbtSummary };
|
| 213 |
+
} catch (err) {
|
| 214 |
+
return { inspected: "inspect-hata", nbtSummary: "inspect-hata" };
|
| 215 |
}
|
| 216 |
}
|
| 217 |
|
|
|
|
| 249 |
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
| 250 |
try {
|
| 251 |
if (typeof bot.activateEntityAt === "function") {
|
|
|
|
| 252 |
try {
|
| 253 |
bot.activateEntityAt(entity, entity.position);
|
| 254 |
logger.info(`safeActivateEntityPreferAt: activateEntityAt çağrıldı id:${entity.id} attempt:${attempt}`);
|
| 255 |
return true;
|
| 256 |
} catch (err) {
|
| 257 |
logger.warn(`safeActivateEntityPreferAt: activateEntityAt hata id:${entity.id} attempt:${attempt} err:${err && err.message ? err.message : err}`);
|
|
|
|
| 258 |
}
|
| 259 |
}
|
| 260 |
|
|
|
|
| 268 |
}
|
| 269 |
}
|
| 270 |
|
|
|
|
| 271 |
logger.warn("safeActivateEntityPreferAt: bot.activateEntityAt/activateEntity bulunamadı.");
|
| 272 |
return false;
|
| 273 |
} catch (err) {
|
|
|
|
| 317 |
const nbt = slot.nbt;
|
| 318 |
if (!nbt) return null;
|
| 319 |
|
|
|
|
| 320 |
const possibleLorePaths = [
|
| 321 |
["value", "display", "value", "Lore", "value"],
|
| 322 |
["value", "display", "value", "Lore"],
|
|
|
|
| 364 |
|
| 365 |
if (!loreCandidate) return null;
|
| 366 |
|
|
|
|
| 367 |
let plainText = loreCandidate;
|
| 368 |
try {
|
| 369 |
const maybe = JSON.parse(loreCandidate);
|
|
|
|
| 381 |
// JSON değilse olduğu gibi kullan
|
| 382 |
}
|
| 383 |
|
|
|
|
| 384 |
const xyMatch = plainText.match(/(\d{1,4})\s*\/\s*(\d{1,4})/);
|
| 385 |
if (xyMatch) {
|
| 386 |
const x = Number(xyMatch[1]);
|
| 387 |
if (!Number.isNaN(x)) return x;
|
| 388 |
}
|
| 389 |
|
|
|
|
| 390 |
const numMatch = plainText.match(/(\d{1,4})/);
|
| 391 |
if (numMatch) {
|
| 392 |
const n = Number(numMatch[1]);
|
|
|
|
| 640 |
bot.on("windowOpen", function (window) {
|
| 641 |
try {
|
| 642 |
// window.title bazen ChatMessage veya obje olabilir; güvenli string'e çevir
|
| 643 |
+
let titleStr = parseWindowTitleToString(window.title);
|
| 644 |
+
logger.info(`[${config["bot-account"]["username"]}] windowOpen başlığı (parsed): ${titleStr}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
|
| 646 |
// Esnek panel eşlemesi (küçük harfe çevirerek "besleyici" kelimesini arar)
|
| 647 |
const panelMatch = (titleStr && (titleStr.toLowerCase().includes("besleyici") || titleStr.includes("ʙᴇsʟᴇʏiᴄi")));
|
|
|
|
| 664 |
|
| 665 |
// Detaylı inspect logu: yapıyı görmemiz için çok önemli
|
| 666 |
try {
|
| 667 |
+
const beefInfo = inspectBeefSlot(beefSlot);
|
| 668 |
+
logger.info(`[${config["bot-account"]["username"]}] beefSlot.inspect:\n${beefInfo.inspected}`);
|
| 669 |
+
logger.info(`[${config["bot-account"]["username"]}] beefSlot.nbtSummary:\n${beefInfo.nbtSummary}`);
|
| 670 |
} catch (e) {
|
| 671 |
logger.info(`[${config["bot-account"]["username"]}] beefSlot inspect alınamadı.`);
|
| 672 |
}
|