Skip to content

Commit c371b3b

Browse files
authored
main.js
fixed some err func
1 parent f1fde87 commit c371b3b

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

main.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,47 @@ const fs = require('fs');
33
const crypto = require('crypto');
44
const { SocksProxyAgent } = require('socks-proxy-agent');
55
const { v4: uuidv4, v3: uuidv3 } = require('uuid');
6-
const logger = require('pino')();
6+
const pino = require('pino');
7+
const logger = pino({ level: 'info', transport: { target: 'pino-pretty' } });
78
const config = require('./configuration');
89

10+
let CoderMarkPrinted = false;
11+
12+
const cl = {
13+
gr: '\x1b[32m',
14+
br: '\x1b[34m',
15+
red: '\x1b[31m',
16+
yl: '\x1b[33m',
17+
gb: '\x1b[4m',
18+
rt: '\x1b[0m'
19+
};
20+
21+
function CoderMark() {
22+
if (!CoderMarkPrinted) {
23+
console.log(`
24+
╭━━━╮╱╱╱╱╱╱╱╱╱╱╱╱╱╭━━━┳╮
25+
┃╭━━╯╱╱╱╱╱╱╱╱╱╱╱╱╱┃╭━━┫┃${cl.gr}
26+
┃╰━━┳╮╭┳━┳━━┳━━┳━╮┃╰━━┫┃╭╮╱╭┳━╮╭━╮
27+
┃╭━━┫┃┃┃╭┫╭╮┃╭╮┃╭╮┫╭━━┫┃┃┃╱┃┃╭╮┫╭╮╮${cl.br}
28+
┃┃╱╱┃╰╯┃┃┃╰╯┃╰╯┃┃┃┃┃╱╱┃╰┫╰━╯┃┃┃┃┃┃┃
29+
╰╯╱╱╰━━┻╯╰━╮┣━━┻╯╰┻╯╱╱╰━┻━╮╭┻╯╰┻╯╰╯${cl.rt}
30+
╱╱╱╱╱╱╱╱╱╱╱┃┃╱╱╱╱╱╱╱╱╱╱╱╭━╯┃
31+
╱╱╱╱╱╱╱╱╱╱╱╰╯╱╱╱╱╱╱╱╱╱╱╱╰━━╯
32+
\n${cl.gb}${cl.yl}getGrass Minner Bot ${cl.rt}${cl.gb}v0.2${cl.rt}
33+
`);
34+
CoderMarkPrinted = true;
35+
}
36+
}
37+
938
async function connectToWss(socks5Proxy, userId) {
1039
const deviceId = uuidv3(socks5Proxy, uuidv3.DNS);
1140
logger.info(deviceId);
1241
while (true) {
1342
try {
1443
await new Promise(resolve => setTimeout(resolve, Math.random() * 900 + 100));
15-
const customHeaders = {
16-
"User-Agent": config["User-Agent"]
17-
};
18-
const uri = "wss://proxy2.wynd.network:4444/";
44+
const customHeaders = { "User-Agent": config.UserAgent };
45+
const uriList = ["wss://proxy2.wynd.network:4444/", "wss://proxy2.wynd.network:4650/"];
46+
const uri = uriList[Math.floor(Math.random() * uriList.length)];
1947
const agent = new SocksProxyAgent(socks5Proxy);
2048
const ws = new WebSocket(uri, {
2149
agent: agent,
@@ -25,15 +53,9 @@ async function connectToWss(socks5Proxy, userId) {
2553
},
2654
rejectUnauthorized: false
2755
});
28-
2956
ws.on('open', () => {
3057
const sendPing = () => {
31-
const sendMessage = JSON.stringify({
32-
id: uuidv4(),
33-
version: "1.0.0",
34-
action: "PING",
35-
data: {}
36-
});
58+
const sendMessage = JSON.stringify({ id: uuidv4(), version: "1.0.0", action: "PING", data: {} });
3759
logger.debug(sendMessage);
3860
ws.send(sendMessage);
3961
setTimeout(sendPing, 110000);
@@ -68,12 +90,8 @@ async function connectToWss(socks5Proxy, userId) {
6890
});
6991

7092
await new Promise((resolve, reject) => {
71-
ws.on('close', () => {
72-
reject(new Error('WebSocket closed'));
73-
});
74-
ws.on('error', (error) => {
75-
reject(error);
76-
});
93+
ws.on('close', () => reject(new Error('WebSocket closed')));
94+
ws.on('error', (error) => reject(error));
7795
});
7896
} catch (e) {
7997
logger.error(`Error with proxy ${socks5Proxy}: ${e.message}`);
@@ -90,7 +108,6 @@ async function main() {
90108
const proxyFile = config.proxyFile;
91109
const userId = config.userId;
92110
const allProxies = fs.readFileSync(proxyFile, 'utf-8').split('\n').filter(Boolean);
93-
94111
let activeProxies = allProxies.sort(() => 0.5 - Math.random()).slice(0, 100);
95112
let tasks = new Map(activeProxies.map(proxy => [connectToWss(proxy, userId), proxy]));
96113

@@ -121,5 +138,5 @@ function removeProxyFromList(proxy) {
121138
const updatedList = proxyList.filter(line => line.trim() !== proxy);
122139
fs.writeFileSync(proxyFile, updatedList.join('\n'));
123140
}
124-
141+
CoderMark();
125142
main().catch(console.error);

0 commit comments

Comments
 (0)