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 2381054 commit 15ffa6b
Showing 1 changed file with 67 additions and 50 deletions.
117 changes: 67 additions & 50 deletions plugins/info-estado.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import os from 'os';
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) {
exec('node -v', (err, nodeVersion) => {
if (err) nodeVersion = '✖️';
Expand Down Expand Up @@ -38,31 +40,46 @@ function getLinuxInfo(callback) {
});
}

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 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 => {
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'));
});
} else {
exec('df -h', (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'));
});
}
}

function getBatteryInfo(callback) {
if (os.platform() === 'win32') {
exec('WMIC PATH Win32_Battery Get EstimatedChargeRemaining', (err, stdout) => {
if (err) return callback('Batería no disponible');
if (err) return callback('✖️');
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');
if (err) return callback('✖️');
const battery = stdout.split(':')[1].trim();
callback(`Carga estimada: ${battery}`);
});
Expand All @@ -74,45 +91,45 @@ async function getSystemInfo(callback) {
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
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(', ')
};

getVersions((versions) => {
getLinuxInfo((linuxInfo) => {
getBatteryInfo((batteryInfo) => {
const storageInfo = getStorageInfo();

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(infoMessage);
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);
});
});
});
});
Expand All @@ -124,6 +141,6 @@ const handler = async (m, { conn }) => {
});
};

handler.command = ['alive', 'host', 'info']
handler.command = /^(sysinfo)$/i;

export default handler;

0 comments on commit 15ffa6b

Please sign in to comment.