From a3a0756db38f4359aa6ec726dc6ba290a51cbbef Mon Sep 17 00:00:00 2001 From: Lucas Gabriel <90426410+lucmsilva651@users.noreply.github.com> Date: Sat, 1 Jun 2024 22:56:49 +0000 Subject: [PATCH] Made stats (thanks ChatGPT) --- src/commands/stats.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/commands/stats.js diff --git a/src/commands/stats.js b/src/commands/stats.js new file mode 100644 index 0000000..220cba2 --- /dev/null +++ b/src/commands/stats.js @@ -0,0 +1,37 @@ +const os = require('os'); + +module.exports = function (bot, msg) { + const chatId = msg.chat.id; + const userName = msg.from.first_name; + const userId = msg.from.id; + + function formatUptime(uptime) { + const hours = Math.floor(uptime / 3600); + const minutes = Math.floor((uptime % 3600) / 60); + const seconds = uptime % 60; + return `${hours}h ${minutes}m ${seconds}s`; + } + + function getSystemInfo() { + const platform = os.platform(); + const release = os.release(); + const cpuModel = os.cpus()[0].model; + const cpuCores = os.cpus().length; + const totalMemory = (os.totalmem() / (1024 ** 3)).toFixed(2) + ' GB'; + const freeMemory = (os.freemem() / (1024 ** 3)).toFixed(2) + ' GB'; + const uptime = formatUptime(os.uptime()); + + return `📊 *Server Stats*\n\n` + + `*OS:* ${platform} ${release}\n` + + `*CPU:* ${cpuModel} (${cpuCores} cores)\n` + + `*RAM:* ${freeMemory} / ${totalMemory}\n` + + `*Uptime:* ${uptime}`; + } + + const message = getSystemInfo(); + + bot.sendMessage(chatId, message, { parse_mode: 'Markdown' }) + .catch(error => console.error('ERROR: Message cannot be sent:', error)); + + console.log(`INFO: /stats executed by ${userName}, ${userId}`); +};