MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MDX / handler

Function handler

plugins/sysinfo.ts:16–93  ·  view source on GitHub ↗
(sock: any, message: any, args: any[], context: BotContext)

Source from the content-addressed store, hash-verified

14 ownerOnly: true,
15
16 async handler(sock: any, message: any, args: any[], context: BotContext) {
17 const { chatId, channelInfo } = context;
18
19 try {
20 // Memory via os module (works everywhere, no free command needed)
21 const totalMem = os.totalmem();
22 const freeMem = os.freemem();
23 const usedMem = totalMem - freeMem;
24 const fmt = (b: number) => b > 1073741824 ? (b / 1073741824).toFixed(2) + ' GB' : (b / 1048576).toFixed(0) + ' MB';
25 const memTotal = fmt(totalMem);
26 const memUsed = fmt(usedMem);
27 const memFree = fmt(freeMem);
28
29 // Disk via df (fallback if not available)
30 let diskTotal = 'N/A', diskUsed = 'N/A', diskFree = 'N/A', diskPct = 'N/A';
31 try {
32 const diskOut = (await execAsync('df -h /')).stdout.trim();
33 const diskVals = diskOut.split('\n')[1]?.split(/\s+/) || [];
34 diskTotal = diskVals[1] || 'N/A';
35 diskUsed = diskVals[2] || 'N/A';
36 diskFree = diskVals[3] || 'N/A';
37 diskPct = diskVals[4] || 'N/A';
38 } catch {}
39
40 // Bot uptime (process uptime, not system uptime)
41 const uptimeSec = Math.floor(process.uptime());
42 const uptimeDays = Math.floor(uptimeSec / 86400);
43 const uptimeHrs = Math.floor((uptimeSec % 86400) / 3600);
44 const uptimeMins = Math.floor((uptimeSec % 3600) / 60);
45 const uptimeSecs = uptimeSec % 60;
46 const uptimeOut = uptimeDays > 0
47 ? `${uptimeDays}d ${uptimeHrs}h ${uptimeMins}m`
48 : uptimeHrs > 0
49 ? `${uptimeHrs}h ${uptimeMins}m ${uptimeSecs}s`
50 : `${uptimeMins}m ${uptimeSecs}s`;
51
52 // CPU
53 const cpus = os.cpus();
54 const cpuModel = cpus[0]?.model?.trim() || 'Unknown';
55 const cpuCores = cpus.length;
56 const loadAvg = os.loadavg().map(l => l.toFixed(2)).join(', ');
57
58 // Platform
59 const platform = os.platform();
60 const arch = os.arch();
61 const nodeVer = process.version;
62 const hostname = os.hostname();
63
64 const text =
65 `╔══════════════════════════════╗\n` +
66 `║ 🖥️ *SERVER STATS* ║\n` +
67 `╚══════════════════════════════╝\n\n` +
68 `🏠 *Host:* ${hostname}\n` +
69 `🐧 *OS:* ${platform} (${arch})\n` +
70 `⏱️ *Bot Uptime:* ${uptimeOut}\n` +
71 `🟢 *Node.js:* ${nodeVer}\n\n` +
72 `━━━━━━ 🧠 CPU ━━━━━━\n` +
73 `🔧 *Model:* ${cpuModel}\n` +

Callers

nothing calls this directly

Calls 1

fmtFunction · 0.70

Tested by

no test coverage detected