forked from Zlkcyber/kaisar-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.js
76 lines (66 loc) · 2.17 KB
/
setup.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
import axios from 'axios';
import crypto from 'crypto';
import fs from 'fs';
function generateUUID() {
return crypto.randomUUID();
}
function getTokensFromFile() {
try {
const tokens = fs.readFileSync('tokens.txt', 'utf-8').split('\n').filter(token => token.trim() !== '');
return tokens;
} catch (error) {
console.error("Error reading tokens.txt:", error.message || error);
return [];
}
}
function saveUUIDToFile(uuid) {
try {
fs.appendFileSync('id.txt', uuid + '\n');
console.log('Extension ID saved to id.txt');
} catch (error) {
console.error("Error saving Extension ID to file:", error.message || error);
}
}
async function startFarmingWithToken(token) {
const extensionId = generateUUID();
const apiClient = axios.create({
baseURL: 'https://zero-api.kaisar.io/',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
});
let miningData = null;
async function startFarming() {
try {
console.log("Created", { extensionId }, "Trying to start farming");
const response = await apiClient.post('/mining/start', {
extension: extensionId
});
if (response.status === 200) {
console.log("Mining started successfully:");
saveUUIDToFile(extensionId);
}
} catch (error) {
if (error.response) {
const { status, data } = error.response;
console.error('Error starting mining (HTTP Error):', {
status,
});
if (status === 412) {
console.log("Mining already started with another ID.\nYou must put Manually your extension id in id.txt");
return;
}
} else {
console.error('Error starting mining try again later');
}
}
}
await startFarming();
}
(async () => {
const tokens = getTokensFromFile();
for (const token of tokens) {
await startFarmingWithToken(token);
}
})();