This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (43 loc) · 1.62 KB
/
index.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
const { spawn } = require("child_process");
const discord = require("discord-rpc");
const gminer = require("gminer.js");
const config = require("./config.js");
const clientId = "829648686706589737";
const startTimestamp = new Date();
const miner = spawn(config.minerPath, config.minerOptions);
let GPU;
miner.stdout.setEncoding("utf8");
miner.stderr.setEncoding("utf8");
miner.stdout.on("data", (data) => {
try {
data = data.toString();
if (config.showMinerLogs) console.log(data);
if (data.includes("Started Mining")) GPU = data.split("\r\n")[0].split("GPU0: ")[1].split("[")[0];
} catch (e) {
console.error(e);
}
});
miner.stderr.on("data", (data) => {
console.error(`error : ${data}`);
});
const GMinerAPI = new gminer.Client(config.minerOptions[config.minerOptions.indexOf("--api") + 1]);
const rpc = new discord.Client({ transport: "ipc" });
const discordPRC = async () => {
let data = await GMinerAPI.stats();
let hashrate = `${(data.devices[0].speed / 1000000).toFixed(2)} M${data.speed_unit}`;
let sharesCount = `${data.total_accepted_shares}/${data.total_rejected_shares}/${data.total_invalid_shares}`;
rpc.setActivity({
details: `${data.algorithm} : ${hashrate} - ${sharesCount} shares`,
state: `GPU: ${GPU ? GPU : data.devices[0].name}`,
startTimestamp,
largeImageKey: "gminer-logo",
largeImageText: data.miner,
});
};
rpc.on("connected", () => {
console.log("Connected to Discord!");
discordPRC();
setInterval(() => discordPRC(), 10000);
});
process.on("unhandledRejection", console.error);
rpc.login({ clientId });