-
Notifications
You must be signed in to change notification settings - Fork 8
/
moonbix.js
330 lines (282 loc) · 12 KB
/
moonbix.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
const fs = require('fs');
const path = require('path');
const axios = require('axios');
const colors = require('colors');
const readline = require('readline');
class Binance {
constructor() {
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": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
"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"
};
this.axios = axios.create({ headers: this.headers });
this.game_response = null;
this.game = null;
}
log(msg, type = 'info') {
const timestamp = new Date().toLocaleTimeString();
switch(type) {
case 'success':
console.log(`[${timestamp}] [*] ${msg}`.green);
break;
case 'custom':
console.log(`[${timestamp}] [*] ${msg}`.magenta);
break;
case 'error':
console.log(`[${timestamp}] [!] ${msg}`.red);
break;
case 'warning':
console.log(`[${timestamp}] [*] ${msg}`.yellow);
break;
default:
console.log(`[${timestamp}] [*] ${msg}`);
}
}
async countdown(seconds) {
for (let i = seconds; i > 0; i--) {
const timestamp = new Date().toLocaleTimeString();
readline.cursorTo(process.stdout, 0);
process.stdout.write(`[${timestamp}] [*] Waiting ${i} seconds to continue...`);
await new Promise(resolve => setTimeout(resolve, 1000));
}
readline.cursorTo(process.stdout, 0);
readline.clearLine(process.stdout, 0);
}
async callBinanceAPI(queryString) {
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 this.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 this.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) {
try {
const response = await this.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("Game started successfully", '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(`Cannot start the 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) {
try {
const response = await this.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) {
const taskListUrl = "https://www.binance.com/bapi/growth/v1/friendly/growth-paas/mini-app-activity/third-party/task/list";
try {
const response = await this.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) {
const completeTaskUrl = "https://www.binance.com/bapi/growth/v1/friendly/growth-paas/mini-app-activity/third-party/task/complete";
try {
const response = await this.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) {
const resourceIds = await this.getTaskList(accessToken);
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);
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(queryString, accountIndex, firstName) {
console.log(`========== Account ${accountIndex} | ${firstName.green} ==========`);
const result = await this.callBinanceAPI(queryString);
if (!result) return;
const { userInfo, accessToken } = result;
const totalGrade = userInfo.metaInfo.totalGrade;
let totalAttempts = userInfo.metaInfo.totalAttempts;
let consumedAttempts = userInfo.metaInfo.consumedAttempts;
let availableTickets = totalAttempts-consumedAttempts;
this.log(`Total points: ${totalGrade}`);
this.log(`Available tickets: ${availableTickets}`);
await this.completeTasks(accessToken)
while (availableTickets > 0) {
this.log(`Starting game with ${availableTickets} available tickets`, 'info');
if (await this.startGame(accessToken)) {
if (await this.gameData()) {
await this.countdown(50);
if (await this.completeGame(accessToken)) {
availableTickets--;
this.log(`Remaining tickets: ${availableTickets}`, 'info');
} else {
break;
}
} else {
this.log("Cannot retrieve game data", 'error');
break;
}
} else {
this.log("Cannot start the game", 'error');
break;
}
if (availableTickets > 0) {
await new Promise(resolve => setTimeout(resolve, 3000));
}
}
if (availableTickets === 0) {
this.log("All tickets used up", 'success');
}
}
async main() {
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);
const dataFile = path.join(__dirname, 'data.txt');
const data = fs.readFileSync(dataFile, 'utf8')
.replace(/\r/g, '')
.split('\n')
.filter(Boolean);
while (true) {
for (let i = 0; i < data.length; i++) {
const queryString = data[i];
const userData = JSON.parse(decodeURIComponent(queryString.split('user=')[1].split('&')[0]));
const firstName = userData.first_name;
await this.playGameIfTicketsAvailable(queryString, i + 1, firstName);
await new Promise(resolve => setTimeout(resolve, 1000));
}
const randomCountdown = Math.floor(Math.random() * (1800 - 300 + 1)) + 300; // Between 5m and 30m
await this.countdown(randomCountdown);
}
}
}
const client = new Binance();
client.main().catch(err => {
client.log(err.message, 'error');
process.exit(1);
});