This repository was archived by the owner on Aug 4, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
194 lines (163 loc) · 7.46 KB
/
index.js
File metadata and controls
194 lines (163 loc) · 7.46 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
185
186
187
188
189
190
191
192
193
194
const fs = require("fs");
const axios = require("axios");
const https = require("https");
const config = require("./config.json");
const UserAgentManager = require("./utils/userAgentManager");
const { getWalletInfo } = require("./utils/walletManager");
const { logWithColor } = require("./utils/logger");
const { getProxyAgent } = require("./utils/proxyManager");
const { handleTasks } = require("./utils/taskManager");
const { generateHeaders } = require("./utils/headerManager");
const userAgentManager = new UserAgentManager();
const wallets = JSON.parse(fs.readFileSync("./wallets.json", "utf8"));
const proxies = fs
.readFileSync("./proxy.txt", "utf8")
.split("\n")
.filter((proxy) => proxy.trim() !== "");
async function handlePing(wallet, registrationResult, proxy) {
const walletId = wallet.id;
let pingCount = 0;
const userAgent =
userAgentManager.getUserAgent(wallet.address) ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36";
if (!registrationResult.success) {
logWithColor(walletId, `Skipping ping operations due to registration failure`, "warning");
return;
}
const { pointId, walletId: meganetWalletId } = registrationResult;
logWithColor(walletId, `Starting ping operations. Point ID: ${pointId}`, "ping");
const pingInterval = setInterval(async () => {
try {
pingCount++;
const pingConfig = {
method: "get",
url: `https://api.meganet.app/points/point-today/${pointId}`,
headers: generateHeaders(userAgent),
timeout: 30000,
};
if (proxy) {
const httpsAgent = getProxyAgent(proxy, walletId);
if (httpsAgent) {
pingConfig.httpsAgent = httpsAgent;
pingConfig.httpAgent = false;
pingConfig.protocol = "https:";
}
} else {
pingConfig.httpsAgent = new https.Agent({ rejectUnauthorized: false });
}
logWithColor(walletId, `Sending ping request`, "ping");
const pingResponse = await axios(pingConfig);
if (pingResponse.status === 200) {
logWithColor(walletId, `Ping successful! Points today: ${pingResponse.data.pointsFarmToday}`, "ping");
if (pingCount % 10 === 0) {
const uptimeConfig = {
method: "patch",
url: `https://api.meganet.app/wallets/uptime/${meganetWalletId}`,
headers: generateHeaders(userAgent),
timeout: 30000,
};
if (proxy) {
const httpsAgent = getProxyAgent(proxy, walletId);
if (httpsAgent) {
uptimeConfig.httpsAgent = httpsAgent;
uptimeConfig.httpAgent = false;
uptimeConfig.protocol = "https:";
}
} else {
uptimeConfig.httpsAgent = new https.Agent({ rejectUnauthorized: false });
}
logWithColor(walletId, `Sending uptime update request`, "info");
const uptimeResponse = await axios(uptimeConfig);
if (uptimeResponse.status === 200) {
logWithColor(walletId, `Uptime update successful!`, "success");
} else {
logWithColor(walletId, `Uptime update failed: ${uptimeResponse.status}`, "error");
}
}
} else {
logWithColor(walletId, `Ping failed: ${pingResponse.status}`, "error");
}
} catch (error) {
if (error.response) {
logWithColor(walletId, `Ping error: ${error.message}`, "error");
logWithColor(walletId, `Response status: ${error.response.status}`, "error");
logWithColor(walletId, `Response data: ${JSON.stringify(error.response.data)}`, "error");
} else if (error.request) {
logWithColor(walletId, `Ping error: No response received`, "error");
} else {
logWithColor(walletId, `Ping error: ${error.message}`, "error");
}
}
}, config.pingInterval || 15000);
}
async function processWalletTasks(wallet, registrationResult, proxy) {
const walletId = wallet.id;
const userAgent =
userAgentManager.getUserAgent(wallet.address) ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36";
if (!registrationResult.success) {
logWithColor(walletId, `Missing task processing due to a registration error`, "warning");
return;
}
const { walletId: meganetWalletId } = registrationResult;
logWithColor(walletId, `Start processing tasks`, "info");
const options = {
userAgent,
proxy,
proxyManager: getProxyAgent,
walletDisplayId: walletId,
};
try {
const tasksResult = await handleTasks(meganetWalletId, options);
if (tasksResult.success) {
logWithColor(
walletId,
`Task processing completed. Completed: ${tasksResult.totalCompleted}, Errors: ${tasksResult.totalFailed}`,
"success"
);
if (tasksResult.completedTasks.length > 0) {
logWithColor(walletId, `Completed tasks: ${tasksResult.completedTasks.join(", ")}`, "success");
}
if (tasksResult.failedTasks.length > 0) {
logWithColor(
walletId,
`Failed tasks: ${tasksResult.failedTasks.map((t) => t.taskName).join(", ")}`,
"warning"
);
}
} else {
logWithColor(walletId, `Task processing error: ${tasksResult.error}`, "error");
}
} catch (error) {
logWithColor(walletId, `Task processing error: ${error.message}`, "error");
}
}
async function main() {
logWithColor("SYSTEM", `Starting Meganet bot for ${wallets.length} wallets...`, "info");
logWithColor("SYSTEM", `Use proxy: ${config.useProxy ? "Yes" : "No"}`, "info");
const getRandomDelay = () => Math.floor(Math.random() * 5000) + 2000;
for (const wallet of wallets) {
setTimeout(async () => {
const proxyIndex = wallet.id - 1;
const proxy = config.useProxy && proxyIndex < proxies.length ? proxies[proxyIndex] : null;
const userAgent =
userAgentManager.getUserAgent(wallet.address) ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36";
const options = {
getProxyAgent,
logWithColor,
userAgent,
refCode: config.refCode,
isRegistrationNeeded: false,
};
let walletResult = await getWalletInfo(wallet, proxy, options);
if (config.processTasks !== false) {
await processWalletTasks(wallet, walletResult, proxy);
}
handlePing(wallet, walletResult, proxy);
}, getRandomDelay());
}
}
main().catch((error) => {
console.error(`${colors.red}FATAL ERROR:${colors.reset} ${error.message}`);
});