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

Function handler

plugins/alive.ts:13–67  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

11 isPrefixless: true,
12
13 async handler(sock: any, message: any, args: any, context: BotContext) {
14 const { chatId, config } = context;
15
16 try {
17 let uptime = Math.floor(process.uptime());
18
19 const days = Math.floor(uptime / 86400);
20 uptime %= 86400;
21 const hours = Math.floor(uptime / 3600);
22 uptime %= 3600;
23 const minutes = Math.floor(uptime / 60);
24 const seconds = (Number(uptime) % Number(60));
25
26 const uptimeParts = [];
27 if (days) uptimeParts.push(`${days}d`);
28 if (hours) uptimeParts.push(`${hours}h`);
29 if (minutes) uptimeParts.push(`${minutes}m`);
30 if (seconds || uptimeParts.length === 0) uptimeParts.push(`${seconds}s`);
31
32 const uptimeText = uptimeParts.join(' ');
33 const totalMem = (os.totalmem() / 1024 / 1024).toFixed(2);
34 const freeMem = (os.freemem() / 1024 / 1024).toFixed(2);
35 const usedMem = (Number(totalMem) - Number(freeMem)).toFixed(2);
36 const cpuLoad = os.loadavg()[0].toFixed(2);
37 const platform = os.platform();
38 const arch = os.arch();
39 const nodeVersion = process.version;
40
41 const text =
42 `*🤖 ${config.botName} IS ACTIVE!*\n\n` +
43 `*Version:* ${config.version}\n` +
44 `*Uptime:* ${uptimeText}\n` +
45 `*RAM Usage:* ${usedMem} MB / ${totalMem} MB\n` +
46 `*CPU Load:* ${cpuLoad}\n` +
47 `*Platform:* ${platform} (${arch})\n` +
48 `*Node.js:* ${nodeVersion}\n`;
49
50 await sock.sendMessage(chatId, {
51 text,
52 contextInfo: {
53 forwardingScore: 999,
54 isForwarded: true,
55 forwardedNewsletterMessageInfo: {
56 newsletterJid: '120363319098372999@newsletter',
57 newsletterName: 'GlobalTechInc',
58 serverMessageId: -1
59 }
60 }
61 }, { quoted: message });
62
63 } catch(error: any) {
64 console.error('Error in alive command:', error);
65 await sock.sendMessage(chatId, { text: '✅ Bot is alive and running!' }, { quoted: message });
66 }
67 }
68};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected