-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
144 lines (123 loc) · 5.09 KB
/
index.ts
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
import { Client, WebhookClient, Partials, TextChannel } from "discord.js";
import { Vulkava } from "vulkava";
import si from "systeminformation";
import os from "os";
import config from "./config";
import moment from "moment";
import pretty from "prettysize";
import "moment-duration-format";
import { fetch } from "undici";
const client = new Client({
intents: [
"Guilds",
"GuildMessages",
"GuildMessageReactions",
"GuildMessageTyping",
"GuildVoiceStates",
]
})
async function main() {
await client.login(config.token);
const hook = new WebhookClient({ url: config.webhook });
const vulkava = new Vulkava({
nodes: config.nodes,
sendWS: (id, payload) => {
client.guilds.cache.get(id)?.shard.send(payload)
}
});
client.on('ready', async () => {
console.log("Bot is ready sir.");
vulkava.start(client.user.id);
let cl = await si.currentLoad();
setInterval(async () => {
let netdata = await si.networkStats();
let memdata = await si.mem();
let diskdata = await si.fsSize();
let osdata = await si.osInfo();
let cpudata = await si.cpu();
let uptime = os.uptime();
const res = await fetch('https://api.waifu.pics/sfw/neko');
const json = await res.json() as any;
let hookImage = json.url;
let embed = {
title: "Server Stats",
color: 0x2F3136,
timestamp: new Date().toISOString(),
thumbnail: {
url: hookImage
},
fields: [
{
name: "**Lavalink**", value: `\`\`\`nim\n${vulkava.nodes.map((node) =>
`Node : ${node.connect ? "🟢" : "🔴"} ${node.options.id}
Memory Usage : ${formatBytes(node.stats.memory.allocated)} - ${node.stats.cpu.lavalinkLoad.toFixed(2)}%
Connections : ${node.stats.playingPlayers} / ${node.stats.players}
System Load : ${node.stats.cpu.systemLoad.toFixed(2)}%
Cpu cores : ${node.stats.cpu.cores}
Uptime : ${moment(node.stats.uptime).format(
"D[ days], H[ hours], M[ minutes], S[ seconds]"
)}`).join('\n\n')}\`\`\``, inline: true
},
{ name: "**CPU**", value: `\`\`\`nim\nCpu: ${cpudata.manufacturer + " " + cpudata.brand}\nLoad: ${cl.currentLoad.toFixed(2)}%\nCores: ${cpudata.cores}\nPlatform: ${osdata.platform}\`\`\``, inline: true },
{ name: "**RAM**", value: `\`\`\`nim\nAvailable: ${pretty(memdata.total)}\nMemory Used: ${pretty(memdata.active)}\`\`\``, inline: true },
{ name: "**DISK**", value: `\`\`\`nim\nDisk Used: ${pretty(diskdata[0].size)} / ${pretty(diskdata[0].used)}\`\`\``, inline: true },
{ name: "**NETWORK**", value: `\`\`\`nim\nPing: ${Math.round(netdata[0].ms)}ms\nUp: ${pretty(netdata[0].tx_sec)}/s\nDown: ${pretty(netdata[0].rx_sec)}/s\n\nTotal Up: ${pretty(netdata[0].tx_bytes)}\nTotal Down: ${pretty(netdata[0].rx_bytes)}\`\`\`` },
{ name: "**Discord API Websocket Ping**", value: `\`\`\`nim\n${Math.round(client.ws.ping)}ms\`\`\``, inline: true },
{ name: "**Uptime**", value: `\`\`\`nim\n${uptimer(uptime)}\`\`\``, inline: true }
]
} as any;
if (hook) {
await hook.editMessage(config.msgId, {
embeds: [embed as any],
content: null,
})
}
}, 10000);
})
}
console.log("Starting...");
main();
console.log("Started!");
process.on('unhandledRejection', (reason, p) => {
console.log(reason, p);
});
process.on('uncaughtException', (err, origin) => {
console.log(err, origin);
});
process.on('uncaughtExceptionMonitor', (err, origin) => {
console.log(err, origin);
});
function uptimer(seconds: number) {
seconds = seconds || 0;
seconds = Number(seconds);
seconds = Math.abs(seconds);
var d = Math.floor(seconds / (3600 * 24));
var h = Math.floor(seconds % (3600 * 24) / 3600);
var m = Math.floor(seconds % 3600 / 60);
var s = Math.floor(seconds % 60);
let parts: any = new Array();
if (d > 0) {
var dDisplay = d > 0 ? d + ' ' + (d == 1 ? "day" : "days") : "";
parts.push(dDisplay);
}
if (h > 0) {
var hDisplay = h > 0 ? h + ' ' + (h == 1 ? "hour" : "hours") : "";
parts.push(hDisplay)
}
if (m > 0) {
var mDisplay = m > 0 ? m + ' ' + (m == 1 ? "minute" : "minutes") : "";
parts.push(mDisplay)
}
if (s > 0) {
var sDisplay = s > 0 ? s + ' ' + (s == 1 ? "second" : "seconds") : "";
parts.push(sDisplay)
}
return parts.join(', ', parts);
}
function formatBytes(bytes: number) {
if (bytes === 0) return "0 B";
const sizes = ["B", "KB", "MB", "GB", "TB"];
return `${(
bytes / Math.pow(1024, Math.floor(Math.log(bytes) / Math.log(1024)))
).toFixed(2)} ${sizes[Math.floor(Math.log(bytes) / Math.log(1024))]}`;
}