-
Notifications
You must be signed in to change notification settings - Fork 10
/
moonbix-mt.js
369 lines (314 loc) · 13.9 KB
/
moonbix-mt.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
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
const fs = require('fs');
const path = require('path');
const axios = require('axios');
const colors = require('colors');
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
class Binance {
constructor(accountIndex, queryString) {
this.accountIndex = accountIndex;
this.queryString = queryString;
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://www.binance.com",
"Referer": "https://www.binance.com/vi/game/tg/moon-bix",
"Sec-Ch-Ua": '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
"Sec-Ch-Ua-Mobile": "?1",
"Sec-Ch-Ua-Platform": '"Android"',
"User-Agent": this.getRandomAndroidUserAgent()
};
this.game_response = null;
this.game = null;
}
getRandomAndroidUserAgent() {
const androidUserAgents = [
"Mozilla/5.0 (Linux; Android 10; SM-G975F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.120 Mobile Safari/537.36",
"Mozilla/5.0 (Linux; Android 11; Pixel 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Mobile Safari/537.36",
"Mozilla/5.0 (Linux; Android 12; SM-G998B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.62 Mobile Safari/537.36",
"Mozilla/5.0 (Linux; Android 11; OnePlus 9 Pro) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Mobile Safari/537.36",
"Mozilla/5.0 (Linux; Android 10; Redmi Note 9 Pro) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Mobile Safari/537.36"
];
return androidUserAgents[Math.floor(Math.random() * androidUserAgents.length)];
}
async log(msg, type = 'info') {
const timestamp = new Date().toLocaleTimeString();
const accountPrefix = `[Account ${this.accountIndex + 1}]`;
let logMessage = '';
switch(type) {
case 'success':
logMessage = `${accountPrefix} ${msg}`.green;
break;
case 'error':
logMessage = `${accountPrefix} ${msg}`.red;
break;
case 'warning':
logMessage = `${accountPrefix} ${msg}`.yellow;
break;
case 'custom':
logMessage = `${accountPrefix} ${msg}`.magenta;
break;
default:
logMessage = `${accountPrefix} ${msg}`.blue;
}
console.log(`[${timestamp}] ${logMessage}`);
}
createAxiosInstance() {
return axios.create({
headers: this.headers,
});
}
async callBinanceAPI(queryString, axios) {
const accessTokenUrl = "https://www.binance.com/bapi/growth/v1/friendly/growth-paas/third-party/access/accessToken";
const userInfoUrl = "https://www.binance.com/bapi/growth/v1/friendly/growth-paas/mini-app-activity/third-party/user/user-info";
try {
const accessTokenResponse = await axios.post(accessTokenUrl, {
queryString: queryString,
socialType: "telegram"
});
if (accessTokenResponse.data.code !== "000000" || !accessTokenResponse.data.success) {
throw new Error(`Failed to get access token: ${accessTokenResponse.data.message}`);
}
const accessToken = accessTokenResponse.data.data.accessToken;
const userInfoHeaders = {
...this.headers,
"X-Growth-Token": accessToken
};
const userInfoResponse = await axios.post(userInfoUrl, {
resourceId: 2056
}, { headers: userInfoHeaders });
if (userInfoResponse.data.code !== "000000" || !userInfoResponse.data.success) {
throw new Error(`Failed to get user info: ${userInfoResponse.data.message}`);
}
return { userInfo: userInfoResponse.data.data, accessToken };
} catch (error) {
this.log(`API call failed: ${error.message}`, 'error');
return null;
}
}
async startGame(accessToken, axios) {
try {
const response = await axios.post(
'https://www.binance.com/bapi/growth/v1/friendly/growth-paas/mini-app-activity/third-party/game/start',
{ resourceId: 2056 },
{ headers: { ...this.headers, "X-Growth-Token": accessToken } }
);
this.game_response = response.data;
if (response.data.code === '000000') {
this.log("Start game successfully, do not close tool before completion", 'success');
return true;
}
if (response.data.code === '116002') {
this.log("Not enough attempts!", 'warning');
} else {
this.log("Error starting the game!", 'error');
}
return false;
} catch (error) {
this.log(`Unable to start game: ${error.message}`, 'error');
return false;
}
}
async gameData() {
try {
const response = await axios.get('https://moonbix-server-9r08ifrt4-scriptvips-projects.vercel.app/moonbix/api/v1/play', {
params: { game_response: this.game_response },
timeout: this.timeout * 1000
});
if (response.data.message === 'success') {
this.game = response.data.game;
this.log("Game data received successfully", 'success');
return true;
}
this.log(response.data.message, 'warning');
return false;
} catch (error) {
this.log(`Error receiving game data: ${error.message}`, 'error');
return false;
}
}
async completeGame(accessToken, axios) {
try {
const response = await axios.post(
'https://www.binance.com/bapi/growth/v1/friendly/growth-paas/mini-app-activity/third-party/game/complete',
{
resourceId: 2056,
payload: this.game.payload,
log: this.game.log
},
{
headers: {
...this.headers,
"X-Growth-Token": accessToken
},
timeout: this.timeout * 1000
}
);
if (response.data.success) {
this.log(`Game completed successfully | Earned ${this.game.log} points`, 'custom');
return true;
}
this.log(`Cannot complete the game: ${response.data.message}`, 'error');
return false;
} catch (error) {
this.log(`Error completing the game: ${error.message}`, 'error');
return false;
}
}
async getTaskList(accessToken, axios) {
const taskListUrl = "https://www.binance.com/bapi/growth/v1/friendly/growth-paas/mini-app-activity/third-party/task/list";
try {
const response = await axios.post(taskListUrl, {
resourceId: 2056
}, {
headers: {
...this.headers,
"X-Growth-Token": accessToken
}
});
if (response.data.code !== "000000" || !response.data.success) {
throw new Error(`Cannot retrieve task list: ${response.data.message}`);
}
const taskList = response.data.data.data[0].taskList.data;
const resourceIds = taskList
.filter(task => task.completedCount === 0)
.map(task => task.resourceId);
return resourceIds;
} catch (error) {
this.log(`Cannot retrieve task list: ${error.message}`, 'error');
return null;
}
}
async completeTask(accessToken, resourceId, axios) {
const completeTaskUrl = "https://www.binance.com/bapi/growth/v1/friendly/growth-paas/mini-app-activity/third-party/task/complete";
try {
const response = await axios.post(completeTaskUrl, {
resourceIdList: [resourceId],
referralCode: null
}, {
headers: {
...this.headers,
"X-Growth-Token": accessToken
}
});
if (response.data.code !== "000000" || !response.data.success) {
throw new Error(`Cannot complete the task: ${response.data.message}`);
}
if (response.data.data.type) {
this.log(`Successfully completed task ${response.data.data.type}!`, 'success');
}
return true;
} catch (error) {
this.log(`Cannot complete the task: ${error.message}`, 'error');
return false;
}
}
async completeTasks(accessToken, axios) {
const resourceIds = await this.getTaskList(accessToken, axios);
if (!resourceIds || resourceIds.length === 0) {
this.log("No uncompleted tasks found", 'info');
return;
}
for (const resourceId of resourceIds) {
if (resourceId !== 2058) {
const success = await this.completeTask(accessToken, resourceId, axios);
if (success) {
this.log(`Completed task: ${resourceId}`, 'success');
} else {
this.log(`Cannot complete task: ${resourceId}`, 'warning');
}
await new Promise(resolve => setTimeout(resolve, 1000));
}
}
}
async playGameIfTicketsAvailable() {
const axiosInstance = this.createAxiosInstance();
const result = await this.callBinanceAPI(this.queryString, axiosInstance);
if (!result) return;
const { userInfo, accessToken } = result;
const totalGrade = userInfo.metaInfo.totalGrade;
let availableTickets = userInfo.metaInfo.totalAttempts - userInfo.metaInfo.consumedAttempts;
this.log(`Total points: ${totalGrade}`);
this.log(`Available tickets: ${availableTickets}`);
await this.completeTasks(accessToken, axiosInstance);
while (availableTickets > 0) {
this.log(`Start the game with ${availableTickets} available tickets`, 'info');
if (await this.startGame(accessToken, axiosInstance)) {
if (await this.gameData()) {
await new Promise(resolve => setTimeout(resolve, 50000));
if (await this.completeGame(accessToken, axiosInstance)) {
availableTickets--;
this.log(`Remaining tickets: ${availableTickets}`, 'info');
await new Promise(resolve => setTimeout(resolve, 3000));
} else {
break;
}
} else {
this.log("Cannot retrieve game data", 'error');
break;
}
} else {
this.log("Cannot start the game", 'error');
break;
}
}
if (availableTickets === 0) {
this.log("All tickets used up", 'success');
}
}
}
if (isMainThread) {
const dataFile = path.join(__dirname, 'data.txt');
const data = fs.readFileSync(dataFile, 'utf8')
.replace(/\r/g, '')
.split('\n')
.filter(Boolean);
const maxThreads = 8; // number of threads
const timeout = 10 * 60 * 1000;
const waitTime = 60 * 60 * 1000; // 1 hour
async function runWorkers() {
while (true) {
const moonbixT = "\n\x1b[1mMoonbix\x1b[0m";
const additionalText = "\nIf you use it, don't be afraid.\nIf you're afraid, don't use it.\nDo With Your Own Risk!\n";
console.log(moonbixT.green);
console.log(additionalText.yellow);
for (let i = 0; i < data.length; i += maxThreads) {
const workerPromises = [];
for (let j = 0; j < maxThreads && i + j < data.length; j++) {
const accountIndex = i + j;
const queryString = data[accountIndex];
const worker = new Worker(__filename, {
workerData: { accountIndex, queryString}
});
const workerPromise = new Promise((resolve, reject) => {
worker.on('message', resolve);
worker.on('error', reject);
worker.on('exit', (code) => {
if (code !== 0) reject(new Error(`The stream is stopped with the code ${code}`));
});
setTimeout(() => {
worker.terminate();
reject(new Error('Worker timed out'));
}, timeout);
});
workerPromises.push(workerPromise);
}
await Promise.allSettled(workerPromises);
await new Promise(resolve => setTimeout(resolve, 3 * 1000));
}
console.log(`All accounts processed. Waiting ${waitTime / 60000} minutes before the next round starts...`);
await new Promise(resolve => setTimeout(resolve, waitTime));
}
}
runWorkers().catch(console.error);
} else {
const { accountIndex, queryString } = workerData;
const client = new Binance(accountIndex, queryString);
client.playGameIfTicketsAvailable().then(() => {
parentPort.postMessage('done');
}).catch(error => {
console.error(`Worker error: ${error.message}`);
parentPort.postMessage('error');
});
}