From bcddfb06ba74c7c7f522c73c36c646006b6bfeb3 Mon Sep 17 00:00:00 2001 From: lucmsilva651 Date: Fri, 26 Jul 2024 01:38:23 -0300 Subject: [PATCH] Push some owner-only commands --- commands/getinfo.js | 49 ---------------------- commands/su.js | 93 +++++++++++++++++++++++++++++++++++++++++ locales/english.json | 1 + locales/portuguese.json | 1 + 4 files changed, 95 insertions(+), 49 deletions(-) create mode 100644 commands/su.js diff --git a/commands/getinfo.js b/commands/getinfo.js index 37e5ddc..4a41ff0 100644 --- a/commands/getinfo.js +++ b/commands/getinfo.js @@ -1,38 +1,5 @@ -const Config = require('../props/config.json'); -const os = require('os'); const { getStrings } = require('../plugins/checklang.js'); -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) { const Strings = getStrings(ctx.from.language_code); let userInfoTemplate = Strings.userInfo; @@ -55,7 +22,6 @@ async function getUserInfo(ctx) { return userInfoTemplate; } -// Função para obter informações do chat async function getChatInfo(ctx) { const Strings = getStrings(ctx.from.language_code); if (ctx.chat.type === 'group' || ctx.chat.type === 'supergroup') { @@ -84,21 +50,6 @@ 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', - reply_to_message_id: ctx.message.message_id - } - ); - } else { - ctx.reply(Strings.noPermission); - } - }); - bot.command('chatinfo', async (ctx) => { const chatInfo = await getChatInfo(ctx); ctx.reply( diff --git a/commands/su.js b/commands/su.js new file mode 100644 index 0000000..f6d348b --- /dev/null +++ b/commands/su.js @@ -0,0 +1,93 @@ +// specific commands to bot admins +const Config = require('../props/config.json'); +const { getStrings } = require('../plugins/checklang.js'); +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`; +} + +module.exports = (bot) => { + bot.command('stats', (ctx) => { + const Strings = getStrings(ctx.from.language_code); + const userId = ctx.from.id || Strings.unKnown; + if (Config.admins.includes(userId)) { + const machineStats = getSystemInfo(); + ctx.reply( + machineStats, { + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id + } + ).catch(error => ctx.reply( + "Error when getting server status:\n" + error, { + reply_to_message_id: ctx.message.message_id + } + )); + } else { + ctx.reply(Strings.botAdminOnly, { + reply_to_message_id: ctx.message.message_id + }); + } + }); + + bot.command('setbotname', (ctx) => { + const Strings = getStrings(ctx.from.language_code); + const userId = ctx.from.id || Strings.unKnown; + if (Config.admins.includes(userId)) { + const botName = ctx.message.text.split(' ').slice(1).join(' '); + ctx.telegram.setMyName(botName).catch(error => ctx.reply( + "Error when changing bot name:\n" + error, { + reply_to_message_id: ctx.message.message_id + } + )); + } else { + ctx.reply(Strings.botAdminOnly, { + reply_to_message_id: ctx.message.message_id + }); + } + }); + + bot.command('setbotdesc', (ctx) => { + const Strings = getStrings(ctx.from.language_code); + const userId = ctx.from.id || Strings.unKnown; + if (Config.admins.includes(userId)) { + const botDesc = ctx.message.text.split(' ').slice(1).join(' '); + ctx.telegram.setMyName(botDesc).catch(error => ctx.reply( + "Error when changing bot description:\n" + error, { + reply_to_message_id: ctx.message.message_id + } + )); + } else { + ctx.reply( + Strings.botAdminOnly, { + reply_to_message_id: ctx.message.message_id + }); + } + }); +}; \ No newline at end of file diff --git a/locales/english.json b/locales/english.json index 6a623a1..3dc3359 100644 --- a/locales/english.json +++ b/locales/english.json @@ -7,6 +7,7 @@ "varNo": "No", "varNone": "None", "noPermission": "You don't have permissions to run this command.", + "botAdminOnly": "This command is exclusive to the bot's general administrators. I can't disclose who they are, nor what this command does.", "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/locales/portuguese.json b/locales/portuguese.json index 1d93cfb..5946803 100644 --- a/locales/portuguese.json +++ b/locales/portuguese.json @@ -7,6 +7,7 @@ "varNo": "Não", "varNone": "Nenhum", "noPermission": "Você não tem permissões para rodar esse comando.", + "botAdminOnly": "Esse comando é exclusivo a administradores gerais do bot. Não posso informar quem são, e nem o que esse comando faz.", "privateOnly": "Esse comando deve ser utilizado apenas em chats privados, e não em grupos.", "groupOnly": "Esse comando deve ser utilizado apenas em grupos, e não em chats privados.", "isGay": "Sim, você é *gay*!",