-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
383 lines (339 loc) · 12.1 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
const fs = require("fs").promises;
const path = require("path");
const axios = require("axios");
const colors = require("colors");
const readline = require("readline");
const { DateTime } = require("luxon");
const TelegramBot = require('node-telegram-bot-api');
const stripAnsi = (str) => {
// Regular expression to match ANSI color codes
const ansiRegex = /\x1b\[.*?m/g;
return str.replace(ansiRegex, '');
};
class Fintopio {
constructor() {
this.baseUrl = "https://fintopio-tg.fintopio.com/api";
this.headers = {
Accept: "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
Referer: "https://fintopio-tg.fintopio.com/",
"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":
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Mobile Safari/537.36",
};
// Initialize Telegram Bot
this.telegramBotToken = '12345678:gantikodemu'; // Replace with your Telegram bot token
this.telegramChatId = '1122334455'; // Replace with your Telegram chat ID
this.bot = new TelegramBot(this.telegramBotToken, { polling: true });
}
async log(msg, color = "white") {
const coloredMsg = msg[color];
console.log(coloredMsg);
await this.logToFile(coloredMsg);
await this.sendLogToTelegram(coloredMsg);
}
async logToFile(msg) {
const logFile = path.join(__dirname, "logfile.log");
const timestamp = DateTime.now().toISO();
const logMessage = `[${timestamp}] ${msg}\n`;
await fs.appendFile(logFile, logMessage);
}
async sendLogToTelegram(msg) {
try {
const cleanedMsg = stripAnsi(msg); // Remove ANSI color codes
await this.bot.sendMessage(this.telegramChatId, cleanedMsg);
} catch (error) {
console.error(`Failed to send log to Telegram: ${error.message}`);
}
}
async waitWithCountdown(seconds, msg = 'continue') {
const spinners = ["|", "/", "-", "\\"];
let i = 0;
for (let s = seconds; s >= 0; s--) {
readline.cursorTo(process.stdout, 0);
process.stdout.write(
`${spinners[i]} Waiting ${s} seconds to ${msg} ${spinners[i]}`.cyan
);
i = (i + 1) % spinners.length;
await new Promise((resolve) => setTimeout(resolve, 1000));
}
console.log("");
}
async auth(userData) {
const url = `${this.baseUrl}/auth/telegram`;
const headers = { ...this.headers, Webapp: "true" };
try {
const response = await axios.get(`${url}?${userData}`, { headers });
return response.data.token;
} catch (error) {
await this.log(`Authentication error: ${error.message}`, "red");
return null;
}
}
async getProfile(token) {
const url = `${this.baseUrl}/referrals/data`;
const headers = {
...this.headers,
Authorization: `Bearer ${token}`,
Webapp: "false, true",
};
try {
const response = await axios.get(url, { headers });
return response.data;
} catch (error) {
await this.log(`Error fetching profile: ${error.message}`, "red");
return null;
}
}
async checkInDaily(token) {
const url = `${this.baseUrl}/daily-checkins`;
const headers = {
...this.headers,
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
};
try {
await axios.post(url, {}, { headers });
await this.log("Daily check-in successful!", "green");
} catch (error) {
await this.log(`Daily check-in error: ${error.message}`, "red");
}
}
async getFarmingState(token) {
const url = `${this.baseUrl}/farming/state`;
const headers = {
...this.headers,
Authorization: `Bearer ${token}`,
};
try {
const response = await axios.get(url, { headers });
return response.data;
} catch (error) {
await this.log(`Error fetching farming state: ${error.message}`, "red");
return null;
}
}
async startFarming(token) {
const url = `${this.baseUrl}/farming/farm`;
const headers = {
...this.headers,
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
};
try {
const response = await axios.post(url, {}, { headers });
const finishTimestamp = response.data.timings.finish;
if (finishTimestamp) {
const finishTime = DateTime.fromMillis(finishTimestamp).toLocaleString(
DateTime.DATETIME_FULL
);
await this.log(`Starting farm...`, "yellow");
await this.log(`Farming completion time: ${finishTime}`, "green");
} else {
await this.log("No completion time available.", "yellow");
}
} catch (error) {
await this.log(`Error starting farming: ${error.message}`, "red");
}
}
async claimFarming(token) {
const url = `${this.baseUrl}/farming/claim`;
const headers = {
...this.headers,
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
};
try {
await axios.post(url, {}, { headers });
await this.log("Farm claimed successfully!", "green");
} catch (error) {
await this.log(`Error claiming farm: ${error.message}`, "red");
}
}
async getDiamondInfo(token){
const url = `${this.baseUrl}/clicker/diamond/state`;
const headers = {
...this.headers,
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
};
try {
const response = await axios.get(url, { headers });
return response.data;
} catch (error) {
await this.log(`Error fetching diamond state: ${error.message}`, "red");
return null;
}
}
async claimDiamond(token, diamondNumber, totalReward) {
const url = `${this.baseUrl}/clicker/diamond/complete`;
const headers = {
...this.headers,
Authorization: `Bearer ${token}`,
"Content-Type": "application/json"
};
const payload = { "diamondNumber": diamondNumber };
try {
await axios.post(url, payload, { headers });
await this.log(`Success claim ${totalReward} diamonds!`, "green");
} catch (error) {
await this.log(`Error claiming Diamond: ${error.message}`, "red");
}
}
async getTask(token) {
const url = `${this.baseUrl}/hold/tasks`;
const headers = {
...this.headers,
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
};
try {
const response = await axios.get(url, { headers });
return response.data;
} catch (error) {
await this.log(`Error fetching task state: ${error.message}`, "red");
return null;
}
}
async startTask(token, taskId, slug) {
const url = `${this.baseUrl}/hold/tasks/${taskId}/start`;
const headers = {
...this.headers,
Authorization: `Bearer ${token}`,
"Content-Type": "application/json; charset=utf-8",
"origin": "https://fintopio-tg.fintopio.com"
};
try {
await axios.post(url, {}, { headers });
await this.log(`Starting task ${slug}!`, "green");
} catch (error) {
await this.log(`Error starting task: ${error.message}`, "red");
}
}
async claimTask(token, taskId, slug, rewardAmount) {
const url = `${this.baseUrl}/hold/tasks/${taskId}/claim`;
const headers = {
...this.headers,
Authorization: `Bearer ${token}`,
"Content-Type": "application/json; charset=utf-8",
"origin": "https://fintopio-tg.fintopio.com"
};
try {
await axios.post(url, {}, { headers });
await this.log(`Task ${slug} complete, reward ${rewardAmount} diamonds!`, "green");
} catch (error) {
await this.log(`Error claiming task: ${error.message}`, "red");
}
}
extractFirstName(userData) {
try {
const userPart = userData.match(/user=([^&]*)/)[1];
const decodedUserPart = decodeURIComponent(userPart);
const userObj = JSON.parse(decodedUserPart);
return userObj.first_name || "Unknown";
} catch (error) {
this.log(`Error extracting first_name: ${error.message}`, "red");
return "Unknown";
}
}
calculateWaitTime(firstAccountFinishTime) {
if (!firstAccountFinishTime) return null;
const now = DateTime.now();
const finishTime = DateTime.fromMillis(firstAccountFinishTime);
const duration = finishTime.diff(now);
return duration.as("milliseconds");
}
async main() {
while (true) {
const dataFile = path.join(__dirname, "data.txt");
const data = await fs.readFile(dataFile, "utf8");
const users = data.split("\n").filter(Boolean);
let firstAccountFinishTime = null;
for (let i = 0; i < users.length; i++) {
const userData = users[i];
const first_name = this.extractFirstName(userData);
await this.log(
`${"=".repeat(5)} Account ${i + 1} | ${first_name.green} ${"=".repeat(
5
)}`.blue
);
const token = await this.auth(userData);
if (token) {
await this.log(`Login successful!`, "green");
const profile = await this.getProfile(token);
if (profile) {
const balance = profile.balance;
await this.log(`Balance: ${balance}`, "green");
await this.checkInDaily(token);
const diamond = await this.getDiamondInfo(token);
if(diamond.state === 'available') {
await this.waitWithCountdown(Math.floor(Math.random() * (21 - 10)) + 10, 'claim Diamonds');
await this.claimDiamond(token, diamond.diamondNumber, diamond.settings.totalReward);
} else {
const nextDiamondTimeStamp = diamond.timings.nextAt;
if(nextDiamondTimeStamp) {
const nextDiamondTime = DateTime.fromMillis(nextDiamondTimeStamp).toLocaleString(DateTime.DATETIME_FULL);
await this.log(`Next Diamond time: ${nextDiamondTime}`, 'green');
if (i === 0) {
firstAccountFinishTime = nextDiamondTimeStamp;
}
}
}
const farmingState = await this.getFarmingState(token);
if (farmingState) {
if (farmingState.state === "idling") {
await this.startFarming(token);
} else if (
farmingState.state === "farmed" ||
farmingState.state === "farming"
) {
const finishTimestamp = farmingState.timings.finish;
if (finishTimestamp) {
const finishTime = DateTime.fromMillis(finishTimestamp).toLocaleString(DateTime.DATETIME_FULL);
await this.log(`Farming completion time: ${finishTime}`, "green");
const currentTime = DateTime.now().toMillis();
if (currentTime > finishTimestamp) {
await this.claimFarming(token);
await this.startFarming(token);
}
}
}
}
const taskState = await this.getTask(token);
if(taskState) {
for (const item of taskState.tasks) {
if(item.status === 'available') {
await this.startTask(token, item.id, item.slug);
} else if(item.status === 'verified') {
await this.claimTask(token, item.id, item.slug, item.rewardAmount);
} else if(item.status === 'in-progress') {
continue;
} else {
await this.log(`Verifying task ${item.slug}!`, "green");
}
}
}
}
}
}
const waitTime = this.calculateWaitTime(firstAccountFinishTime);
if (waitTime && waitTime > 0) {
await this.waitWithCountdown(Math.floor(waitTime / 1000));
} else {
await this.log("No valid wait time, continuing loop immediately.", "yellow");
await this.waitWithCountdown(5);
}
}
}
}
if (require.main === module) {
const fintopio = new Fintopio();
fintopio.main().catch((err) => {
console.error(err);
process.exit(1);
});
}