-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
404 lines (370 loc) · 12.5 KB
/
main.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
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
const fs = require("fs");
const path = require("path");
const axios = require("axios");
const { DateTime } = require("luxon");
const colors = require("colors");
const readline = require("readline");
const winston = require("winston");
// Configure Winston logger with improved formatting
const logger = winston.createLogger({
level: "info",
format: winston.format.combine(
winston.format.timestamp({
format: "YYYY-MM-DD HH:mm:ss.SSS",
}),
winston.format.printf(({ timestamp, level, message }) => {
const levelUpper = level.toUpperCase().padEnd(5);
let coloredLevel;
switch (level) {
case "info":
coloredLevel = colors.green(levelUpper);
break;
case "warn":
coloredLevel = colors.yellow(levelUpper);
break;
case "error":
coloredLevel = colors.red(levelUpper);
break;
default:
coloredLevel = colors.white(levelUpper);
}
return `${colors.gray(timestamp)} ${coloredLevel}: ${message}`;
})
),
transports: [new winston.transports.Console()],
});
class Nomis {
constructor() {
this.currentAppInitData = "";
}
headers() {
return {
"Content-Type": "application/json",
Accept: "application/json, text/plain, */*",
"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",
Authorization:
"Bearer 8e25d2673c5025dfcd36556e7ae1b330095f681165fe964181b13430ddeb385a0844815b104eff05f44920b07c073c41ff19b7d95e487a34aa9f109cab754303cd994286af4bd9f6fbb945204d2509d4420e3486a363f61685c279ae5b77562856d3eb947e5da44459089b403eb5c80ea6d544c5aa99d4221b7ae61b5b4cbb55",
Origin: "https://telegram.nomis.cc",
Referer: "https://telegram.nomis.cc/",
"Sec-Ch-Ua":
'"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
"Sec-Ch-Ua-Mobile": "?1",
"Sec-Ch-Ua-Platform": '"Android"',
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-site",
"User-Agent":
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36",
"X-App-Init-Data": this.currentAppInitData,
};
}
async request(config) {
return axios(config);
}
async auth(telegram_user_id, telegram_username, referrer) {
const url = "https://cms-tg.nomis.cc/api/ton-twa-users/auth/";
const headers = this.headers();
const payload = {
telegram_user_id,
telegram_username,
referrer,
};
const config = {
url,
method: "post",
headers,
data: payload,
};
return this.request(config);
}
async getProfile(id) {
const url = `https://cms-api.nomis.cc/api/users/farm-data?user_id=${id}`;
const headers = this.headers(false);
const config = {
url,
method: "get",
headers,
};
return this.request(config);
}
async getTask(id) {
const url = `https://cms-tg.nomis.cc/api/ton-twa-tasks/by-groups?user_id=${id}`;
const headers = this.headers();
logger.info(colors.blue("Checking task list"));
const config = {
url,
method: "get",
headers,
};
return this.request(config);
}
async kiemtraTask(id) {
const url = `https://cms-tg.nomis.cc/api/ton-twa-tasks/by-groups?user_id=${id}&completed=true`;
const headers = this.headers();
const config = {
url,
method: "get",
headers,
};
return this.request(config);
}
async claimTask(user_id, task_id) {
const url = `https://cms-tg.nomis.cc/api/ton-twa-user-tasks/verify`;
const headers = this.headers();
const payload = {
task_id,
user_id,
};
const config = {
url,
method: "post",
headers,
data: payload,
};
return this.request(config);
}
async claimFarm(user_id) {
const url = `https://cms-tg.nomis.cc/api/ton-twa-users/claim-farm`;
const headers = this.headers();
const payload = { user_id };
const config = {
url,
method: "post",
headers,
data: payload,
};
return this.request(config);
}
async startFarm(user_id) {
const url = `https://cms-tg.nomis.cc/api/ton-twa-users/start-farm`;
const headers = this.headers();
const payload = { user_id };
const config = {
url,
method: "post",
headers,
data: payload,
};
return this.request(config);
}
async getReferralData(user_id) {
const url = `https://cms-api.nomis.cc/api/users/referrals-data?user_id=${user_id}`;
const headers = this.headers();
const config = {
url,
method: "get",
headers,
};
return this.request(config);
}
async claimReferral(user_id) {
const url = `https://cms-tg.nomis.cc/api/ton-twa-users/claim-referral`;
const headers = this.headers();
const payload = { user_id };
const config = {
url,
method: "post",
headers,
data: payload,
};
return this.request(config);
}
async waitWithCountdown(seconds) {
const formatTime = (totalSeconds) => {
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
return `${hours.toString().padStart(2, "0")}:${minutes
.toString()
.padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
};
for (let i = seconds; i >= 0; i--) {
readline.cursorTo(process.stdout, 0);
readline.clearLine(process.stdout, 0);
if (i > 0) {
process.stdout.write(
colors.cyan(
`Completed all accounts, waiting ${formatTime(
i
)} to continue the loop`
)
);
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
console.log(colors.green("\nResuming operations..."));
}
async main() {
const dataFile = path.join(__dirname, "data.txt");
const data = fs
.readFileSync(dataFile, "utf8")
.replace(/\r/g, "")
.split("\n")
.filter(Boolean);
let firstFarmCompleteTime = null;
while (true) {
for (let no = 0; no < data.length; no++) {
const appInitData = data[no];
this.currentAppInitData = appInitData;
const userMatch = appInitData.match(
/user=%7B%22id%22%3A(\d+).*?%22username%22%3A%22(.*?)%22/
);
if (!userMatch) {
logger.error(`Invalid app init data for entry ${no + 1}`);
continue;
}
const [, telegram_user_id, telegram_username] = userMatch;
const referrer = "Lndkhu-VNo";
try {
const authResponse = await this.auth(
telegram_user_id,
telegram_username,
referrer
);
const profileData = authResponse.data;
if (profileData && profileData.id) {
const userId = profileData.id;
logger.info(
colors.cyan(`Account ${no + 1} | ${telegram_username}`)
);
const farmDataResponse = await this.getProfile(userId);
const farmData = farmDataResponse.data;
const points = farmData.points / 1000;
const nextfarm = farmData.nextFarmClaimAt;
logger.info(`Balance: ${colors.yellow(points)}`);
let claimFarmSuccess = false;
if (nextfarm) {
const nextFarmLocal = DateTime.fromISO(nextfarm, {
zone: "utc",
}).setZone(DateTime.local().zoneName);
logger.info(
`Farm completion time: ${colors.magenta(
nextFarmLocal.toLocaleString(DateTime.DATETIME_FULL)
)}`
);
if (no === 0) {
firstFarmCompleteTime = nextFarmLocal;
}
const now = DateTime.local();
if (now > nextFarmLocal) {
try {
await this.claimFarm(userId);
logger.info(colors.green("Farm claim successful!"));
claimFarmSuccess = true;
} catch (claimError) {
logger.error(claimError);
logger.error(colors.red("Error when claiming farm!"));
}
}
} else {
claimFarmSuccess = true;
}
if (claimFarmSuccess) {
try {
await this.startFarm(userId);
logger.info(colors.green("Farm start successful!"));
} catch (startError) {
logger.error(colors.red("Error when starting farm!"));
}
}
try {
const getTaskResponse = await this.getTask(userId);
const tasks = getTaskResponse.data;
const kiemtraTaskResponse = await this.kiemtraTask(userId);
const completedTasks = kiemtraTaskResponse.data.flatMap(
(taskGroup) => taskGroup.ton_twa_tasks
);
const completedTaskIds = new Set(
completedTasks.map((task) => task.id)
);
const pendingTasks = tasks
.flatMap((taskGroup) => taskGroup.ton_twa_tasks)
.filter(
(task) =>
task.reward > 0 &&
!completedTaskIds.has(task.id) &&
!["telegramAuth", "pumpersToken", "pumpersTrade"].includes(
task.handler
)
);
for (const task of pendingTasks) {
const result = await this.claimTask(userId, task.id);
logger.info(
`Doing task ${colors.cyan(
task.title
)} | Status: ${colors.green("Completed")}`
);
}
} catch (taskError) {
logger.error(colors.red("Error when doing task"));
logger.error(taskError);
}
try {
const referralDataResponse = await this.getReferralData(userId);
const referralData = referralDataResponse.data;
if (referralData && referralData.claimAvailable > 0) {
if (referralData.nextReferralsClaimAt) {
const nextReferralsClaimLocal = DateTime.fromISO(
referralData.nextReferralsClaimAt,
{ zone: "utc" }
).setZone(DateTime.local().zoneName);
logger.info(
`Next referrals claim time: ${colors.magenta(
nextReferralsClaimLocal.toLocaleString(
DateTime.DATETIME_FULL
)
)}`
);
const now = DateTime.local();
if (now > nextReferralsClaimLocal) {
const claimResponse = await this.claimReferral(userId);
if (claimResponse.data.result) {
logger.info(colors.green("Referrals claim successful!"));
} else {
logger.error(colors.red("Referrals claim failed!"));
}
}
} else {
logger.info(colors.yellow("Performing claim"));
const claimResponse = await this.claimReferral(userId);
if (claimResponse.data.result) {
logger.info(colors.green("Referrals claim successful!"));
} else {
logger.error(colors.red("Referrals claim failed!"));
}
}
} else {
logger.warn(colors.yellow("No available referrals to claim"));
}
} catch (error) {
logger.error(colors.red("Error when processing referrals"));
logger.error(error);
}
} else {
logger.error(colors.red("Error: User ID not found"));
}
} catch (error) {
logger.error(colors.red("Error when processing account"));
logger.error(error);
}
}
let waitTime;
if (firstFarmCompleteTime) {
const now = DateTime.local();
const diff = firstFarmCompleteTime.diff(now, "seconds").seconds;
waitTime = Math.max(0, Math.ceil(diff));
} else {
waitTime = 15 * 60;
}
await this.waitWithCountdown(waitTime);
}
}
}
if (require.main === module) {
const dancay = new Nomis();
dancay.main().catch((err) => {
logger.error(err);
process.exit(1);
});
}