From 7f93f53cd69dc1cc6fc1010719007e48744acae7 Mon Sep 17 00:00:00 2001 From: lucmsilva651 Date: Wed, 24 Jul 2024 23:16:39 -0300 Subject: [PATCH] Small updates --- .gitignore | 3 ++- README.md | 2 +- bot.js | 4 ++-- commands/getinfo.js | 49 +++++++++++++++++++++++++++++++++++++++++++- locales/english.json | 1 + props/config.json | 3 ++- 6 files changed, 56 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 8a2e9a3..02a33f0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.txt node_modules __pycache__ -!requirements.txt \ No newline at end of file +!requirements.txt +props/config.json \ No newline at end of file diff --git a/README.md b/README.md index e65cf1f..dc32104 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ First, [make a fork of this repo](https://github.com/lucmsilva651/lynx/fork), or ``` git clone https://github.com/lucmsilva651/lynx ``` -Next, go to the repository directory, create a ``config.env`` file and put the content below: +Next, go to the repository directory, create a ``Config.env`` file and put the content below: ``` TGBOT_TOKEN="0000000000:AAAaaAAaaaaAaAaaAAAaaaAaaaaAAAAAaaa" TGBOT_ADMINS=[0000000000, 1111111111, 2222222222] diff --git a/bot.js b/bot.js index 91f4b29..80402da 100644 --- a/bot.js +++ b/bot.js @@ -1,7 +1,7 @@ const { Telegraf } = require('telegraf'); -const config = require('./props/config.json'); +const Config = require('./props/config.json'); -const bot = new Telegraf(config.botToken); +const bot = new Telegraf(Config.botToken); const loadCommands = () => { const fs = require('fs'); diff --git a/commands/getinfo.js b/commands/getinfo.js index 4dd7dbf..845e4f9 100644 --- a/commands/getinfo.js +++ b/commands/getinfo.js @@ -1,5 +1,38 @@ const Strings = require('../locales/english.json'); +const Config = require('../props/config.json'); +const os = require('os'); +function formatUptime(uptime) { + const hours = Math.floor(uptime / 3600); + const minutes = Math.floor((uptime % 3600) / 60); + const seconds = Math.floor(uptime % 60); + return `${hours}h ${minutes}m ${seconds}s`; +} + +function getSystemInfo() { + const platform = os.platform(); + const release = os.release(); + const arch = os.arch(); + 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 loadAverage = os.loadavg().map(avg => avg.toFixed(2)).join(', '); + const uptime = formatUptime(os.uptime()); + const nodeVersion = process.version; + + return `*Server Stats*\n\n` + + `*OS:* \`${platform} ${release}\`\n` + + `*Arch:* \`${arch}\`\n` + + `*Node.js Version:* \`${nodeVersion}\`\n` + + `*CPU:* \`${cpuModel}\`\n` + + `*CPU Cores:* \`${cpuCores} cores\`\n` + + `*RAM:* \`${freeMemory} / ${totalMemory}\`\n` + + `*Load Average:* \`${loadAverage}\`\n` + + `*Uptime:* \`${uptime}\`\n\n`; +} + +// Função para obter informações do usuário async function getUserInfo(ctx) { let userInfoTemplate = Strings.userInfo; @@ -21,6 +54,7 @@ async function getUserInfo(ctx) { return userInfoTemplate; } +// Função para obter informações do chat async function getChatInfo(ctx) { if (ctx.chat.type === 'group' || ctx.chat.type === 'supergroup') { let chatInfoTemplate = Strings.chatInfo; @@ -30,7 +64,6 @@ async function getChatInfo(ctx) { const chatHandle = ctx.chat.username ? `@${ctx.chat.username}` : Strings.varNone; const chatType = ctx.chat.type || Strings.unKnown; - // Aguarde a contagem de membros ser resolvida const chatMembersCount = await ctx.telegram.getChatMembersCount(chatId); const isForum = ctx.chat.is_forum ? Strings.varYes : Strings.varNo; @@ -49,6 +82,20 @@ async function getChatInfo(ctx) { } module.exports = (bot) => { + bot.command('stats', (ctx) => { + const userId = ctx.from.id || Strings.unKnown; + if (Config.admins.includes(userId)) { + const machineStats = getSystemInfo(); + ctx.reply( + machineStats, { + parse_mode: 'Markdown' + } + ); + } else { + ctx.reply(Strings.noPermission); + } + }); + bot.command('chatinfo', async (ctx) => { const chatInfo = await getChatInfo(ctx); ctx.reply( diff --git a/locales/english.json b/locales/english.json index 3eb6375..f3cdf6b 100644 --- a/locales/english.json +++ b/locales/english.json @@ -6,6 +6,7 @@ "varYes": "Yes", "varNo": "No", "varNone": "None", + "noPermission": "You don't have permissions to run this command.", "privateOnly": "This command should be used only on private chats, and not on groups.", "groupOnly": "This command should be used only on groups, and not on private chats.", "isGay": "Yes, you are *gay*!", diff --git a/props/config.json b/props/config.json index 23ccd64..21e479b 100644 --- a/props/config.json +++ b/props/config.json @@ -1,3 +1,4 @@ { - "botToken": "" + "botToken": "7082772504:AAGQ8wUsaoLBlhRW62DxgZbhIfMrjbbJBlg", + "admins": [6637260427, 6993445432, 6723363421] } \ No newline at end of file