Skip to content

Commit

Permalink
sysinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
weskerty committed Oct 8, 2024
1 parent ce55b3b commit 2381054
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 76 deletions.
148 changes: 73 additions & 75 deletions plugins/info-estado.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os from 'os';
import { exec } from 'child_process';
import { generateWAMessageFromContent } from 'baileys';
import fs from 'fs';
import { performance } from 'perf_hooks';

function formatUptime(uptime) {
const seconds = Math.floor(uptime % 60);
Expand Down Expand Up @@ -33,6 +31,44 @@ function getVersions(callback) {
});
}

function getLinuxInfo(callback) {
exec('cat /etc/os-release', (err, osInfo) => {
if (err) osInfo = '✖️';
callback(osInfo.trim());
});
}

function getStorageInfo() {
const diskInfo = [];
const drives = os.platform() === 'win32' ? 'wmic logicaldisk get size,freespace,caption' : 'df -h';

exec(drives, (err, stdout) => {
if (err) {
console.error('Error al obtener la información de almacenamiento:', err);
} else {
diskInfo.push(stdout.trim());
}
});

return diskInfo;
}

function getBatteryInfo(callback) {
if (os.platform() === 'win32') {
exec('WMIC PATH Win32_Battery Get EstimatedChargeRemaining', (err, stdout) => {
if (err) return callback('Batería no disponible');
const battery = stdout.trim();
callback(`Carga estimada: ${battery}%`);
});
} else {
exec('upower -i $(upower -e | grep BAT) | grep percentage', (err, stdout) => {
if (err) return callback('Batería no disponible');
const battery = stdout.split(':')[1].trim();
callback(`Carga estimada: ${battery}`);
});
}
}

async function getSystemInfo(callback) {
const systemInfo = {
platform: os.platform(),
Expand All @@ -46,86 +82,48 @@ async function getSystemInfo(callback) {
};

getVersions((versions) => {
callback(systemInfo, versions);
});
}
getLinuxInfo((linuxInfo) => {
getBatteryInfo((batteryInfo) => {
const storageInfo = getStorageInfo();

function getBotInfo(conn, m, callback) {
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 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(3);

const botInfo = {
uptime,
totalusrReg,
totalusr,
groupsCount: groups.length,
chatsCount: chats.length,
rtime,
autoread,
restrict,
pconly,
gconly,
antiprivado,
antiCall,
modejadibot
};
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 += `> *🔋 Batería*\n${batteryInfo}\n\n`;

infoMessage += `> *💾 Almacenamiento*\n${storageInfo.join('\n')}\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`;
}

callback(botInfo);
callback(infoMessage);
});
});
});
}

const handler = async (m, { conn }) => {
getSystemInfo((systemInfo, versions) => {
getBotInfo(conn, m, (botInfo) => {
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 del Bot*\n\n`;
infoMessage += `- ⏲️ *Uptime*: ${botInfo.uptime}\n`;
infoMessage += `- 👥 *Usuarios Registrados*: ${botInfo.totalusrReg}\n`;
infoMessage += `- 👤 *Usuarios Totales*: ${botInfo.totalusr}\n`;
infoMessage += `- 🏘️ *Grupos*: ${botInfo.groupsCount}\n`;
infoMessage += `- 📨 *Chats*: ${botInfo.chatsCount}\n`;
infoMessage += `- ⏱️ *Tiempo de Respuesta*: ${botInfo.rtime} ms\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`; // Solo primera linea
infoMessage += `- 🐍 *Python*: ${versions.pythonVersion.trim()}\n`;
infoMessage += `- 📦 *PIP*: ${versions.pipVersion.trim()}\n`;
infoMessage += `- 🍫 *Chocolatey*: ${versions.chocoVersion.trim()}\n`;

conn.sendMessage(m.chat, { text: infoMessage });
});
getSystemInfo((infoMessage) => {
conn.sendMessage(m.chat, { text: infoMessage });
});
};

function clockString(ms) {
const h = Math.floor(ms / 3600000);
const m = Math.floor(ms / 60000) % 60;
const s = Math.floor(ms / 1000) % 60;
return [h, m, s].map((v) => v.toString().padStart(2, 0)).join(':');
}
handler.command = ['alive', 'host', 'info']

handler.command = /^(host|sysinfo)$/i;
export default handler;
2 changes: 1 addition & 1 deletion plugins/info-repositorio.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const handler = async (m, { conn, args, usedPrefix }) => {
const _translate = JSON.parse(fs.readFileSync(`./src/languages/${idioma}.json`))
const tradutor = _translate.plugins.info_repositorio

const res = await fetch('https://api.github.com/repos/BrunoSobrino/TheMystic-Bot-MD');
const res = await fetch('https://github.com/weskerty/TheMysticMOD');
const json = await res.json();
let txt = `${tradutor.texto1[0]}\n\n`;
txt += `${tradutor.texto1[1]} ${json?.name || tradutor.texto1[2]}\n\n`;
Expand Down

0 comments on commit 2381054

Please sign in to comment.