Suvarii commited on
Commit
95c0e36
·
verified ·
1 Parent(s): f5b9589

Update bot.js

Browse files
Files changed (1) hide show
  1. bot.js +282 -362
bot.js CHANGED
@@ -1,7 +1,7 @@
1
  const mineflayer = require("mineflayer");
2
  const Movements = require("mineflayer-pathfinder").Movements;
3
  const pathfinder = require("mineflayer-pathfinder").pathfinder;
4
- const { GoalBlock, GoalXZ } = require("mineflayer-pathfinder").goals;
5
 
6
  const config = require("./settings.json");
7
 
@@ -9,382 +9,302 @@ const loggers = require("./logging.js");
9
  const logger = loggers.logger;
10
 
11
  function createBot() {
12
- const bot = mineflayer.createBot({
13
- username: config["bot-account"]["username"],
14
- auth: config["bot-account"]["type"],
15
- host: config.server.ip,
16
- port: config.server.port,
17
- version: config.server.version,
18
- });
19
-
20
- bot.loadPlugin(pathfinder);
21
-
22
- // --- Yardımcı fonksiyonlar ---
23
- function stripColorCodes(s) {
24
- if (!s || typeof s !== "string") return s;
25
- return s.replace(/§[0-9a-fk-or]/gi, "");
26
- }
27
-
28
- function getEntityReadableName(e) {
29
- if (!e) return "";
30
- try {
31
- // displayName ChatMessage objesi ise toString ile al
32
- if (e.displayName && typeof e.displayName.toString === "function") {
33
- const d = e.displayName.toString();
34
- if (d) return stripColorCodes(d);
35
- }
36
- } catch (err) {
37
- // ignore
38
- }
39
- if (e.name && typeof e.name === "string") return stripColorCodes(e.name);
40
- if (e.username && typeof e.username === "string") return stripColorCodes(e.username);
41
- return "";
42
- }
43
-
44
- function isBesleyiciEntity(e) {
45
- const name = getEntityReadableName(e);
46
- if (!name) return false;
47
- // Hem "Besleyici" hem "besleyici" gibi varyasyonlar için case-insensitive kontrol
48
- return name.toLowerCase().includes("besleyici");
49
- }
50
-
51
- // Güvenli activate wrapper (farklı mineflayer sürümlerine uyumlu)
52
- function safeActivateEntity(entity) {
53
- try {
54
- if (!entity) return false;
55
- if (typeof bot.activateEntityAt === "function") {
56
- bot.activateEntityAt(entity, entity.position);
57
- return true;
58
- }
59
- if (typeof bot.activateEntity === "function") {
60
- bot.activateEntity(entity);
61
- return true;
62
- }
63
- // fallback: sağ tıklama benzeri bir işlem gerekiyorsa burada ekleyebilirsin
64
- logger.warn("Bot'ta activateEntityAt/activateEntity fonksiyonu bulunamadı.");
65
- return false;
66
- } catch (err) {
67
- logger.error(`Entity aktive edilirken hata: ${err.message}`);
68
- return false;
69
- }
70
- }
71
-
72
- // Debug: entities snapshot (isteğe bağlı, loglamak için)
73
- function logEntitiesSnapshot() {
74
- try {
75
- const snapshot = Object.values(bot.entities).map(e => {
76
- return {
77
- id: e.id,
78
- type: e.type,
79
- name: e.name || null,
80
- displayName: (() => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  try {
82
- return e.displayName && typeof e.displayName.toString === "function"
83
- ? stripColorCodes(e.displayName.toString())
84
- : null;
85
- } catch { return null; }
86
- })(),
87
- position: e.position ? { x: e.position.x, y: e.position.y, z: e.position.z } : null
88
- };
89
- });
90
- logger.debug("Entities snapshot: " + JSON.stringify(snapshot));
91
- } catch (err) {
92
- logger.error("Entities snapshot alınırken hata: " + err.message);
93
- }
94
- }
95
-
96
- // --- Besleyici arama / aktive etme mantığı ---
97
- let besleyiciInterval = null;
98
- let periodicIsHomeInterval = null;
99
-
100
- async function tryFindAndActivateBesleyici(logIfNotFound = true) {
101
- try {
102
- const besleyici = Object.values(bot.entities).find(isBesleyiciEntity);
103
- if (besleyici) {
104
- const readable = getEntityReadableName(besleyici);
105
- logger.info(`[${config["bot-account"]["username"]}] Besleyici bulundu: ${readable} (id:${besleyici.id})`);
106
- safeActivateEntity(besleyici);
107
- // /is home komutunu düzenli at
108
- if (!periodicIsHomeInterval) {
109
- periodicIsHomeInterval = setInterval(() => {
110
- bot.chat(`/is home`);
111
- }, 5000);
112
- }
113
- return true;
114
- } else {
115
- if (logIfNotFound) {
116
- logger.info(`[${config["bot-account"]["username"]}] Besleyici minyon bulunamadı (tarama yapıldı).`);
117
- }
118
- return false;
119
- }
120
- } catch (err) {
121
- logger.error(`tryFindAndActivateBesleyici hata: ${err.message}`);
122
- return false;
123
- }
124
- }
125
-
126
- // entity spawn olduğunda anında kontrol et
127
- bot.on('entitySpawn', (entity) => {
128
- try {
129
- if (isBesleyiciEntity(entity)) {
130
- logger.info("Yeni besleyici spawn oldu, aktive ediliyor.");
131
- safeActivateEntity(entity);
132
- }
133
- } catch (err) {
134
- logger.error("entitySpawn işlenirken hata: " + err.message);
135
- }
136
- });
137
-
138
- bot.once("spawn", async () => {
139
- const defaultMove = new Movements(bot);
140
- bot.pathfinder.setMovements(defaultMove);
141
- bot.settings.colorsEnabled = false;
142
- logger.info("Bot sunucuya giriş yaptı.");
143
-
144
- // Opsiyonel: ilk snapshot debug (gerekiyorsa aç)
145
- // logEntitiesSnapshot();
146
-
147
- if (config.utils["auto-auth"].enabled) {
148
- let password = config.utils["auto-auth"].password;
149
- setTimeout(() => {
150
- bot.chat(`/login ${password}`);
151
- logger.info(`[${config["bot-account"]["username"]}] Login komutu kullanıldı.`);
152
- }, 500);
153
-
154
- setTimeout(async () => {
155
- bot.chat(`/skyblock`);
156
- logger.info(`[${config["bot-account"]["username"]}] Skyblock'a ışınlanma komutu kullanıldı.`);
157
- }, 5000);
158
-
159
- setTimeout(async () => {
160
- bot.chat(`/home`);
161
- logger.info(`[${config["bot-account"]["username"]}] Home konumuna ışınlanma komutu kullanıldı.`);
162
- }, 10000);
163
-
164
- // Periyodik tarama: 5 dakika (300000 ms) aralıkla
165
- if (!besleyiciInterval) {
166
- besleyiciInterval = setInterval(async () => {
167
- const found = await tryFindAndActivateBesleyici(true);
168
- if (!found) {
169
- logEntitiesSnapshot();
170
- // Bulunamadıysa orijinal mantığa uygun komutlar
171
- setTimeout(() => {
172
- bot.chat(`/skyblock`);
173
- logger.info(`[${config["bot-account"]["username"]}] Bölgede besleyici minyon bulunamadı. Skyblock'a ışınlanma komutu kullanıldı.`);
174
- }, 5000);
175
-
176
- setTimeout(() => {
177
- bot.chat(`/home`);
178
- logger.info(`[${config["bot-account"]["username"]}] Bölgede besleyici minyon bulunamadı. Home konumuna ışınlanma komutu kullanıldı.`);
179
- }, 10000);
180
-
181
- // 13s aralıkla iç kontrol (bir süre sonra tekrar dene)
182
- setTimeout(() => {
183
- const inner = setInterval(async () => {
184
- const found2 = await tryFindAndActivateBesleyici(false);
185
- if (found2) {
186
- clearInterval(inner);
187
- }
188
- }, 13000);
189
- // inner için istersen bir maksimum süre ekleyebilirsin
190
- }, 12000);
191
-
192
- // /is home komutunu 16s sonra at
193
- setTimeout(() => {
194
- bot.chat(`/is home`);
195
- }, 16000);
196
- }
197
- }, 60000);
198
- }
199
 
200
- // İlk hızlı deneme (spawn sonrası kısa gecikme)
201
- setTimeout(() => {
202
- tryFindAndActivateBesleyici(true);
203
- }, 2000);
204
- }
205
-
206
- // chat-messages, position, anti-afk vs. (orijinal kodun mantığı korunmuştur)
207
- if (config.utils["chat-messages"].enabled) {
208
- logger.info("Started chat-messages module");
209
-
210
- let messages = config.utils["chat-messages"]["messages"];
211
-
212
- if (config.utils["chat-messages"].repeat) {
213
- let delay = config.utils["chat-messages"]["repeat-delay"];
214
- let i = 0;
215
-
216
- setInterval(() => {
217
- bot.chat(`${messages[i]}`);
218
-
219
- if (i + 1 === messages.length) {
220
- i = 0;
221
- } else i++;
222
- }, delay * 1000);
223
- } else {
224
- messages.forEach((msg) => {
225
- bot.chat(msg);
226
- });
227
  }
228
- }
229
 
230
- const pos = config.position;
 
231
 
232
- if (config.position.enabled) {
233
- logger.info(
234
- `Starting moving to target location (${pos.x}, ${pos.y}, ${pos.z})`,
235
- );
236
- bot.pathfinder.setGoal(new GoalBlock(pos.x, pos.y, pos.z));
237
- }
238
 
239
- if (config.utils["anti-afk"].enabled) {
240
- if (config.utils["anti-afk"].sneak) {
241
- bot.setControlState("sneak", true);
242
- }
243
 
244
- if (config.utils["anti-afk"].jump) {
245
- bot.setControlState("jump", true);
246
- }
247
 
248
- if (config.utils["anti-afk"]["hit"].enabled) {
249
- let delay = config.utils["anti-afk"]["hit"]["delay"];
250
- let attackMobs = config.utils["anti-afk"]["hit"]["attack-mobs"];
251
-
252
- setInterval(() => {
253
- if (attackMobs) {
254
- let entity = bot.nearestEntity(
255
- (e) =>
256
- e.type !== "object" &&
257
- e.type !== "player" &&
258
- e.type !== "global" &&
259
- e.type !== "orb" &&
260
- e.type !== "other",
261
- );
262
-
263
- if (entity) {
264
- bot.attack(entity);
265
- return;
266
- }
267
- }
268
-
269
- bot.swingArm("right", true);
270
- }, delay);
271
  }
272
 
273
- if (config.utils["anti-afk"].rotate) {
274
- setInterval(() => {
275
- bot.look(bot.entity.yaw + 1, bot.entity.pitch, true);
276
- }, 100);
 
 
 
277
  }
278
 
279
- if (config.utils["anti-afk"]["circle-walk"].enabled) {
280
- let radius = config.utils["anti-afk"]["circle-walk"]["radius"];
281
- setInterval(() => {
282
- circleWalk(bot, radius);
283
- }, 30000);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  }
285
- }
286
- });
287
-
288
- bot.on('windowOpen', function (window) {
289
- try {
290
- if (window.title && window.title.includes("ʙᴇsʟᴇʏiᴄi ᴍiɴʏᴏɴ ᴘᴀɴᴇʟi")) {
291
- // Besleyici minyon paneli
292
- const cooked = window.slots.filter(xx => xx?.name && xx?.name == "cooked_beef");
293
- if (cooked.length > 0) {
294
- const loreRaw = cooked[0]?.nbt?.value?.display?.value?.Lore?.value?.value[1];
295
- const parsed = loreRaw ? JSON.parse(loreRaw) : null;
296
- const extraText = parsed?.extra?.[0]?.text;
297
- const minyoncani = Number((extraText || "").split("/")[0]);
298
- if (!isNaN(minyoncani) && minyoncani <= 2) {
299
- bot.clickWindow(36, 0, 0);
300
  logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${minyoncani} olduğu için besleyici minyon beslendi.`);
301
  bot.closeWindow(window);
302
- } else {
303
- logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${minyoncani} olduğu için beslemeye gerek duyulmadı.`);
 
 
304
  bot.closeWindow(window);
305
- }
306
- } else {
307
- bot.closeWindow(window);
308
- }
309
- } else {
310
- bot.closeWindow(window);
311
  }
312
- } catch (err) {
313
- logger.error(`windowOpen işlenirken hata: ${err.message}`);
314
- try { bot.closeWindow(window); } catch {}
315
- }
316
- });
317
-
318
- bot.on("chat", (username, message) => {
319
- if (config.utils["chat-log"]) {
320
- logger.info(`<${username}> ${message}`);
321
- }
322
- });
323
-
324
- bot.on("goal_reached", () => {
325
- if (config.position.enabled) {
326
- logger.info(`Bot arrived to target location. ${bot.entity.position}`);
327
- }
328
- });
329
-
330
- bot.on("death", () => {
331
- logger.warn(
332
- `Bot has been died and was respawned at ${bot.entity.position}`,
333
- );
334
- });
335
-
336
- if (config.utils["auto-reconnect"]) {
337
- bot.on("end", () => {
338
- // Temizleme: interval'leri kapat
339
- try {
340
- if (besleyiciInterval) clearInterval(besleyiciInterval);
341
- if (periodicIsHomeInterval) clearInterval(periodicIsHomeInterval);
342
- } catch (e) {}
343
- setTimeout(() => {
344
- createBot();
345
- }, config.utils["auto-reconnect-delay"]);
346
  });
347
- }
348
-
349
- bot.on("kicked", (reason) => {
350
- let reasonText = "";
351
- try {
352
- const parsed = JSON.parse(reason);
353
- reasonText = parsed.text || parsed.extra?.[0]?.text || "";
354
- reasonText = reasonText?.replace(/§./g, "");
355
- logger.warn(`Bot sunucudan atıldı. Sebep: ${reasonText}`);
356
- } catch {
357
- logger.warn(`Bot sunucudan atıldı. Sebep: Bulunamadı.`);
358
- }
359
- });
360
-
361
- bot.on("error", (err) => logger.error(`${err.message}`));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  }
363
 
 
364
  function circleWalk(bot, radius) {
365
- // Make bot walk in square with center in bot's current position without stopping
366
- return new Promise(() => {
367
- const pos = bot.entity.position;
368
- const x = pos.x;
369
- const y = pos.y;
370
- const z = pos.z;
371
-
372
- const points = [
373
- [x + radius, y, z],
374
- [x, y, z + radius],
375
- [x - radius, y, z],
376
- [x, y, z - radius],
377
- ];
378
-
379
- let i = 0;
380
- setTimeout(() => {
381
- if (i === points.length) i = 0;
382
- const defaultMove = new Movements(bot);
383
- bot.pathfinder.setMovements(defaultMove);
384
- bot.pathfinder.setGoal(new GoalXZ(points[i][0], points[i][2]));
385
- i++;
386
- }, 1000);
387
- });
388
  }
389
 
390
  createBot();
@@ -396,12 +316,12 @@ const port = process.env.PORT || 7860; //buraya karışmayın.
396
  app.get("/", (req, res) => res.send("Pinglendi")); //değiştirebilirsiniz.
397
 
398
  app.listen(
399
- port,
400
- () =>
401
- console.log(`Bot bu adres üzerinde çalışıyor: http://localhost:${port}`), //port
402
  );
403
 
404
  process.on('uncaughtException', function (err) {
405
- console.error("Hata aldım!");
406
- console.log(err);
407
- });
 
1
  const mineflayer = require("mineflayer");
2
  const Movements = require("mineflayer-pathfinder").Movements;
3
  const pathfinder = require("mineflayer-pathfinder").pathfinder;
4
+ const { GoalBlock, GoalXZ, GoalNear } = require("mineflayer-pathfinder").goals;
5
 
6
  const config = require("./settings.json");
7
 
 
9
  const logger = loggers.logger;
10
 
11
  function createBot() {
12
+ const bot = mineflayer.createBot({
13
+ username: config["bot-account"]["username"],
14
+ auth: config["bot-account"]["type"],
15
+ host: config.server.ip,
16
+ port: config.server.port,
17
+ version: config.server.version,
18
+ });
19
+
20
+ bot.loadPlugin(pathfinder);
21
+
22
+ // --- Yardımcı fonksiyonlar (güvenli entity isim okuma ve /home sonrası snapshot) ---
23
+ function stripColorCodes(s) {
24
+ if (!s || typeof s !== "string") return s;
25
+ return s.replace(/§[0-9a-fk-or]/gi, "");
26
+ }
27
+
28
+ function getEntityReadableName(e) {
29
+ if (!e) return "";
30
+ try {
31
+ if (e.displayName && typeof e.displayName.toString === "function") {
32
+ const d = e.displayName.toString();
33
+ if (d) return stripColorCodes(d);
34
+ }
35
+ } catch (err) {}
36
+ if (e.name && typeof e.name === "string") return stripColorCodes(e.name);
37
+ if (e.username && typeof e.username === "string") return stripColorCodes(e.username);
38
+ return "";
39
+ }
40
+
41
+ function logEntitiesSnapshotToConsole() {
42
+ try {
43
+ const snapshot = Object.values(bot.entities).map(e => {
44
+ const raw = getEntityReadableName(e);
45
+ return {
46
+ id: e.id,
47
+ type: e.type,
48
+ rawName: raw,
49
+ pos: e.position ? { x: e.position.x, y: e.position.y, z: e.position.z } : null
50
+ };
51
+ });
52
+ console.log("=== ENTITIES SNAPSHOT START ===");
53
+ if (snapshot.length === 0) {
54
+ console.log("No entities found in bot.entities");
55
+ } else {
56
+ snapshot.forEach(s => {
57
+ console.log(`id:${s.id} type:${s.type} name:${s.rawName || 'null'} pos:${s.pos ? `${s.pos.x.toFixed(2)},${s.pos.y.toFixed(2)},${s.pos.z.toFixed(2)}` : 'null'}`);
58
+ });
59
+ }
60
+ console.log("=== ENTITIES SNAPSHOT END ===");
61
+ } catch (err) {
62
+ console.error("Entities snapshot alınırken hata:", err);
63
+ }
64
+ }
65
+
66
+ // /home sonrası snapshot tetikleyicisi
67
+ function triggerHomeSnapshots() {
68
+ setTimeout(() => {
69
+ console.log("/home sonrası entity snapshot (5s):");
70
+ logEntitiesSnapshotToConsole();
71
+ }, 5000);
72
+
73
+ setTimeout(() => {
74
+ console.log("/home sonrası entity snapshot (12s):");
75
+ logEntitiesSnapshotToConsole();
76
+ }, 12000);
77
+ }
78
+
79
+ // Yeni spawn olan entityleri anında logla
80
+ bot.on('entitySpawn', (entity) => {
81
+ try {
82
+ const raw = getEntityReadableName(entity);
83
+ console.log(`entitySpawn id:${entity.id} type:${entity.type} name:${raw || 'null'}`);
84
+ } catch (err) {
85
+ console.error("entitySpawn log hatası:", err);
86
+ }
87
+ });
88
+
89
+ bot.once("spawn", async() => {
90
+ const defaultMove = new Movements(bot);
91
+ bot.pathfinder.setMovements(defaultMove);
92
+ bot.settings.colorsEnabled = false;
93
+ logger.info("Bot sunucuya giriş yaptı.");
94
+
95
+ if (config.utils["auto-auth"].enabled) {
96
+
97
+ let password = config.utils["auto-auth"].password;
98
+ setTimeout(() => {
99
+ bot.chat(`/login ${password}`);
100
+ logger.info(`[${config["bot-account"]["username"]}] Login komutu kullanıldı.`);
101
+ }, 500);
102
+
103
+ setTimeout(async () => {
104
+ bot.chat(`/skyblock`);
105
+ logger.info(`[${config["bot-account"]["username"]}] Skyblock'a ışınlanma komutu kullanıldı.`);
106
+ }, 5000);
107
+
108
+ setTimeout(async () => {
109
+ bot.chat(`/home`);
110
+ logger.info(`[${config["bot-account"]["username"]}] Home konumuna ışınlanma komutu kullanıldı.`);
111
+ // /home sonrası entity snapshot'larını tetikle
112
+ triggerHomeSnapshots();
113
+ }, 10000);
114
+
115
+ // Orijinal interval mantığını koruyorum ama JSON.stringify yerine güvenli kontrol kullanıldı
116
+ setInterval(async () => {
117
  try {
118
+ const entitiesArr = Object.values(bot.entities);
119
+ // Burada eski kodda "ʙᴇsʟᴇʏiᴄi " arıyordun; biz güvenli isim okuma ile kontrol ediyoruz
120
+ const foundIndex = entitiesArr.findIndex(e => {
121
+ const name = getEntityReadableName(e);
122
+ return name && name.includes("ʙᴇsʟᴇʏiᴄi ");
123
+ });
124
+ if (foundIndex > -1) {
125
+ const ent = entitiesArr[foundIndex];
126
+ // activateEntityAt çağrısı orijinal kodda vardı; hata verirse logla
127
+ try {
128
+ bot.activateEntityAt(ent, ent.position);
129
+ } catch (err) {
130
+ logger.error("activateEntityAt çağrılırken hata: " + (err && err.message ? err.message : err));
131
+ }
132
+ }
133
+ } catch (err) {
134
+ logger.error("Periyodik entity kontrolü sırasında hata: " + (err && err.message ? err.message : err));
135
+ }
136
+ }, 30000);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  }
 
139
 
140
+ if (config.utils["chat-messages"].enabled) {
141
+ logger.info("Started chat-messages module");
142
 
143
+ let messages = config.utils["chat-messages"]["messages"];
 
 
 
 
 
144
 
145
+ if (config.utils["chat-messages"].repeat) {
146
+ let delay = config.utils["chat-messages"]["repeat-delay"];
147
+ let i = 0;
 
148
 
149
+ setInterval(() => {
150
+ bot.chat(`${messages[i]}`);
 
151
 
152
+ if (i + 1 === messages.length) {
153
+ i = 0;
154
+ } else i++;
155
+ }, delay * 1000);
156
+ } else {
157
+ messages.forEach((msg) => {
158
+ bot.chat(msg);
159
+ });
160
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  }
162
 
163
+ const pos = config.position;
164
+
165
+ if (config.position.enabled) {
166
+ logger.info(
167
+ `Starting moving to target location (${pos.x}, ${pos.y}, ${pos.z})`,
168
+ );
169
+ bot.pathfinder.setGoal(new GoalBlock(pos.x, pos.y, pos.z));
170
  }
171
 
172
+ if (config.utils["anti-afk"].enabled) {
173
+ if (config.utils["anti-afk"].sneak) {
174
+ bot.setControlState("sneak", true);
175
+ }
176
+
177
+ if (config.utils["anti-afk"].jump) {
178
+ bot.setControlState("jump", true);
179
+ }
180
+
181
+ if (config.utils["anti-afk"]["hit"].enabled) {
182
+ let delay = config.utils["anti-afk"]["hit"]["delay"];
183
+ let attackMobs = config.utils["anti-afk"]["hit"]["attack-mobs"];
184
+
185
+ setInterval(() => {
186
+ if (attackMobs) {
187
+ let entity = bot.nearestEntity(
188
+ (e) =>
189
+ e.type !== "object" &&
190
+ e.type !== "player" &&
191
+ e.type !== "global" &&
192
+ e.type !== "orb" &&
193
+ e.type !== "other",
194
+ );
195
+
196
+ if (entity) {
197
+ bot.attack(entity);
198
+ return;
199
+ }
200
+ }
201
+
202
+ bot.swingArm("right", true);
203
+ }, delay);
204
+ }
205
+
206
+ if (config.utils["anti-afk"].rotate) {
207
+ setInterval(() => {
208
+ bot.look(bot.entity.yaw + 1, bot.entity.pitch, true);
209
+ }, 100);
210
+ }
211
+
212
+ if (config.utils["anti-afk"]["circle-walk"].enabled) {
213
+ let radius = config.utils["anti-afk"]["circle-walk"]["radius"];
214
+ setInterval(() => {
215
+ circleWalk(bot, radius);
216
+ }, 30000);
217
+ }
218
  }
219
+ });
220
+
221
+ bot.on('windowOpen', function (window) {
222
+ if(window.title.includes("ʙᴇsʟᴇʏiᴄi ᴍiɴʏᴏɴ ᴘᴀɴᴇʟi")){
223
+ //Besleyici minyon paneli
224
+ if(window.slots.filter(xx => xx?.name && xx?.name == "cooked_beef").length > 0){
225
+ var minyoncani = Number((JSON.parse(window.slots.filter(xx => xx?.name && xx?.name == "cooked_beef")[0]?.nbt?.value?.display?.value?.Lore?.value?.value[1])?.extra[0].text).split("/")[0]);
226
+ if(minyoncani <= 2){
227
+ bot.clickWindow(36,0,0);
 
 
 
 
 
 
228
  logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${minyoncani} olduğu için besleyici minyon beslendi.`);
229
  bot.closeWindow(window);
230
+ }else{
231
+ bot.closeWindow(window);
232
+ }
233
+ }else{
234
  bot.closeWindow(window);
235
+ }
236
+ }else{
237
+ bot.closeWindow(window);
 
 
 
238
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  });
240
+
241
+ bot.on("chat", (username, message) => {
242
+ if (config.utils["chat-log"]) {
243
+ logger.info(`<${username}> ${message}`);
244
+ }
245
+ });
246
+
247
+ bot.on("goal_reached", () => {
248
+ if (config.position.enabled) {
249
+ logger.info(`Bot arrived to target location. ${bot.entity.position}`);
250
+ }
251
+ });
252
+
253
+ bot.on("death", () => {
254
+ logger.warn(
255
+ `Bot has been died and was respawned at ${bot.entity.position}`,
256
+ );
257
+ });
258
+
259
+ if (config.utils["auto-reconnect"]) {
260
+ bot.on("end", () => {
261
+ setTimeout(() => {
262
+ createBot();
263
+ }, config.utils["auto-reconnect-delay"]);
264
+ });
265
+ }
266
+
267
+ bot.on("kicked", (reason) => {
268
+ let reasonText = "";
269
+ try {
270
+ const parsed = JSON.parse(reason);
271
+ reasonText = parsed.text || parsed.extra?.[0]?.text || "";
272
+ reasonText = reasonText?.replace(/§./g, "");
273
+ logger.warn(`Bot sunucudan atıldı.Sebep: ${reasonText}`);
274
+ }catch{
275
+ logger.warn(`Bot sunucudan atıldı.Sebep: Bulunamadı.`);
276
+ }
277
+
278
+ });
279
+
280
+ bot.on("error", (err) => logger.error(`${err.message}`));
281
  }
282
 
283
+
284
  function circleWalk(bot, radius) {
285
+ // Make bot walk in square with center in bot's wthout stopping
286
+ return new Promise(() => {
287
+ const pos = bot.entity.position;
288
+ const x = pos.x;
289
+ const y = pos.y;
290
+ const z = pos.z;
291
+
292
+ const points = [
293
+ [x + radius, y, z],
294
+ [x, y, z + radius],
295
+ [x - radius, y, z],
296
+ [x, y, z - radius],
297
+ ];
298
+
299
+ let i = 0;
300
+ setTimeout(() => {
301
+ if (i === points.length) i = 0;
302
+ const defaultMove = new Movements(bot);
303
+ bot.pathfinder.setMovements(defaultMove);
304
+ bot.pathfinder.setGoal(new GoalXZ(points[i][0], points[i][2]));
305
+ i++;
306
+ }, 1000);
307
+ });
308
  }
309
 
310
  createBot();
 
316
  app.get("/", (req, res) => res.send("Pinglendi")); //değiştirebilirsiniz.
317
 
318
  app.listen(
319
+ port,
320
+ () =>
321
+ console.log(`Bot bu adres üzerinde çalışıyor: http://localhost:${port}`), //port
322
  );
323
 
324
  process.on('uncaughtException', function (err) {
325
+ console.error("Hata aldım!");
326
+ console.log(err)
327
+ })