Suvarii commited on
Commit
9966aaf
·
verified ·
1 Parent(s): 1b0827e

Update bot.js

Browse files
Files changed (1) hide show
  1. bot.js +71 -150
bot.js CHANGED
@@ -33,9 +33,7 @@ function createBot() {
33
  if (e && e.displayName && typeof e.displayName.toString === "function") {
34
  return e.displayName.toString();
35
  }
36
- } catch (err) {
37
- // ignore
38
- }
39
  return null;
40
  }
41
 
@@ -120,9 +118,7 @@ function createBot() {
120
  }
121
 
122
  if (Array.isArray(obj)) {
123
- for (let i = 0; i < obj.length; i++) {
124
- recurse(obj[i], `${path}[${i}]`);
125
- }
126
  return;
127
  }
128
 
@@ -141,9 +137,7 @@ function createBot() {
141
  const val = obj[key];
142
  if (typeof val === "string") {
143
  const norm = normalizeForMatch(val);
144
- if (norm.includes(targetLower)) {
145
- results.push({ path: `${path}.${key}`, value: val });
146
- }
147
  } else if (val && typeof val === "object") {
148
  recurse(val, `${path}.${key}`);
149
  } else {
@@ -155,9 +149,7 @@ function createBot() {
155
  }
156
  } catch (e) {}
157
  }
158
- } catch (e) {
159
- // ignore property access errors
160
- }
161
  }
162
  }
163
 
@@ -168,19 +160,20 @@ function createBot() {
168
  }
169
 
170
  // -------------------------
171
- // Dump yardımcıları
172
  // -------------------------
173
- function dumpEntityFull(entity) {
174
  try {
175
- if (!entity) {
176
- console.log("dumpEntityFull: entity yok");
177
- return;
178
- }
179
- console.log("=== DUMP ENTITY FULL START ===");
180
- console.log(util.inspect(entity, { depth: null, colors: false, maxArrayLength: null }));
181
- console.log("=== DUMP ENTITY FULL END ===");
182
- } catch (err) {
183
- console.error("dumpEntityFull hata:", err);
 
184
  }
185
  }
186
 
@@ -213,11 +206,8 @@ function createBot() {
213
  ? entity.position.offset(0, 1.5, 0)
214
  : { x: entity.position.x, y: entity.position.y + 1.5, z: entity.position.z };
215
  await bot.lookAt(lookPos, true);
216
- // küçük bekleme, sunucu bazlı gereksinimler için
217
  await new Promise(r => setTimeout(r, 180));
218
- } catch (e) {
219
- // lookAt desteklenmiyorsa sessizce devam et
220
- }
221
  }
222
 
223
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
@@ -234,11 +224,10 @@ function createBot() {
234
  return true;
235
  }
236
 
237
- // Eğer ikisi de yoksa, deneme amaçlı bot.swingArm veya benzeri bir fallback ekleyebiliriz
238
  logger.warn("safeActivateEntity: bot.activateEntityAt/activateEntity bulunamadı.");
239
  return false;
240
  } catch (err) {
241
- logger.warn(`safeActivateEntity: activate denemesi başarısız id:${entity.id} attempt:${attempt} err:${err && err.message ? err.message : err}`);
242
  await new Promise(r => setTimeout(r, retryDelay));
243
  }
244
  }
@@ -252,124 +241,86 @@ function createBot() {
252
  }
253
 
254
  // -------------------------
255
- // Tek seferlik detaylı snapshot ( /home sonrası )
256
  // -------------------------
257
- function logDetailedEntitiesOnce() {
258
  setTimeout(() => {
259
  (async () => {
260
  try {
261
- console.log("/home sonrası DETAILED entity snapshot (5s):");
262
  const arr = Object.values(bot.entities);
263
  if (!arr || arr.length === 0) {
264
- console.log("No entities found in bot.entities");
265
  return;
266
  }
267
 
268
- arr.forEach(e => {
269
- try {
270
- const rawDisplay = safeDisplayNameToString(e);
271
- const readable = getEntityReadableName(e) || "null";
272
- const pos = e.position ? `${e.position.x.toFixed(2)},${e.position.y.toFixed(2)},${e.position.z.toFixed(2)}` : "null";
273
- const dist = (e.position && bot.entity && bot.entity.position) ? e.position.distanceTo(bot.entity.position).toFixed(2) : "n/a";
274
- const metaKeys = e.metadata ? Object.keys(e.metadata).join(",") : "none";
275
-
276
- console.log("--------------------------------------------------");
277
- console.log(`id: ${e.id}`);
278
- console.log(`type: ${e.type}`);
279
- console.log(`readableName: ${readable}`);
280
- console.log(`rawDisplayName: ${rawDisplay || "null"}`);
281
- console.log(`username/name field: ${e.username || e.name || "null"}`);
282
- console.log(`position: ${pos}`);
283
- console.log(`distanceToBot: ${dist}`);
284
- console.log(`metadata keys: ${metaKeys}`);
285
- if (e.mobType) console.log(`mobType: ${e.mobType}`);
286
- if (e.mobTypeName) console.log(`mobTypeName: ${e.mobTypeName}`);
287
- console.log("shortInspect (depth 2):");
288
- console.log(util.inspect(e, { depth: 2, colors: false, breakLength: 120 }));
289
- console.log("--------------------------------------------------\n");
290
- } catch (innerErr) {
291
- console.error("Entity detay yazdırılırken hata:", innerErr);
292
- }
293
- });
294
-
295
- const minimal = arr.map(e => ({
296
- id: e.id,
297
- type: e.type,
298
- readableName: getEntityReadableName(e),
299
- rawDisplayName: safeDisplayNameToString(e),
300
- pos: e.position ? { x: e.position.x, y: e.position.y, z: e.position.z } : null
301
- }));
302
- console.log("Minimal snapshot JSON (tek satır):");
303
- console.log(JSON.stringify(minimal));
304
-
305
- // -------------------------
306
- // Her entity içinde derin arama yap: "besleyici"
307
- // -------------------------
308
  const target = "besleyici";
309
  const targetNorm = normalizeForMatch(target);
310
 
311
- let anyFound = false;
 
 
312
  for (const e of arr) {
313
- try {
314
- // 1) Hızlı name/displayName kontrolü
315
- const name = getEntityReadableName(e);
316
- if (isBesleyiciName(name)) {
317
- logger.info(`[${config["bot-account"]["username"]}] Besleyici bulundu (name/displayName): ${name} (id:${e.id}) — aktive ediliyor.`);
318
- await safeActivateEntity(e, { maxRetries: 4, retryDelay: 300, requireLook: true, maxDistance: 7 });
319
- anyFound = true;
320
- break;
321
- }
322
 
323
- // 2) Metadata özel yol kontrolü (senin verdiğin path'e göre)
 
 
324
  const candidate = safeGet(e, ["metadata", 2, "value", "extra", "value", "value", 0]);
325
  if (candidate) {
326
  let candidateStr = null;
327
  try {
328
  if (typeof candidate === "string") candidateStr = candidate;
329
  else if (candidate && typeof candidate.toString === "function") candidateStr = candidate.toString();
330
- else candidateStr = util.inspect(candidate, { depth: 2 });
331
  } catch (err) {
332
  candidateStr = String(candidate);
333
  }
334
  if (normalizeForMatch(candidateStr).includes(targetNorm)) {
335
- console.log(`*** Metadata özel yol ile Besleyici bulundu: entity id ${e.id} value=${candidateStr}`);
336
- dumpEntityFull(e);
337
- logger.info(`[${config["bot-account"]["username"]}] Metadata yolundan besleyici tespit edildi, aktive ediliyor (id:${e.id}).`);
338
- await safeActivateEntity(e, { maxRetries: 4, retryDelay: 300, requireLook: true, maxDistance: 7 });
339
- anyFound = true;
340
  break;
341
  }
342
  }
 
 
343
 
344
- // 3) Genel derin arama
 
 
345
  const matches = deepSearchForString(e, targetNorm);
346
  if (matches && matches.length > 0) {
347
- anyFound = true;
348
- console.log(`*** Derin arama ile eşleşme bulundu: entity id ${e.id} name:${getEntityReadableName(e)}`);
349
- matches.forEach((m, idx) => {
350
- try {
351
- let valStr = typeof m.value === "string" ? m.value : util.inspect(m.value, { depth: 1, colors: false });
352
- console.log(` Match ${idx + 1}: path=${m.path} value=${valStr}`);
353
- } catch (inner) {}
354
- });
355
- dumpEntityFull(e);
356
- logger.info(`[${config["bot-account"]["username"]}] Derin arama ile bulunan entity aktive ediliyor (id:${e.id}).`);
357
- await safeActivateEntity(e, { maxRetries: 4, retryDelay: 300, requireLook: true, maxDistance: 7 });
358
  break;
359
  }
360
- } catch (inner) {
361
- console.error("Entity derin arama sırasında hata:", inner);
362
  }
363
  }
364
 
365
- if (!anyFound) {
366
- logger.info(`[${config["bot-account"]["username"]}] /home sonrası tarama: besleyici minyon bulunamadı (derin arama yapıldı).`);
 
 
 
 
 
 
 
 
367
  }
368
  } catch (err) {
369
- console.error("logDetailedEntitiesOnce hata:", err);
370
  }
371
  })();
372
- }, 5000); // 5 saniye sonra tek seferlik
373
  }
374
 
375
  // -------------------------
@@ -396,11 +347,9 @@ function createBot() {
396
  setTimeout(async () => {
397
  bot.chat(`/home`);
398
  logger.info(`[${config["bot-account"]["username"]}] Home konumuna ışınlanma komutu kullanıldı.`);
399
- // /home sonrası tek seferlik detaylı snapshot + derin arama
400
- logDetailedEntitiesOnce();
401
  }, 10000);
402
-
403
- // Orijinal periyodik JSON.stringify kontrolü kaldırıldı (spam oluyordu).
404
  }
405
 
406
  if (config.utils["chat-messages"].enabled) {
@@ -434,13 +383,8 @@ function createBot() {
434
  }
435
 
436
  if (config.utils["anti-afk"].enabled) {
437
- if (config.utils["anti-afk"].sneak) {
438
- bot.setControlState("sneak", true);
439
- }
440
-
441
- if (config.utils["anti-afk"].jump) {
442
- bot.setControlState("jump", true);
443
- }
444
 
445
  if (config.utils["anti-afk"]["hit"].enabled) {
446
  let delay = config.utils["anti-afk"]["hit"]["delay"];
@@ -483,49 +427,32 @@ function createBot() {
483
  });
484
 
485
  // -------------------------
486
- // windowOpen: minyon paneli ve besleme mantığı
487
  // -------------------------
488
  bot.on("windowOpen", function (window) {
489
  try {
490
  if (window.title && window.title.includes("ʙᴇsʟᴇʏiᴄi ᴍiɴʏᴏɴ ᴘᴀɴᴇʟi")) {
491
- // Besleyici minyon paneli
492
  const beefSlots = window.slots.filter(xx => xx?.name && xx?.name == "cooked_beef");
493
  if (beefSlots.length > 0) {
494
- // Orijinal kodda kullanılan nbt parsing ile minyon canını al
495
  const beefSlot = beefSlots[0];
496
  let minyoncani = 9999;
497
  try {
498
  const lore = beefSlot?.nbt?.value?.display?.value?.Lore?.value?.value[1];
499
  const loreText = lore ? (JSON.parse(lore)?.extra?.[0]?.text ?? lore?.toString?.() ?? "") : "";
500
  minyoncani = Number((loreText).split("/")[0]);
501
- if (Number.isNaN(minyoncani)) {
502
- // fallback: bazı sunucularda farklı yapı olabilir
503
- minyoncani = Number(String(loreText).replace(/\D/g, "")) || minyoncani;
504
- }
505
  } catch (err) {
506
- // parsing hatası olursa logla ama devam et
507
  logger.warn("Minyon canı okunurken hata: " + (err && err.message ? err.message : err));
508
  }
509
 
510
  if (minyoncani <= 2) {
511
- // Besleme gerçekleştiriliyor
512
  bot.clickWindow(36, 0, 0);
513
  logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${minyoncani} olduğu için besleyici minyon beslendi.`);
514
- // Kullanıcıya chat ile bildirim gönder
515
- try {
516
- bot.chat(`Minyon canı ${minyoncani} olduğu için besleyici ile beslendi.`);
517
- } catch (e) {
518
- logger.warn("Chat gönderilemedi: " + (e && e.message ? e.message : e));
519
- }
520
  bot.closeWindow(window);
521
  } else {
522
- // Can 2'den yüksek olduğu için yenilenmedi — kullanıcıya bildirim gönder
523
  logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${minyoncani} olduğu için yenilenmedi.`);
524
- try {
525
- bot.chat(`Minyon canı ${minyoncani} olduğu için yenilenmedi.`);
526
- } catch (e) {
527
- logger.warn("Chat gönderilemedi: " + (e && e.message ? e.message : e));
528
- }
529
  bot.closeWindow(window);
530
  }
531
  } else {
@@ -541,15 +468,11 @@ function createBot() {
541
  });
542
 
543
  bot.on("chat", (username, message) => {
544
- if (config.utils["chat-log"]) {
545
- logger.info(`<${username}> ${message}`);
546
- }
547
  });
548
 
549
  bot.on("goal_reached", () => {
550
- if (config.position.enabled) {
551
- logger.info(`Bot arrived to target location. ${bot.entity.position}`);
552
- }
553
  });
554
 
555
  bot.on("death", () => {
@@ -558,9 +481,7 @@ function createBot() {
558
 
559
  if (config.utils["auto-reconnect"]) {
560
  bot.on("end", () => {
561
- setTimeout(() => {
562
- createBot();
563
- }, config.utils["auto-reconnect-delay"]);
564
  });
565
  }
566
 
@@ -584,7 +505,7 @@ function createBot() {
584
  if (!msg) return;
585
  if (msg.type === "dumpEntityById" && msg.id) {
586
  const ent = Object.values(bot.entities).find(e => e && e.id === msg.id);
587
- dumpEntityFull(ent);
588
  }
589
  } catch (e) {}
590
  });
 
33
  if (e && e.displayName && typeof e.displayName.toString === "function") {
34
  return e.displayName.toString();
35
  }
36
+ } catch (err) {}
 
 
37
  return null;
38
  }
39
 
 
118
  }
119
 
120
  if (Array.isArray(obj)) {
121
+ for (let i = 0; i < obj.length; i++) recurse(obj[i], `${path}[${i}]`);
 
 
122
  return;
123
  }
124
 
 
137
  const val = obj[key];
138
  if (typeof val === "string") {
139
  const norm = normalizeForMatch(val);
140
+ if (norm.includes(targetLower)) results.push({ path: `${path}.${key}`, value: val });
 
 
141
  } else if (val && typeof val === "object") {
142
  recurse(val, `${path}.${key}`);
143
  } else {
 
149
  }
150
  } catch (e) {}
151
  }
152
+ } catch (e) {}
 
 
153
  }
154
  }
155
 
 
160
  }
161
 
162
  // -------------------------
163
+ // Minimal log helper
164
  // -------------------------
165
+ function logMinimalEntities(arr) {
166
  try {
167
+ const minimal = arr.map(e => ({
168
+ id: e.id,
169
+ type: e.type,
170
+ name: getEntityReadableName(e),
171
+ pos: e.position ? { x: Number(e.position.x.toFixed(2)), y: Number(e.position.y.toFixed(2)), z: Number(e.position.z.toFixed(2)) } : null
172
+ }));
173
+ console.log("/home sonrası kısa entity listesi:");
174
+ console.log(JSON.stringify(minimal));
175
+ } catch (e) {
176
+ console.log("Kısa entity listesi alınamadı.");
177
  }
178
  }
179
 
 
206
  ? entity.position.offset(0, 1.5, 0)
207
  : { x: entity.position.x, y: entity.position.y + 1.5, z: entity.position.z };
208
  await bot.lookAt(lookPos, true);
 
209
  await new Promise(r => setTimeout(r, 180));
210
+ } catch (e) {}
 
 
211
  }
212
 
213
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
 
224
  return true;
225
  }
226
 
 
227
  logger.warn("safeActivateEntity: bot.activateEntityAt/activateEntity bulunamadı.");
228
  return false;
229
  } catch (err) {
230
+ logger.warn(`safeActivateEntity: deneme başarısız id:${entity.id} attempt:${attempt} err:${err && err.message ? err.message : err}`);
231
  await new Promise(r => setTimeout(r, retryDelay));
232
  }
233
  }
 
241
  }
242
 
243
  // -------------------------
244
+ // Tek seferlik kısa snapshot + arama ( /home sonrası )
245
  // -------------------------
246
+ function logAndFindBesleyiciOnce() {
247
  setTimeout(() => {
248
  (async () => {
249
  try {
 
250
  const arr = Object.values(bot.entities);
251
  if (!arr || arr.length === 0) {
252
+ console.log("/home sonrası: entity bulunamadı.");
253
  return;
254
  }
255
 
256
+ // Konsolu sade tut: sadece kısa liste yaz
257
+ logMinimalEntities(arr);
258
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  const target = "besleyici";
260
  const targetNorm = normalizeForMatch(target);
261
 
262
+ let found = null;
263
+ let foundPath = null;
264
+ // 1) Hızlı name/displayName kontrolü
265
  for (const e of arr) {
266
+ const name = getEntityReadableName(e);
267
+ if (isBesleyiciName(name)) {
268
+ found = e;
269
+ foundPath = "displayName/name";
270
+ break;
271
+ }
272
+ }
 
 
273
 
274
+ // 2) Metadata özel yol kontrolü (senin verdiğin path'e göre)
275
+ if (!found) {
276
+ for (const e of arr) {
277
  const candidate = safeGet(e, ["metadata", 2, "value", "extra", "value", "value", 0]);
278
  if (candidate) {
279
  let candidateStr = null;
280
  try {
281
  if (typeof candidate === "string") candidateStr = candidate;
282
  else if (candidate && typeof candidate.toString === "function") candidateStr = candidate.toString();
283
+ else candidateStr = util.inspect(candidate, { depth: 1 });
284
  } catch (err) {
285
  candidateStr = String(candidate);
286
  }
287
  if (normalizeForMatch(candidateStr).includes(targetNorm)) {
288
+ found = e;
289
+ foundPath = "metadata[2].value.extra.value.value[0]";
 
 
 
290
  break;
291
  }
292
  }
293
+ }
294
+ }
295
 
296
+ // 3) Genel derin arama (sadece kısa sonuç)
297
+ if (!found) {
298
+ for (const e of arr) {
299
  const matches = deepSearchForString(e, targetNorm);
300
  if (matches && matches.length > 0) {
301
+ found = e;
302
+ foundPath = matches[0].path;
 
 
 
 
 
 
 
 
 
303
  break;
304
  }
 
 
305
  }
306
  }
307
 
308
+ if (found) {
309
+ const readable = getEntityReadableName(found);
310
+ console.log(`Besleyici bulundu: id:${found.id} name:${readable} path:${foundPath}`);
311
+ logger.info(`[${config["bot-account"]["username"]}] Besleyici bulundu id:${found.id} path:${foundPath} — aktive ediliyor.`);
312
+ const activated = await safeActivateEntity(found, { maxRetries: 4, retryDelay: 300, requireLook: true, maxDistance: 7 });
313
+ if (!activated) {
314
+ logger.warn(`[${config["bot-account"]["username"]}] Besleyici aktive edilemedi (id:${found.id}).`);
315
+ }
316
+ } else {
317
+ logger.info(`[${config["bot-account"]["username"]}] /home sonrası tarama: besleyici minyon bulunamadı.`);
318
  }
319
  } catch (err) {
320
+ console.error("logAndFindBesleyiciOnce hata:", err);
321
  }
322
  })();
323
+ }, 5000);
324
  }
325
 
326
  // -------------------------
 
347
  setTimeout(async () => {
348
  bot.chat(`/home`);
349
  logger.info(`[${config["bot-account"]["username"]}] Home konumuna ışınlanma komutu kullanıldı.`);
350
+ // /home sonrası tek seferlik kısa snapshot + besleyici arama
351
+ logAndFindBesleyiciOnce();
352
  }, 10000);
 
 
353
  }
354
 
355
  if (config.utils["chat-messages"].enabled) {
 
383
  }
384
 
385
  if (config.utils["anti-afk"].enabled) {
386
+ if (config.utils["anti-afk"].sneak) bot.setControlState("sneak", true);
387
+ if (config.utils["anti-afk"].jump) bot.setControlState("jump", true);
 
 
 
 
 
388
 
389
  if (config.utils["anti-afk"]["hit"].enabled) {
390
  let delay = config.utils["anti-afk"]["hit"]["delay"];
 
427
  });
428
 
429
  // -------------------------
430
+ // windowOpen: minyon paneli ve besleme mantığı (chat bildirimleri eklendi)
431
  // -------------------------
432
  bot.on("windowOpen", function (window) {
433
  try {
434
  if (window.title && window.title.includes("ʙᴇsʟᴇʏiᴄi ᴍiɴʏᴏɴ ᴘᴀɴᴇʟi")) {
 
435
  const beefSlots = window.slots.filter(xx => xx?.name && xx?.name == "cooked_beef");
436
  if (beefSlots.length > 0) {
 
437
  const beefSlot = beefSlots[0];
438
  let minyoncani = 9999;
439
  try {
440
  const lore = beefSlot?.nbt?.value?.display?.value?.Lore?.value?.value[1];
441
  const loreText = lore ? (JSON.parse(lore)?.extra?.[0]?.text ?? lore?.toString?.() ?? "") : "";
442
  minyoncani = Number((loreText).split("/")[0]);
443
+ if (Number.isNaN(minyoncani)) minyoncani = Number(String(loreText).replace(/\D/g, "")) || minyoncani;
 
 
 
444
  } catch (err) {
 
445
  logger.warn("Minyon canı okunurken hata: " + (err && err.message ? err.message : err));
446
  }
447
 
448
  if (minyoncani <= 2) {
 
449
  bot.clickWindow(36, 0, 0);
450
  logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${minyoncani} olduğu için besleyici minyon beslendi.`);
451
+ try { bot.chat(`Minyon canı ${minyoncani} olduğu için besleyici ile beslendi.`); } catch (e) {}
 
 
 
 
 
452
  bot.closeWindow(window);
453
  } else {
 
454
  logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${minyoncani} olduğu için yenilenmedi.`);
455
+ try { bot.chat(`Minyon canı ${minyoncani} olduğu için yenilenmedi.`); } catch (e) {}
 
 
 
 
456
  bot.closeWindow(window);
457
  }
458
  } else {
 
468
  });
469
 
470
  bot.on("chat", (username, message) => {
471
+ if (config.utils["chat-log"]) logger.info(`<${username}> ${message}`);
 
 
472
  });
473
 
474
  bot.on("goal_reached", () => {
475
+ if (config.position.enabled) logger.info(`Bot arrived to target location. ${bot.entity.position}`);
 
 
476
  });
477
 
478
  bot.on("death", () => {
 
481
 
482
  if (config.utils["auto-reconnect"]) {
483
  bot.on("end", () => {
484
+ setTimeout(() => createBot(), config.utils["auto-reconnect-delay"]);
 
 
485
  });
486
  }
487
 
 
505
  if (!msg) return;
506
  if (msg.type === "dumpEntityById" && msg.id) {
507
  const ent = Object.values(bot.entities).find(e => e && e.id === msg.id);
508
+ if (ent) console.log(util.inspect(ent, { depth: 2 }));
509
  }
510
  } catch (e) {}
511
  });