Skip to content

Commit 634ab5c

Browse files
authored
Merge pull request #2 from mrepol742/added-stats-command
added-stats-command
2 parents 815fd76 + d122d1d commit 634ab5c

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/commands/go.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default async function (msg: Message) {
4949
const searchUrl = `https://duckduckgo.com/?q=${encodeURIComponent(query)}`;
5050
await msg.reply(`DuckDuckGo search results for "${query}":\n${searchUrl}`);
5151
} catch (error) {
52-
log.error("GoCommand", "Error fetching DuckDuckGo results:", error);
52+
log.error("Command", "Error fetching DuckDuckGo results:", error);
5353
await msg.reply("Failed to search DuckDuckGo.");
5454
}
5555
}

src/commands/stats.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Message } from "whatsapp-web.js";
2+
import log from "npmlog";
3+
import os from "os";
4+
5+
export const command = "stats";
6+
7+
export default async function (msg: Message) {
8+
try {
9+
const stats = {
10+
platform: os.platform(),
11+
arch: os.arch(),
12+
cpuCount: os.cpus().length,
13+
totalMemory: os.totalmem(),
14+
freeMemory: os.freemem(),
15+
uptime: process.uptime(),
16+
};
17+
18+
const statsMessage = `
19+
*System Stats:*
20+
- Platform: ${stats.platform}
21+
- Architecture: ${stats.arch}
22+
- CPU Count: ${stats.cpuCount}
23+
- Total Memory: ${(stats.totalMemory / (1024 ** 3)).toFixed(2)} GB
24+
- Free Memory: ${(stats.freeMemory / (1024 ** 3)).toFixed(2)} GB
25+
- Uptime: ${(stats.uptime / 3600).toFixed(2)} hours
26+
- Node.js Version: ${process.version}
27+
`;
28+
29+
await msg.reply(statsMessage);
30+
} catch (error) {
31+
log.error("Command", "Error occured while processing the request:", error);
32+
await msg.reply("An error occurred while processing your request.");
33+
}
34+
}

0 commit comments

Comments
 (0)