Skip to content

Instantly share code, notes, and snippets.

@weskerty
Last active February 23, 2026 21:53
Show Gist options
  • Select an option

  • Save weskerty/1f95be17b58a27c8b5baf147c456af04 to your computer and use it in GitHub Desktop.

Select an option

Save weskerty/1f95be17b58a27c8b5baf147c456af04 to your computer and use it in GitHub Desktop.
View System Info ant Tools Version
const { bot } = require('../lib');
const os = require('os');
const { exec } = require('child_process');
const fs = require('fs').promises;
const util = require('util');
const path = require('path');
const execAsync = util.promisify(exec);
class FastFetchDownloader {
constructor() {
this.config = {
binPath: path.join(process.cwd(), 'media', 'bin'),
};
this.fastfetchBinaries = new Map([
['linux-x64', {
url: 'https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-amd64.tar.gz',
relativePath: 'fastfetch-linux-amd64/usr/bin/fastfetch',
}],
['linux-arm64', {
url: 'https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-aarch64.tar.gz',
relativePath: 'fastfetch-linux-aarch64/usr/bin/fastfetch',
}],
['win32-x64', {
url: 'https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-windows-amd64.zip',
relativePath: 'fastfetch-windows-amd64/fastfetch.exe',
}],
]);
}
getPlatformInfo() {
let platform = os.platform();
let arch = os.arch();
if (platform === 'android') {
platform = 'android';
arch = arch === 'arm64' ? 'arm64' : 'x64';
} else if (platform === 'linux') {
arch = (arch === 'arm64' || arch === 'aarch64') ? 'arm64' : 'x64';
} else if (platform === 'win32') {
arch = 'x64';
}
return { platform, arch };
}
async tryInstallFromPackageManager() {
const { platform } = this.getPlatformInfo();
try {
if (platform === 'android') {
await execAsync('pkg update -y && pkg install fastfetch -y');
return true;
} else if (platform === 'linux') {
await execAsync('sudo apt update && sudo apt install fastfetch -y');
return true;
}
} catch {
return false;
}
return false;
}
async downloadAndExtractFastFetch() {
const { platform, arch } = this.getPlatformInfo();
const key = `${platform === 'android' ? 'linux' : platform}-${arch}`;
const binary = this.fastfetchBinaries.get(key);
if (!binary) throw new Error(`Unsupported System: ${key}`);
await fs.mkdir(this.config.binPath, { recursive: true });
const downloadPath = path.join(this.config.binPath, path.basename(binary.url));
const extractPath = this.config.binPath;
await execAsync(`curl -fsSL -o "${downloadPath}" "${binary.url}"`);
if (platform === 'win32') {
await execAsync(`powershell -Command "Expand-Archive -Path '${downloadPath}' -DestinationPath '${extractPath}' -Force"`);
} else {
await execAsync(`tar xf "${downloadPath}" -C "${extractPath}"`);
}
const binaryPath = path.join(this.config.binPath, binary.relativePath);
if (platform !== 'win32') await fs.chmod(binaryPath, '755');
await fs.unlink(downloadPath);
return binaryPath;
}
async getFastFetchPath() {
try {
const { stdout } = await execAsync('which fastfetch');
if (stdout.trim()) return 'fastfetch';
} catch {}
if (await this.tryInstallFromPackageManager()) return 'fastfetch';
const { platform, arch } = this.getPlatformInfo();
const key = `${platform === 'android' ? 'linux' : platform}-${arch}`;
const binary = this.fastfetchBinaries.get(key);
const localBinaryPath = path.join(this.config.binPath, binary.relativePath);
try {
await fs.access(localBinaryPath);
return localBinaryPath;
} catch {
return await this.downloadAndExtractFastFetch();
}
}
}
async function safeExec(command, fallbackCommand = null) {
try {
const { stdout } = await execAsync(command);
return stdout.trim();
} catch {
if (fallbackCommand) {
try {
const { stdout } = await execAsync(fallbackCommand);
return stdout.trim();
} catch {
return null;
}
}
return null;
}
}
async function runSpeedtest(message) {
try {
const tempDir = process.env.TEMP_DOWNLOAD_DIR || path.join(process.cwd(), 'media');
const speedtestPath = path.join(tempDir, 'bin', 'ookla-speedtest.py');
await fs.mkdir(path.dirname(speedtestPath), { recursive: true });
try {
await fs.access(speedtestPath);
} catch {
const speedtestUrl = 'https://raw.githubusercontent.com/weskerty/MysticTools/refs/heads/main/Utilidades/ookla-speedtest.py';
await execAsync(`curl -fsSL -o "${speedtestPath}" "${speedtestUrl}"`);
await execAsync(`chmod +x ${speedtestPath}`);
}
const stdout = await safeExec(`python3 ${speedtestPath} --secure --share`, `python ${speedtestPath} --secure --share`);
if (!stdout) throw new Error('Failed to run speedtest');
const imageUrlMatch = stdout.match(/http[^"]+\.png/);
if (imageUrlMatch) {
const imageUrl = imageUrlMatch[0];
const fetch = (await import('node-fetch')).default;
const response = await fetch(imageUrl);
const imageBuffer = Buffer.from(await response.arrayBuffer());
await message.send(
imageBuffer,
{ fileName: 'speedtest_result.png', mimetype: 'image/png', caption: stdout },
'image'
);
} else {
await message.send(stdout);
}
return stdout;
} catch (error) {
return '❌ Error Speedtest';
}
}
async function getSoftwareVersions() {
const versions = [];
const sudoCheck = await safeExec('which sudo');
versions.push(`*Sudo* ${sudoCheck ? 'βœ…' : 'βœ–'}`);
const checks = [
{ name: 'Node.js', command: 'node -v', emoji: '🟒' },
{ name: 'NPM', command: 'npm -v', emoji: 'πŸ“¦' },
{ name: 'Python', command: 'python3 --version', fallback: 'python --version', emoji: '🐍' },
{ name: 'Chocolatey', command: 'choco --version', emoji: '🍫' },
{ name: 'FFmpeg', command: 'ffmpeg -version', emoji: '🎬', process: (out) => out.split('\n')[0] }
];
const pipOutput = await safeExec('pip3 --version', 'pip --version');
let pipVersion = 'βœ–';
if (pipOutput) {
const pipMatch = pipOutput.match(/pip\s+(\d+\.\d+\.\d+)/);
pipVersion = pipMatch ? pipMatch[1] : pipOutput;
}
versions.push(`πŸ“Š *PIP:* ${pipVersion}`);
for (const check of checks) {
const output = await safeExec(check.command, check.fallback);
const value = output ? (check.process ? check.process(output) : output) : 'βœ–';
versions.push(`${check.emoji} *${check.name}:* ${value}`);
}
return versions.join('\n');
}
bot(
{
pattern: 'sysinfo ?(.*)',
fromMe: true,
desc: 'All System Server Info',
type: 'machine',
},
async (message, match) => {
try {
const allMode = match && match.trim() === '--all';
const fastFetchPath = await new FastFetchDownloader().getFastFetchPath();
const ffCmd = allMode
? `"${fastFetchPath}" -l none -c all`
: `"${fastFetchPath}" -l none`;
const sysInfo = await safeExec(ffCmd);
if (sysInfo) await message.send(sysInfo);
else throw new Error('Failed to get system information');
const softwareVersions = await getSoftwareVersions();
await message.send(softwareVersions);
await runSpeedtest(message);
} catch (error) {
await message.send(`❌ ${error.message}`);
}
}
);
module.exports = { FastFetchDownloader };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment