-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
161 lines (148 loc) · 4.57 KB
/
index.js
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
import { Blum } from "./src/blum/blum.js";
import { Config } from "./src/config/config.js";
import { proxyList } from "./src/config/proxy_list.js";
import { Telegram } from "./src/core/telegram.js";
import { Helper } from "./src/utils/helper.js";
import logger from "./src/utils/logger.js";
async function operation(acc, query, queryObj, proxy) {
logger.clear();
try {
const blum = new Blum(acc, query, queryObj, proxy);
await blum.login();
// await blum.getUser(true);
await blum.getBalance(true);
await blum.checkIn();
if (blum.balance.farming) {
if (Helper.isFutureTime(blum.balance.farming.endTime)) {
await blum.claim();
}
}
await blum.mining();
await blum.getTaskAnswer();
await blum.getTasks(true);
const uncompletableTaskIds = [
"a90d8b81-0974-47f1-bb00-807463433bde",
"03e4a46f-7588-4950-8289-f42787e3eca2",
];
const uncompletedTasks = blum.tasks.filter(
(task) =>
task.status !== "FINISHED" &&
task.type !== "WALLET_CONNECTION" &&
task.type !== "PROGRESS_TARGET" &&
!uncompletableTaskIds.includes(task.id)
);
for (const task of uncompletedTasks) {
if (task.status === "NOT_STARTED") {
await blum.startAndCompleteTask(task.id);
} else if (task.status === "READY_FOR_VERIFY") {
const answer = blum.TASKANSWER.find((item) => item.id == task.id);
if (answer != -1 && answer != undefined) {
await blum.validateAndCompleteTask(task.id, answer.answer);
}
} else {
await blum.completeTask(task.id);
}
}
let err = 0;
// if (Config.PLAYGAME ?? true)
// while (blum.balance.playPasses > 0) {
// await blum.play().catch(() => {
// err += 1;
// });
// if (err > 5) {
// await Helper.delay(
// 3000,
// acc,
// "Failed to play game something wen't wrong",
// blum
// );
// logger.error(err);
// break;
// }
// }
await Helper.delay(
60000 * 10,
acc,
"Account Processing Complete, Delaying for 1 hour",
blum
);
await operation(acc, query, queryObj, proxy);
} catch (error) {
await Helper.delay(
10000,
acc,
`Error : ${error}, Retrying after 10 Second`
);
await operation(acc, query, queryObj, proxy);
}
}
let init = false;
async function startBot() {
return new Promise(async (resolve, reject) => {
try {
logger.info(`BOT STARTED`);
const tele = await new Telegram();
if (init == false) {
await tele.init();
init = true;
}
const accountList = Helper.getSession("accounts");
const paramList = [];
if (proxyList.length > 0) {
if (accountList.length != proxyList.length) {
reject(
`You have ${accountList.length} Session but you provide ${proxyList.length} Proxy`
);
}
}
for (const acc of accountList) {
const accIdx = accountList.indexOf(acc);
const proxy = proxyList.length > 0 ? proxyList[accIdx] : undefined;
if (!acc.includes("query")) {
await tele.useSession("accounts/" + acc, proxy);
tele.session = acc;
const user = await tele.client.getMe();
const query = await tele
.resolvePeer()
.then(async () => {
return await tele.initWebView();
})
.catch((err) => {
throw err;
});
const queryObj = Helper.queryToJSON(query);
await tele.disconnect();
paramList.push([user, query, queryObj, proxy]);
} else {
const query = Helper.readQueryFile("accounts/" + acc + "/query.txt");
const queryObj = Helper.queryToJSON(query);
const user = queryObj.user;
user.firstName = user.first_name;
user.lastName = user.last_name;
paramList.push([user, query, queryObj, proxy]);
}
}
const promiseList = paramList.map(async (data) => {
await operation(data[0], data[1], data[2], data[3]);
});
await Promise.all(promiseList);
resolve();
} catch (error) {
logger.info(`BOT STOPPED`);
logger.error(JSON.stringify(error));
reject(error);
}
});
}
(async () => {
try {
logger.info("");
logger.clear();
logger.info("Application Started");
await startBot();
} catch (error) {
console.error("Error in main process:", error);
logger.info(`Application Error : ${error}`);
throw error;
}
})();