This repository was archived by the owner on May 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
184 lines (161 loc) · 6.11 KB
/
Copy pathmain.js
File metadata and controls
184 lines (161 loc) · 6.11 KB
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
const axios = require("axios");
const fs = require("fs");
const readline = require("readline");
const querystring = require("querystring");
const BASE_URL = "https://tonclayton.fun";
async function readFromFile(filePath) {
const fileStream = fs.createReadStream(filePath);
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity,
});
const items = [];
for await (const line of rl) {
if (line.trim()) {
items.push(line.trim());
}
}
return items;
}
function createApiClient(initData, proxy) {
const axiosConfig = {
baseURL: BASE_URL,
headers: {
Host: "tonclayton.fun",
"Init-Data": initData,
Origin: BASE_URL,
Referer: `${BASE_URL}/games/game-512`,
},
};
if (proxy) {
const [protocol, proxyUrl] = proxy.split("://");
const [auth, hostPort] = proxyUrl.split("@");
const [username, password] = auth.split(":");
const [host, port] = hostPort.split(":");
axiosConfig.proxy = {
protocol,
host,
port,
auth: {
username,
password,
},
};
}
return axios.create(axiosConfig);
}
function log(message, color = "white") {
const colors = {
red: "\x1b[31m",
green: "\x1b[32m",
yellow: "\x1b[33m",
blue: "\x1b[34m",
magenta: "\x1b[35m",
cyan: "\x1b[36m",
white: "\x1b[37m",
};
console.log(colors[color] + message + "\x1b[0m");
}
async function safeRequest(api, method, url, data) {
try {
const response = await api[method](url, data);
return response.data;
} catch (error) {
log(`Request failed: ${error.message}`, "red");
throw error;
}
}
const apiFunctions = {
login: (api) => safeRequest(api, 'post', "/api/user/login", {}),
claimDailyReward: (api) => safeRequest(api, 'post', "/api/user/daily-claim", {}),
claimTokens: (api) => safeRequest(api, 'post', "/api/user/claim", {}),
startFarming: (api) => safeRequest(api, 'post', "/api/user/start", {}),
getDailyTasks: (api) => safeRequest(api, 'post', "/api/user/daily-tasks", {}),
completeTask: (api, taskId) => safeRequest(api, 'post', `/api/user/daily-task/${taskId}/complete`, {}),
claimTaskReward: (api, taskId) => safeRequest(api, 'post', `/api/user/daily-task/${taskId}/claim`, {}),
playGame: async (api, gameName) => {
await safeRequest(api, 'post', "/api/game/start", {});
await simulateGameplay(gameName);
await safeRequest(api, 'post', "/api/game/save-tile", { maxTile: 1024 });
log(`${gameName} tile saved: 1024`, "cyan");
return await safeRequest(api, 'post', "/api/game/over", {});
}
};
async function simulateGameplay(gameName) {
const duration = Math.floor(Math.random() * 31) + 30;
for (let i = 0; i <= duration; i++) {
process.stdout.write(
`\r\x1b[36m${gameName} game in progress: ${i}s / ${duration}s [${"=".repeat(i)}${" ".repeat(
duration - i
)}]\x1b[0m`
);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
console.log();
}
async function processAccount(initData, firstName, proxy) {
try {
const api = createApiClient(initData, proxy);
let loginData = await apiFunctions.login(api);
log("Logged in successfully", "green");
if (loginData.dailyReward?.can_claim_today) {
await apiFunctions.claimDailyReward(api);
log("Daily reward claimed", "yellow");
} else {
log("Daily reward not available", "yellow");
}
if (loginData.user.can_claim) {
await apiFunctions.claimTokens(api);
log("Tokens claimed", "magenta");
await apiFunctions.startFarming(api);
log("Farming started", "blue");
} else {
log("Token claim not available", "magenta");
}
const dailyAttempts = loginData.user.daily_attempts;
log(`Available game attempts: ${dailyAttempts}`, "cyan");
for (let i = 1; i <= dailyAttempts; i++) {
const gameResult = await apiFunctions.playGame(api, "1024");
log(`1024 game ${i} result:`, "green");
console.log(gameResult);
}
log("Fetching daily tasks...", "cyan");
let tasks = await apiFunctions.getDailyTasks(api);
for (const task of tasks) {
if (!task.is_completed && !task.is_reward) {
log(`Completing task: ${task.task_type} (ID: ${task.id})`, "yellow");
const completeResult = await apiFunctions.completeTask(api, task.id);
log(completeResult.message, "green");
} else {
log(`Task already completed: ${task.task_type} (ID: ${task.id})`, "yellow");
}
}
tasks = await apiFunctions.getDailyTasks(api);
for (const task of tasks) {
if (task.is_completed && !task.is_reward) {
log(`Claiming reward for task: ${task.task_type} (ID: ${task.id})`, "yellow");
const claimResult = await apiFunctions.claimTaskReward(api, task.id);
log(claimResult.message, "green");
console.log(`Reward received: ${claimResult.reward}`);
}
}
log("All tasks completed", "green");
} catch (error) {
log(`Error occurred for ${firstName}: ${error.message}`, "red");
}
}
async function main() {
const tokens = await readFromFile("data.txt");
const proxies = await readFromFile("proxy.txt");
for (let i = 0; i < tokens.length; i++) {
const initData = tokens[i];
const proxy = proxies[i] || null;
const parsed = querystring.parse(initData);
const userDecoded = decodeURIComponent(parsed.user);
const userObject = JSON.parse(userDecoded);
const firstName = userObject?.first_name;
log(`Processing account: ${firstName} ${proxy ? `using proxy ${proxy}` : ""}`, "cyan");
await processAccount(initData, firstName, proxy);
}
}
main();