-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzoo-proxy.js
More file actions
847 lines (745 loc) · 28.9 KB
/
Copy pathzoo-proxy.js
File metadata and controls
847 lines (745 loc) · 28.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
const fs = require("fs");
const path = require("path");
const axios = require("axios");
const colors = require("colors");
const readline = require("readline");
const crypto = require("crypto");
const { DateTime } = require("luxon");
const { HttpsProxyAgent } = require("https-proxy-agent");
const user_agents = require("./config/userAgents");
const settings = require("./config/config");
const { sleep, loadData, getRandomNumber } = require("./utils");
const { checkBaseUrl } = require("./checkAPI");
const { Worker, isMainThread, parentPort, workerData } = require("worker_threads");
class ZooAPIClient {
constructor(queryId, accountIndex, proxy, baseURL) {
this.headers = {
Accept: "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "vi-VN,vi;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5",
"Content-Type": "application/json",
Origin: "https://game.zoo.team",
Referer: "https://game.zoo.team/",
"Sec-Ch-Ua": '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-site",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
"Is-Beta-Server": "null",
};
this.cachedData = null;
this.proxyList = [];
this.loadProxies();
this.session_user_agents = this.#load_session_data();
this.baseURL = baseURL;
this.queryId = queryId;
this.accountIndex = accountIndex;
this.proxy = proxy;
this.proxyIP = null;
this.session_name = null;
}
#load_session_data() {
try {
const filePath = path.join(process.cwd(), "session_user_agents.json");
const data = fs.readFileSync(filePath, "utf8");
return JSON.parse(data);
} catch (error) {
if (error.code === "ENOENT") {
return {};
} else {
throw error;
}
}
}
#get_random_user_agent() {
const randomIndex = Math.floor(Math.random() * user_agents.length);
return user_agents[randomIndex];
}
#get_user_agent() {
if (this.session_user_agents[this.session_name]) {
return this.session_user_agents[this.session_name];
}
this.log(`Tạo user agent...`);
const newUserAgent = this.#get_random_user_agent();
this.session_user_agents[this.session_name] = newUserAgent;
this.#save_session_data(this.session_user_agents);
return newUserAgent;
}
#save_session_data(session_user_agents) {
const filePath = path.join(process.cwd(), "session_user_agents.json");
fs.writeFileSync(filePath, JSON.stringify(session_user_agents, null, 2));
}
#get_platform(userAgent) {
const platformPatterns = [
{ pattern: /iPhone/i, platform: "ios" },
{ pattern: /Android/i, platform: "android" },
{ pattern: /iPad/i, platform: "ios" },
];
for (const { pattern, platform } of platformPatterns) {
if (pattern.test(userAgent)) {
return platform;
}
}
return "Unknown";
}
set_headers() {
const platform = this.#get_platform(this.#get_user_agent());
this.headers["sec-ch-ua"] = `"Not)A;Brand";v="99", "${platform} WebView";v="127", "Chromium";v="127`;
this.headers["sec-ch-ua-platform"] = platform;
this.headers["User-Agent"] = this.#get_user_agent();
}
createUserAgent() {
try {
const telegramauth = this.queryId;
const userData = JSON.parse(decodeURIComponent(telegramauth.split("user=")[1].split("&")[0]));
this.session_name = userData.id;
this.#get_user_agent();
} catch (error) {
this.log(`Can't create user agent, try get new query_id: ${error.message}`, "error");
return;
}
}
loadProxies() {
try {
const proxyFile = path.join(__dirname, "proxy.txt");
if (fs.existsSync(proxyFile)) {
this.proxyList = fs.readFileSync(proxyFile, "utf8").replace(/\r/g, "").split("\n").filter(Boolean);
}
} catch (error) {
this.log("Error loading proxies: " + error.message, "error");
}
}
async checkProxyIP(proxy) {
try {
const proxyAgent = new HttpsProxyAgent(proxy);
const response = await axios.get("https://api.ipify.org?format=json", {
httpsAgent: proxyAgent,
timeout: 10000,
});
if (response.status === 200) {
return response.data.ip;
} else {
throw new Error(`Không thể kiểm tra IP của proxy. Status code: ${response.status}`);
}
} catch (error) {
throw new Error(`Error khi kiểm tra IP của proxy: ${error.message}`);
}
}
getAxiosConfig(index) {
if (this.proxyList.length > 0 && index < this.proxyList.length) {
return {
httpsAgent: new HttpsProxyAgent(this.proxyList[index]),
timeout: 30000,
};
}
return { timeout: 30000 };
}
async createApiHash(timestamp, data) {
const combinedData = `${timestamp}_${data}`;
const encodedData = encodeURIComponent(combinedData);
return crypto.createHash("md5").update(encodedData).digest("hex");
}
async login(initData, accountIndex) {
if (!initData) {
return { success: false, error: "initData is required" };
}
try {
const hash = initData.split("hash=")[1]?.split("&")[0];
if (!hash) {
throw new Error("Could not extract hash from initData");
}
const currentTime = Math.floor(Date.now() / 1000);
const userData = JSON.parse(decodeURIComponent(initData.split("user=")[1].split("&")[0]));
const startParam = initData.split("start_param=")[1]?.split("&")[0] || "";
const chatInstance = initData.split("chat_instance=")[1]?.split("&")[0] || "";
const payload = {
data: {
initData: initData,
startParam: startParam,
photoUrl: userData.photo_url || "",
platform: "android",
chatId: "",
chatType: "channel",
chatInstance: chatInstance,
},
};
const apiHash = await this.createApiHash(currentTime, JSON.stringify(payload));
const headers = {
...this.headers,
"api-hash": apiHash,
"Api-Key": hash,
"Api-Time": currentTime,
};
const response = await axios.post(`${this.baseURL}/telegram/auth`, payload, {
headers,
...this.getAxiosConfig(accountIndex),
});
if (response.status === 200 && response.data.success) {
return { success: true, data: response.data.data };
} else {
return { success: false, error: response.data.message };
}
} catch (error) {
return { success: false, error: error.message };
}
}
async finishOnboarding(initData, accountIndex) {
try {
const hash = initData.split("hash=")[1]?.split("&")[0];
if (!hash) {
throw new Error("Could not extract hash from initData");
}
const currentTime = Math.floor(Date.now() / 1000);
const payload = { data: 1 };
const apiHash = await this.createApiHash(currentTime, JSON.stringify(payload));
const headers = {
...this.headers,
"api-hash": apiHash,
"Api-Key": hash,
"Api-Time": currentTime,
};
const response = await axios.post(`${this.baseURL}/hero/onboarding/finish`, payload, {
headers,
...this.getAxiosConfig(accountIndex),
});
if (response.status === 200 && response.data.success) {
return { success: true, data: response.data.data };
} else {
return { success: false, error: response.data.message };
}
} catch (error) {
return { success: false, error: error.message };
}
}
async getUserData(initData, accountIndex) {
if (!initData) {
return { success: false, error: "initData is required" };
}
try {
const hash = initData.split("hash=")[1]?.split("&")[0];
if (!hash) {
throw new Error("Could not extract hash from initData");
}
const currentTime = Math.floor(Date.now() / 1000);
const dataPayload = JSON.stringify({ data: {} });
const apiHash = await this.createApiHash(currentTime, dataPayload);
const headers = {
...this.headers,
"api-hash": apiHash,
"Api-Key": hash,
"Api-Time": currentTime,
};
const response = await axios.post(
`${this.baseURL}/user/data/all`,
{ data: {} },
{
headers,
...this.getAxiosConfig(accountIndex),
}
);
if (response.status === 200 && response.data.success) {
this.cachedData = response.data.data;
return { success: true, data: response.data.data };
} else {
return { success: false, error: response.data.message };
}
} catch (error) {
return { success: false, error: error.message };
}
}
async getUserDataAfter(initData, accountIndex) {
try {
const hash = initData.split("hash=")[1]?.split("&")[0];
if (!hash) {
throw new Error("Could not extract hash from initData");
}
const currentTime = Math.floor(Date.now() / 1000);
const dataPayload = JSON.stringify({ data: {} });
const apiHash = await this.createApiHash(currentTime, dataPayload);
const headers = {
...this.headers,
"api-hash": apiHash,
"Api-Key": hash,
"Api-Time": currentTime,
};
const response = await axios.post(
`${this.baseURL}/user/data/after`,
{ data: {} },
{
headers,
...this.getAxiosConfig(accountIndex),
}
);
if (response.status === 200 && response.data.success) {
return { success: true, data: response.data.data };
} else {
return { success: false, error: response.data.message };
}
} catch (error) {
return { success: false, error: error.message };
}
}
async claimDailyReward(initData, rewardIndex, accountIndex) {
try {
const hash = initData.split("hash=")[1]?.split("&")[0];
if (!hash) {
throw new Error("Could not extract hash from initData");
}
const currentTime = Math.floor(Date.now() / 1000);
const payload = { data: rewardIndex };
const apiHash = await this.createApiHash(currentTime, JSON.stringify(payload));
const headers = {
...this.headers,
"api-hash": apiHash,
"Api-Key": hash,
"Api-Time": currentTime,
};
const response = await axios.post(`${this.baseURL}/quests/daily/claim`, payload, {
headers,
...this.getAxiosConfig(accountIndex),
});
if (response.status === 200 && response.data.success) {
return { success: true, data: response.data.data };
} else {
return { success: false, error: response.data.message };
}
} catch (error) {
return { success: false, error: error.message };
}
}
async AnswerDaily(hash, accountIndex, questKey, checkData) {
const url = `${this.baseURL}/quests/check`;
const currentTime = Math.floor(Date.now() / 1000);
const payload = { data: [questKey, checkData] };
const apiHash = await this.createApiHash(currentTime, JSON.stringify(payload));
const headers = {
...this.headers,
"api-hash": `${apiHash}`,
"Api-Key": `${hash}`,
"Api-Time": `${currentTime}`,
};
try {
const response = await axios.post(url, payload, { headers, ...this.getAxiosConfig(accountIndex) });
if (response.status === 200 && response.data.success) {
return await this.claimQuest(hash, accountIndex, questKey, checkData);
} else {
this.log(`Kiểm tra nhiệm vụ "${questKey}" thất bại: ${response.data.error}`, "warning");
return { success: false, error: response.data.error };
}
} catch (error) {
this.log(`Lỗi khi kiểm tra nhiệm vụ "${questKey}": ${error.message}`, "error");
return { success: false, error: error.message };
}
}
async claimQuest(hash, accountIndex, questKey, checkData = null) {
const payload = { data: [questKey, checkData] };
const currentTime = Math.floor(Date.now() / 1000);
const apiHash = await this.createApiHash(currentTime, JSON.stringify(payload));
const url = `${this.baseURL}/quests/claim`;
const headers = {
...this.headers,
"api-hash": `${apiHash}`,
"Api-Key": `${hash}`,
"Api-Time": `${currentTime}`,
};
try {
const response = await axios.post(url, payload, {
headers,
...this.getAxiosConfig(accountIndex),
});
if (response.status === 200 && response.data.success) {
this.log(`Claim nhiệm vụ "${questKey}" thành công, nhận thưởng.`, "success");
return { success: true, data: response.data };
} else {
return { success: false, error: response.data.error };
}
} catch (error) {
this.log(`Lỗi khi claim nhiệm vụ "${questKey}": ${error.message}`, "error");
return { success: false, error: error.message };
}
}
async completeAllQuests(initData, accountIndex) {
try {
const hash = initData.split("hash=")[1]?.split("&")[0];
if (!hash) {
throw new Error("Could not extract hash from initData");
}
const userDataResult = await this.getUserData(initData, accountIndex);
if (!userDataResult.success) {
throw new Error(`Failed to get user data: ${userDataResult.error}`);
}
const { dbData } = userDataResult.data;
const quests = dbData.dbQuests.filter((q) => !settings.SKIP_TASKS.includes(q.key));
for (const quest of quests) {
if (quest.checkType === "donate_ton" || quest.checkType === "invite" || quest.checkType === "username" || quest.checkType === "ton_wallet_transaction") {
continue;
}
if (quest.checkType === "checkCode") {
this.log(`Bắt đầu làm nhiệm vụ trả lời câu hỏi hằng ngày...`, "custom");
await this.AnswerDaily(hash, accountIndex, quest.key, quest.checkData);
continue;
}
const claimResult = await this.claimQuest(hash, accountIndex, quest.key);
if (claimResult.success === true) {
this.log(`Hoàn thành nhiệm vụ ${quest.key} | "${quest.title}", nhận ${quest.reward} phần thưởng.`, "success");
} else if (claimResult.error === "already rewarded") {
this.log(`Nhiệm vụ ${quest.key} "${quest.title}" đã được hoàn thành trước đó.`, "warning");
} else {
this.log(`Không thể hoàn thành hoặc cần làm bằng tay nhiệm vụ ${quest.key} | "${quest.title}": ${claimResult.error}`, "warning");
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
} catch (error) {
this.log(`Lỗi khi lấy danh sách nhiệm vụ: ${error.message}`, "error");
}
}
async handleAutoFeed(initData, accountIndex) {
try {
const hash = initData.split("hash=")[1]?.split("&")[0];
if (!hash) {
throw new Error("Could not extract hash from initData");
}
const userDataResult = await this.getUserData(initData, accountIndex);
if (!userDataResult.success) {
throw new Error(`Failed to get user data: ${userDataResult.error}`);
}
const { hero, feed } = userDataResult.data;
if (feed.isNeedFeed) {
if (!hero.onboarding.includes("20")) {
const currentTime = Math.floor(Date.now() / 1000);
const payload = { data: 20 };
const apiHash = await this.createApiHash(currentTime, JSON.stringify(payload));
const headers = {
...this.headers,
"api-hash": apiHash,
"Api-Key": hash,
"Api-Time": currentTime,
};
const onboardingResponse = await axios.post(`${this.baseURL}/hero/onboarding/finish`, payload, {
headers,
...this.getAxiosConfig(accountIndex),
});
if (!onboardingResponse.data.success) {
throw new Error("Failed to complete onboarding step 20");
}
}
const currentTime = Math.floor(Date.now() / 1000);
const feedPayload = { data: "instant" };
const apiHash = await this.createApiHash(currentTime, JSON.stringify(feedPayload));
const headers = {
...this.headers,
"api-hash": apiHash,
"Api-Key": hash,
"Api-Time": currentTime,
};
const feedResponse = await axios.post(`${this.baseURL}/autofeed/buy`, feedPayload, {
headers,
...this.getAxiosConfig(accountIndex),
});
if (feedResponse.data.success) {
this.log("Cho động vật ăn thành công", "success");
return { success: true, data: feedResponse.data };
}
}
return { success: true };
} catch (error) {
return { success: false, error: error.message };
}
}
async buyOrUpgradeAnimals(initData, accountIndex) {
try {
const hash = initData.split("hash=")[1]?.split("&")[0];
if (!hash) {
throw new Error("Could not extract hash from initData");
}
const userDataResult = await this.getUserData(initData, accountIndex);
if (!userDataResult.success) {
throw new Error(`Failed to get user data: ${userDataResult.error}`);
}
const { animals, hero, dbData } = userDataResult.data;
const existingKeys = new Set(animals.map((animal) => animal.key));
const usedPositions = new Set(animals.map((animal) => animal.position));
if (settings.AUTO_BUY_ANIMAL) {
for (const dbAnimal of dbData.dbAnimals) {
if (!existingKeys.has(dbAnimal.key)) {
const level1Price = dbAnimal.levels[0].price;
if (hero.coins >= level1Price) {
let position = 1;
while (usedPositions.has(position)) {
position++;
}
const currentTime = Math.floor(Date.now() / 1000);
const payload = { data: { position, animalKey: dbAnimal.key } };
const apiHash = await this.createApiHash(currentTime, JSON.stringify(payload));
const headers = {
...this.headers,
"api-hash": apiHash,
"Api-Key": hash,
"Api-Time": currentTime,
};
const response = await axios.post(`${this.baseURL}/animal/buy`, payload, {
headers,
...this.getAxiosConfig(accountIndex),
});
if (response.status === 200 && response.data.success) {
this.log(`Mua thành công ${dbAnimal.title}`, "success");
usedPositions.add(position);
existingKeys.add(dbAnimal.key);
}
}
}
}
}
if (settings.AUTO_UPGRADE_ANIMAL) {
for (const animal of animals) {
const dbAnimal = dbData.dbAnimals.find((dba) => dba.key === animal.key);
if (dbAnimal) {
if (animal.level >= settings.MAX_LEVEL_UPGRADE_ANIMAL) continue;
const nextLevel = animal.level + 1;
const nextLevelData = dbAnimal.levels.find((l) => l.level === nextLevel);
if (nextLevelData && hero.coins >= nextLevelData.price) {
const currentTime = Math.floor(Date.now() / 1000);
const payload = { data: { position: animal.position, animalKey: animal.key } };
const apiHash = await this.createApiHash(currentTime, JSON.stringify(payload));
const headers = {
...this.headers,
"api-hash": apiHash,
"Api-Key": hash,
"Api-Time": currentTime,
};
try {
const response = await axios.post(`${this.baseURL}/animal/buy`, payload, {
headers,
...this.getAxiosConfig(accountIndex),
});
if (response.status === 200 && response.data.success) {
this.log(`Nâng cấp ${dbAnimal.title} thành công lên level ${nextLevel}`, "success");
}
} catch (error) {
if (error.response?.status === 500) {
this.log(`Không thể nâng cấp ${dbAnimal.title}: ${error.message}`, "error");
}
}
}
}
}
}
return { success: true };
} catch (error) {
return { success: false, error: error.message };
}
}
log(msg, type = "info") {
const timestamp = new Date().toLocaleTimeString();
const accountPrefix = `[Tài khoản ${this.accountIndex + 1}]`;
const ipPrefix = this.proxyIP ? `[${this.proxyIP}]` : "[Unknown IP]";
switch (type) {
case "success":
console.log(`[${timestamp}]${accountPrefix}${ipPrefix} [✓] ${msg}`.green);
break;
case "custom":
console.log(`[${timestamp}]${accountPrefix}${ipPrefix} [*] ${msg}`.magenta);
break;
case "error":
console.log(`[${timestamp}]${accountPrefix}${ipPrefix} [✗] ${msg}`.red);
break;
case "warning":
console.log(`[${timestamp}]${accountPrefix}${ipPrefix} [!] ${msg}`.yellow);
break;
default:
console.log(`[${timestamp}]${accountPrefix}${ipPrefix} [ℹ] ${msg}`.blue);
}
}
calculateWaitTimeInSeconds(nextFeedTime) {
const now = DateTime.local();
const feedTime = DateTime.fromFormat(nextFeedTime, "yyyy-MM-dd HH:mm:ss", { zone: "UTC" }).setZone("local");
const diffInSeconds = Math.max(0, Math.floor(feedTime.diff(now, "seconds").seconds));
return diffInSeconds;
}
async countdown(seconds) {
const endTime = DateTime.local().plus({ seconds });
for (let i = seconds; i > 0; i--) {
const currentTime = DateTime.local().toLocaleString(DateTime.TIME_WITH_SECONDS);
const remainingTime = endTime.diff(DateTime.local());
const remainingMinutes = Math.floor(remainingTime.as("minutes"));
const remainingSeconds = Math.floor(remainingTime.as("seconds")) % 60;
readline.cursorTo(process.stdout, 0);
process.stdout.write(`[${currentTime}] [*] Chờ ${remainingMinutes} phút ${remainingSeconds} giây để tiếp tục...`);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
readline.cursorTo(process.stdout, 0);
readline.clearLine(process.stdout, 0);
}
async runAccount() {
const i = this.accountIndex;
const initData = this.queryId;
const queryData = JSON.parse(decodeURIComponent(initData.split("user=")[1].split("&")[0]));
const firstName = queryData.first_name || "";
const lastName = queryData.last_name || "";
this.session_name = queryData.id;
if (this.proxy) {
try {
this.proxyIP = await this.checkProxyIP(this.proxy);
} catch (proxyError) {
this.log(`Proxy check failed: ${proxyError.message}`, "warning");
}
}
const timesleep = getRandomNumber(settings.DELAY_START_BOT[0], settings.DELAY_START_BOT[1]);
console.log(`=========Tài khoản ${i + 1}| ${firstName + " " + lastName} | ${this.proxyIP} | Bắt đầu sau ${timesleep} giây...`.green);
this.set_headers();
await sleep(timesleep);
try {
this.log(`Đang đăng nhập...`, "info");
const loginResult = await this.login(initData, i);
if (loginResult.success) {
this.log("Đăng nhập thành công!", "success");
const userDataResult = await this.getUserData(initData, i);
if (userDataResult.success) {
const { hero, feed } = userDataResult.data;
if (i === 0 && !feed.isNeedFeed && feed.nextFeedTime) {
const localFeedTime = DateTime.fromFormat(feed.nextFeedTime, "yyyy-MM-dd HH:mm:ss", { zone: "UTC" }).setZone("local");
this.log(`Thời gian cho ăn tiếp theo: ${localFeedTime.toFormat("yyyy-MM-dd HH:mm:ss")}`, "info");
}
if (Array.isArray(hero.onboarding) && hero.onboarding.length === 0) {
this.log("Đang hoàn thành onboarding...", "info");
const onboardingResult = await this.finishOnboarding(initData, i);
if (onboardingResult.success) {
this.log("Hoàn thành onboarding thành công!", "success");
}
}
if (settings.AUTO_FEED) {
await this.handleAutoFeed(initData, i);
}
if (settings.AUTO_TASK) {
await this.completeAllQuests(initData, i);
}
if (settings.AUTO_BUY_ANIMAL || settings.AUTO_UPGRADE_ANIMAL) {
await this.buyOrUpgradeAnimals(initData, i);
}
const dataAfterResult = await this.getUserDataAfter(initData, i);
if (dataAfterResult.success) {
const { dailyRewards } = dataAfterResult.data;
for (let day = 1; day <= 16; day++) {
if (dailyRewards[day] === "canTake") {
this.log(`Đang nhận phần thưởng ngày ${day}...`, "info");
const claimResult = await this.claimDailyReward(initData, day, i);
if (claimResult.success) {
this.log("Điểm danh hàng ngày thành công!", "success");
}
break;
}
}
}
const finalData = await this.getUserData(initData, i);
if (finalData.success) {
this.log(`Token: ${finalData.data.hero.tokens}`, "custom");
this.log(`Coins: ${finalData.data.hero.coins}`, "custom");
}
}
}
await new Promise((resolve) => setTimeout(resolve, 2000));
} catch (error) {
this.log(`Error processing account ${i + 1}: ${error.message}`, "error");
return;
}
}
}
async function runWorker(workerData) {
const { queryId, accountIndex, proxy, hasIDAPI } = workerData;
const to = new ZooAPIClient(queryId, accountIndex, proxy, hasIDAPI);
try {
await Promise.race([to.runAccount(), new Promise((_, reject) => setTimeout(() => reject(new Error("Timeout")), 24 * 60 * 60 * 1000))]);
parentPort.postMessage({
accountIndex,
});
} catch (error) {
parentPort.postMessage({ accountIndex, error: error.message });
} finally {
if (!isMainThread) {
parentPort.postMessage("taskComplete");
}
}
}
async function main() {
const queryIds = loadData("data.txt");
const proxies = loadData("proxy.txt");
if (queryIds.length > proxies.length) {
console.log("Số lượng proxy và data phải bằng nhau.".red);
console.log(`Data: ${queryIds.length}`);
console.log(`Proxy: ${proxies.length}`);
process.exit(1);
}
console.log("Tool được phát triển bởi nhóm tele Airdrop Hunter Siêu Tốc (https://t.me/airdrophuntersieutoc)".yellow);
let maxThreads = settings.MAX_THEADS;
const { endpoint: hasIDAPI, message } = await checkBaseUrl();
if (!hasIDAPI) return console.log(`Không thể tìm thấy ID API, thử lại sau!`.red);
console.log(`${message}`.yellow);
// process.exit();
queryIds.map((val, i) => new ZooAPIClient(val, i, proxies[i], hasIDAPI).createUserAgent());
await sleep(1);
while (true) {
let currentIndex = 0;
const errors = [];
while (currentIndex < queryIds.length) {
const workerPromises = [];
const batchSize = Math.min(maxThreads, queryIds.length - currentIndex);
for (let i = 0; i < batchSize; i++) {
const worker = new Worker(__filename, {
workerData: {
hasIDAPI,
queryId: queryIds[currentIndex],
accountIndex: currentIndex,
proxy: proxies[currentIndex % proxies.length],
},
});
workerPromises.push(
new Promise((resolve) => {
worker.on("message", (message) => {
if (message === "taskComplete") {
worker.terminate();
}
if (settings.ENABLE_DEBUG) {
console.log(message);
}
resolve();
});
worker.on("error", (error) => {
console.log(`Lỗi worker cho tài khoản ${currentIndex}: ${error.message}`);
worker.terminate();
resolve();
});
worker.on("exit", (code) => {
worker.terminate();
if (code !== 0) {
errors.push(`Worker cho tài khoản ${currentIndex} thoát với mã: ${code}`);
}
resolve();
});
})
);
currentIndex++;
}
await Promise.all(workerPromises);
if (errors.length > 0) {
errors.length = 0;
}
if (currentIndex < queryIds.length) {
await new Promise((resolve) => setTimeout(resolve, 3000));
}
}
await sleep(3);
console.log("Tool được phát triển bởi nhóm tele Airdrop Hunter Siêu Tốc (https://t.me/airdrophuntersieutoc)".yellow);
console.log(`=============Hoàn thành tất cả tài khoản | Chờ ${settings.TIME_SLEEP} phút=============`.magenta);
await sleep(settings.TIME_SLEEP * 60);
}
}
if (isMainThread) {
main().catch((error) => {
console.log("Lỗi rồi:", error);
process.exit(1);
});
} else {
runWorker(workerData);
}