Last active
February 23, 2026 21:53
-
-
Save weskerty/1f95be17b58a27c8b5baf147c456af04 to your computer and use it in GitHub Desktop.
View System Info ant Tools Version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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