From c7d5c0549deac0bbc5873e28643b129c08fafa6c Mon Sep 17 00:00:00 2001 From: Weskerty Date: Tue, 8 Oct 2024 08:22:55 -0300 Subject: [PATCH] sysinfo test --- plugins/SYS.js | 136 +++++++++++++++++++++ plugins/info-estado.js | 266 ++++++++++++++++++++++++++--------------- 2 files changed, 308 insertions(+), 94 deletions(-) create mode 100644 plugins/SYS.js diff --git a/plugins/SYS.js b/plugins/SYS.js new file mode 100644 index 000000000..c3ecc04ff --- /dev/null +++ b/plugins/SYS.js @@ -0,0 +1,136 @@ +import os from 'os'; +import { exec } from 'child_process'; + +function formatUptime(uptime) { + const seconds = Math.floor(uptime % 60); + const minutes = Math.floor((uptime / 60) % 60); + const hours = Math.floor((uptime / 3600) % 24); + return `${hours} horas, ${minutes} minutos, ${seconds} segundos`; +} + +function getVersions(callback) { + exec('node -v', (err, nodeVersion) => { + if (err) nodeVersion = '✖️'; + exec('npm -v', (err, npmVersion) => { + if (err) npmVersion = '✖️'; + exec('ffmpeg -version', (err, ffmpegVersion) => { + if (err) ffmpegVersion = '✖️'; + exec('python --version || python3 --version || py --version', (err, pythonVersion) => { + if (err) pythonVersion = '✖️'; + exec('pip --version || pip3 --version', (err, pipVersion) => { + if (err) pipVersion = '✖️'; + exec('choco -v', (err, chocoVersion) => { + if (err) chocoVersion = '✖️'; + callback({ nodeVersion, npmVersion, ffmpegVersion, pythonVersion, pipVersion, chocoVersion }); + }); + }); + }); + }); + }); + }); +} + +function getStorageInfo(callback) { + if (os.platform() === 'win32') { + exec('wmic logicaldisk get size,freespace,caption', (err, stdout) => { + if (err) return callback('✖️'); + const lines = stdout.trim().split('\n').slice(1); + const storageInfo = lines.map(line => { + const [drive, free, total] = line.trim().split(/\s+/); + return `🖥️ ${drive}: ${(total / (1024 ** 3)).toFixed(2)} GB total, ${(free / (1024 ** 3)).toFixed(2)} GB libres`; + }).join('\n'); + callback(storageInfo); + }); + } else { + exec('df -h --output=source,size,avail,target', (err, stdout) => { + if (err) return callback('✖️'); + const lines = stdout.trim().split('\n').slice(1); + const storageInfo = lines.map(line => { + const [device, total, free, mount] = line.trim().split(/\s+/); + return `🖥️ ${mount}: ${total} total, ${free} libres en ${device}`; + }).join('\n'); + callback(storageInfo); + }); + } +} + +function getLinuxInfo(callback) { + exec('cat /etc/os-release', (err, osInfo) => { + if (err) osInfo = '✖️'; + callback(osInfo.trim()); + }); +} + +function getBatteryInfo(callback) { + if (os.platform() === 'linux' || os.platform() === 'darwin') { + exec('upower -i $(upower -e | grep BAT)', (err, batteryInfo) => { + if (err) return callback('✖️'); + callback(batteryInfo); + }); + } else if (os.platform() === 'win32') { + exec('WMIC Path Win32_Battery Get EstimatedChargeRemaining', (err, batteryInfo) => { + if (err) return callback('✖️'); + callback(`🔋 ${batteryInfo.trim()}%`); + }); + } else { + callback('✖️'); + } +} + +async function systemInfoPlugin(m, extra) { + try { + const systemInfo = { + platform: os.platform(), + cpuArch: os.arch(), + cpus: os.cpus().length, + totalMemory: (os.totalmem() / (1024 ** 3)).toFixed(2) + ' GB', // Total RAM en GB + freeMemory: (os.freemem() / (1024 ** 3)).toFixed(2) + ' GB', // RAM libre en GB + uptime: formatUptime(os.uptime()), // Tiempo de actividad + osVersion: os.release(), // Versión del SO + loadAverage: os.loadavg().map(load => load.toFixed(2)).join(', ') // Carga promedio + }; + + getVersions((versions) => { + getBatteryInfo((batteryStatus) => { + getStorageInfo((storageInfo) => { + getLinuxInfo((linuxInfo) => { + let infoMessage = `> *📊 Información del Sistema*\n\n`; + infoMessage += `- 🌐 *Plataforma*: _${systemInfo.platform}_\n`; + infoMessage += `- 💻 *Arquitectura CPU*: ${systemInfo.cpuArch}\n`; + infoMessage += `- 🧠 *Núcleos CPU*: ${systemInfo.cpus}\n`; + infoMessage += `- 🗄️ *Memoria Total*: ${systemInfo.totalMemory}\n`; + infoMessage += `- 🗃️ *Memoria Libre*: ${systemInfo.freeMemory}\n`; + infoMessage += `- ⏱️ *Tiempo de Actividad*: ${systemInfo.uptime}\n`; + infoMessage += `- 📀 *Versión del SO*: ${systemInfo.osVersion}\n`; + infoMessage += `- 📊 *Carga Promedio (1, 5, 15 min)*: ${systemInfo.loadAverage}\n`; + infoMessage += `- 🔋 *Energia*: ${batteryStatus}\n\n`; + + infoMessage += `> *💾 Almacenamiento*\n`; + infoMessage += `${storageInfo}\n\n`; + + infoMessage += `> *🛠️ Version Herramientas*\n\n`; + infoMessage += `- ☕ *Node.js*: ${versions.nodeVersion.trim()}\n`; + infoMessage += `- 📦 *NPM*: ${versions.npmVersion.trim()}\n`; + infoMessage += `- 🎥 *FFmpeg*: ${versions.ffmpegVersion.split('\n')[0]}\n`; // Solo primera linea + infoMessage += `- 🐍 *Python*: ${versions.pythonVersion.trim()}\n`; + infoMessage += `- 📦 *PIP*: ${versions.pipVersion.trim()}\n`; + infoMessage += `- 🍫 *Chocolatey*: ${versions.chocoVersion.trim()}\n\n`; + + if (os.platform() === 'linux') { + infoMessage += `> *🐧 Distribución Linux*\n${linuxInfo}\n`; + } + + extra.conn.sendMessage(m.chat, { text: infoMessage }); + }); + }); + }); + }); + } catch (error) { + console.error('Falla Plugin sysinfo:', error); + await extra.conn.sendMessage(m.chat, { text: 'ERROR' }); + } +} + +systemInfoPlugin.command = ['sysinfo', 'host']; + +export default systemInfoPlugin; diff --git a/plugins/info-estado.js b/plugins/info-estado.js index 3cb1c2b87..23572bcbf 100644 --- a/plugins/info-estado.js +++ b/plugins/info-estado.js @@ -1,17 +1,38 @@ -import os from 'os'; +import { generateWAMessageFromContent } from "baileys"; +import os from "os"; +import util from "util"; +import sizeFormatter from "human-readable"; +import MessageType from "baileys"; +import fs from "fs"; +import { performance } from "perf_hooks"; import { exec } from 'child_process'; -import fs from 'fs'; - -// Función para formatear el uptime -function formatUptime(uptime) { - const seconds = Math.floor(uptime % 60); - const minutes = Math.floor((uptime / 60) % 60); - const hours = Math.floor((uptime / 3600) % 24); - return `${hours} horas, ${minutes} minutos, ${seconds} segundos`; -} -// Obtener las versiones de las herramientas instaladas -function getVersions(callback) { +const handler = async (m, { conn, usedPrefix }) => { + const datas = global + const idioma = datas.db.data.users[m.sender].language || global.defaultLenguaje + const _translate = JSON.parse(fs.readFileSync(`./src/languages/${idioma}.json`)) + const tradutor = _translate.plugins.info_estado + + const _uptime = process.uptime() * 1000; + const uptime = clockString(_uptime); + const totalusrReg = Object.values(global.db.data.users).filter((user) => user.registered == true).length; + const totalusr = Object.keys(global.db.data.users).length; + const chats = Object.entries(conn.chats).filter( + ([id, data]) => id && data.isChats, + ); + const groupsIn = chats.filter(([id]) => id.endsWith("@g.us")); + const groups = chats.filter(([id]) => id.endsWith("@g.us")); + const used = process.memoryUsage(); + const { restrict, antiCall, antiprivado, modejadibot } = + global.db.data.settings[conn.user.jid] || {}; + const { autoread, gconly, pconly, self } = global.opts || {}; + const old = performance.now(); + const neww = performance.now(); + const rtime = (neww - old).toFixed(7); + const wm = 'MysticMOD'; + const info = ` ${tradutor.texto1[0]} + + function getVersions(callback) { exec('node -v', (err, nodeVersion) => { if (err) nodeVersion = '✖️'; exec('npm -v', (err, npmVersion) => { @@ -33,114 +54,171 @@ function getVersions(callback) { }); } -function getLinuxInfo(callback) { - exec('cat /etc/os-release', (err, osInfo) => { - if (err) osInfo = '✖️'; - callback(osInfo.trim()); - }); -} - function getStorageInfo(callback) { if (os.platform() === 'win32') { exec('wmic logicaldisk get size,freespace,caption', (err, stdout) => { - if (err) return callback('Error al obtener la información de almacenamiento.'); - - // Formatear la salida - const lines = stdout.trim().split('\n'); - const storage = lines.slice(1).map(line => { + if (err) return callback('✖️'); + const lines = stdout.trim().split('\n').slice(1); + const storageInfo = lines.map(line => { const [drive, free, total] = line.trim().split(/\s+/); - const totalGB = (total / (1024 ** 3)).toFixed(2) + ' GB'; - const freeGB = (free / (1024 ** 3)).toFixed(2) + ' GB'; - return `Unidad ${drive}: ${freeGB} libres de ${totalGB}`; - }); - callback(storage.join('\n')); + return `🖥️ ${drive}: ${(total / (1024 ** 3)).toFixed(2)} GB total, ${(free / (1024 ** 3)).toFixed(2)} GB libres`; + }).join('\n'); + callback(storageInfo); }); } else { - exec('df -h', (err, stdout) => { + exec('df -h --output=source,size,avail,target', (err, stdout) => { if (err) return callback('✖️'); - - // Formatear la salida - const lines = stdout.trim().split('\n'); - const storage = lines.slice(1).map(line => { - const parts = line.split(/\s+/); - return `Dispositivo ${parts[0]}: ${parts[3]} libres de ${parts[1]}`; - }); - callback(storage.join('\n')); + const lines = stdout.trim().split('\n').slice(1); + const storageInfo = lines.map(line => { + const [device, total, free, mount] = line.trim().split(/\s+/); + return `🖥️ ${mount}: ${total} total, ${free} libres en ${device}`; + }).join('\n'); + callback(storageInfo); }); } } +function getLinuxInfo(callback) { + exec('cat /etc/os-release', (err, osInfo) => { + if (err) osInfo = '✖️'; + callback(osInfo.trim()); + }); +} + function getBatteryInfo(callback) { - if (os.platform() === 'win32') { - exec('WMIC PATH Win32_Battery Get EstimatedChargeRemaining', (err, stdout) => { + if (os.platform() === 'linux' || os.platform() === 'darwin') { + exec('upower -i $(upower -e | grep BAT)', (err, batteryInfo) => { if (err) return callback('✖️'); - const battery = stdout.trim(); - callback(`Carga estimada: ${battery}%`); + callback(batteryInfo); }); - } else { - exec('upower -i $(upower -e | grep BAT) | grep percentage', (err, stdout) => { + } else if (os.platform() === 'win32') { + exec('WMIC Path Win32_Battery Get EstimatedChargeRemaining', (err, batteryInfo) => { if (err) return callback('✖️'); - const battery = stdout.split(':')[1].trim(); - callback(`Carga estimada: ${battery}`); + callback(`🔋 ${batteryInfo.trim()}%`); }); + } else { + callback('✖️'); } } -async function getSystemInfo(callback) { - const systemInfo = { - platform: os.platform(), - cpuArch: os.arch(), - cpus: os.cpus().length, - totalMemory: (os.totalmem() / (1024 ** 3)).toFixed(2) + ' GB', - freeMemory: (os.freemem() / (1024 ** 3)).toFixed(2) + ' GB', - uptime: formatUptime(os.uptime()), - osVersion: os.release(), - loadAverage: os.loadavg().map(load => load.toFixed(2)).join(', ') - }; +async function systemInfoPlugin(m, extra) { + try { + const systemInfo = { + platform: os.platform(), + cpuArch: os.arch(), + cpus: os.cpus().length, + totalMemory: (os.totalmem() / (1024 ** 3)).toFixed(2) + ' GB', // Total RAM en GB + freeMemory: (os.freemem() / (1024 ** 3)).toFixed(2) + ' GB', // RAM libre en GB + uptime: formatUptime(os.uptime()), // Tiempo de actividad + osVersion: os.release(), // Versión del SO + loadAverage: os.loadavg().map(load => load.toFixed(2)).join(', ') // Carga promedio + }; - getVersions((versions) => { - getLinuxInfo((linuxInfo) => { - getBatteryInfo((batteryInfo) => { + getVersions((versions) => { + getBatteryInfo((batteryStatus) => { getStorageInfo((storageInfo) => { - let infoMessage = `> *📊 Información del Sistema*\n\n`; - infoMessage += `- 🌐 *Plataforma*: _${systemInfo.platform}_\n`; - infoMessage += `- 💻 *Arquitectura CPU*: ${systemInfo.cpuArch}\n`; - infoMessage += `- 🧠 *Núcleos CPU*: ${systemInfo.cpus}\n`; - infoMessage += `- 🗄️ *Memoria Total*: ${systemInfo.totalMemory}\n`; - infoMessage += `- 🗃️ *Memoria Libre*: ${systemInfo.freeMemory}\n`; - infoMessage += `- ⏱️ *Tiempo de Actividad*: ${systemInfo.uptime}\n`; - infoMessage += `- 📀 *Versión del SO*: ${systemInfo.osVersion}\n`; - infoMessage += `- 📊 *Carga Promedio (1, 5, 15 min)*: ${systemInfo.loadAverage}\n\n`; - - infoMessage += `> *🔋 Información de Batería*\n${batteryInfo}\n\n`; - - infoMessage += `> *💾 Información de Almacenamiento*\n${storageInfo}\n\n`; - - infoMessage += `> *🛠️ Versiones de Herramientas*\n\n`; - infoMessage += `- ☕ *Node.js*: ${versions.nodeVersion.trim()}\n`; - infoMessage += `- 📦 *NPM*: ${versions.npmVersion.trim()}\n`; - infoMessage += `- 🎥 *FFmpeg*: ${versions.ffmpegVersion.split('\n')[0]}\n`; - infoMessage += `- 🐍 *Python*: ${versions.pythonVersion.trim()}\n`; - infoMessage += `- 📦 *PIP*: ${versions.pipVersion.trim()}\n`; - infoMessage += `- 🍫 *Chocolatey*: ${versions.chocoVersion.trim()}\n\n`; - - if (os.platform() === 'linux') { - infoMessage += `> *🐧 Distribución Linux*\n${linuxInfo}\n`; - } - - callback(infoMessage); + getLinuxInfo((linuxInfo) => { + let infoMessage = `> *📊 Información del Sistema*\n\n`; + infoMessage += `- 🌐 *Plataforma*: _${systemInfo.platform}_\n`; + infoMessage += `- 💻 *Arquitectura CPU*: ${systemInfo.cpuArch}\n`; + infoMessage += `- 🧠 *Núcleos CPU*: ${systemInfo.cpus}\n`; + infoMessage += `- 🗄️ *Memoria Total*: ${systemInfo.totalMemory}\n`; + infoMessage += `- 🗃️ *Memoria Libre*: ${systemInfo.freeMemory}\n`; + infoMessage += `- ⏱️ *Tiempo de Actividad*: ${systemInfo.uptime}\n`; + infoMessage += `- 📀 *Versión del SO*: ${systemInfo.osVersion}\n`; + infoMessage += `- 📊 *Carga Promedio (1, 5, 15 min)*: ${systemInfo.loadAverage}\n`; + infoMessage += `- 🔋 *Energia*: ${batteryStatus}\n\n`; + + infoMessage += `> *💾 Almacenamiento*\n`; + infoMessage += `${storageInfo}\n\n`; + + infoMessage += `> *🛠️ Version Herramientas*\n\n`; + infoMessage += `- ☕ *Node.js*: ${versions.nodeVersion.trim()}\n`; + infoMessage += `- 📦 *NPM*: ${versions.npmVersion.trim()}\n`; + infoMessage += `- 🎥 *FFmpeg*: ${versions.ffmpegVersion.split('\n')[0]}\n`; // Solo primera linea + infoMessage += `- 🐍 *Python*: ${versions.pythonVersion.trim()}\n`; + infoMessage += `- 📦 *PIP*: ${versions.pipVersion.trim()}\n`; + infoMessage += `- 🍫 *Chocolatey*: ${versions.chocoVersion.trim()}\n\n`; + + if (os.platform() === 'linux') { + infoMessage += `> *🐧 Distribución Linux*\n${linuxInfo}\n`; + } + + extra.conn.sendMessage(m.chat, { text: infoMessage }); + }); }); }); }); - }); + } catch (error) { + console.error('Falla Plugin sysinfo:', error); + await extra.conn.sendMessage(m.chat, { text: 'ERROR' }); + } } -const handler = async (m, { conn }) => { - getSystemInfo((infoMessage) => { - conn.sendMessage(m.chat, { text: infoMessage }); - }); -}; + ${tradutor.texto1[1]} + ${tradutor.texto1[2]} + ${tradutor.texto1[3]} -handler.command = /^(sysinfo)$/i; + ${tradutor.texto1[4]} ${rtime} + ${tradutor.texto1[5]} ${uptime} + ${tradutor.texto1[6]} ${usedPrefix} + ${tradutor.texto1[7]} ${self ? "privado" : "público"} + ${tradutor.texto1[8]} ${totalusrReg} + ${tradutor.texto1[9]} ${totalusr} + ${tradutor.texto1[10]} ${(conn.user.jid == global.conn.user.jid ? '' : `Sub-bot de:\n ▢ +${global.conn.user.jid.split`@`[0]}`) || 'No es sub-bot'} + + ${tradutor.texto1[11]} ${chats.length - groups.length} + ${tradutor.texto1[12]} ${groups.length} + ${tradutor.texto1[13]} ${chats.length} + + ${tradutor.texto1[14]} ${autoread ? "activo" : "desactivado"} + ${tradutor.texto1[15]} ${restrict ? "activo" : "desactivado"} + ${tradutor.texto1[16]} ${pconly ? "activado" : "desactivado"} + ${tradutor.texto1[17]} ${gconly ? "activado" : "desactivado"} + ${tradutor.texto1[18]} ${antiprivado ? "activado" : "desactivado"} + ${tradutor.texto1[19]} ${antiCall ? "activado" : "desactivado"} + ${tradutor.texto1[20]} ${modejadibot ? "activado" : "desactivado"}`.trim(); + const doc = [ + "pdf", + "zip", + "vnd.openxmlformats-officedocument.presentationml.presentation", + "vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "vnd.openxmlformats-officedocument.wordprocessingml.document", + ]; + const document = doc[Math.floor(Math.random() * doc.length)]; + const Message = { + document: { url: `https://github.com/weskerty/TheMysticMOD` }, + mimetype: `application/${document}`, + fileName: `Documento`, + fileLength: 999, + pageCount: 200, + contextInfo: { + forwardingScore: 200, + isForwarded: true, + externalAdReply: { + mediaUrl: "https://github.com/weskerty/TheMysticMOD", + mediaType: 2, + previewType: "pdf", + title: "The Mystic - Bot", + body: tradutor.texto2, + thumbnail: imagen1, + sourceUrl: "https://github.com/weskerty/TheMysticMOD", + }, + }, + caption: info, + footer: wm, + headerType: 6, + }; + conn.sendMessage(m.chat, Message, { quoted: m }); +}; +handler.command = /^(ping|info|status|estado|infobot)$/i; export default handler; + +function clockString(ms) { + const h = Math.floor(ms / 3600000); + const m = Math.floor(ms / 60000) % 60; + const s = Math.floor(ms / 1000) % 60; + console.log({ ms, h, m, s }); + return [h, m, s].map((v) => v.toString().padStart(2, 0)).join(":"); +} \ No newline at end of file