// code from goatstore // api: https://store.agi.bd const os = require("os"); const fs = require("fs"); const http = require("http"); const crypto = require("crypto"); const { execSync } = require("child_process"); // ================= কনফিগ ================= const WEB_PORT = parseInt(process.env.SYSINFO_PORT) || 3099; // হোস্টিংয়ে খোলা পোর্ট দিন const PUBLIC_URL = process.env.SYSINFO_URL || ""; // যেমন: https://myapp.example.com (ফাঁকা থাকলে IP দিয়ে বানাবে) const WEB_LIFETIME_MS = 10 * 60 * 1000; // ওয়েব ড্যাশবোর্ড ১০ মিনিট পর বন্ধ const EDIT_INTERVAL_MS = 3000; // মেসেজ এডিটের ব্যবধান const EDIT_TICKS = 10; // মোট কতবার আপডেট (৩০ সেকেন্ড) // ================= ডাটা সংগ্রহ ================= const fmtBytes = (b) => { const u = ["B", "KB", "MB", "GB", "TB"]; let i = 0; while (b >= 1024 && i < u.length - 1) { b /= 1024; i++; } return b.toFixed(i >= 3 ? 2 : 1) + " " + u[i]; }; const fmtUptime = (s) => { const d = Math.floor(s / 86400), h = Math.floor((s % 86400) / 3600); const m = Math.floor((s % 3600) / 60), sec = Math.floor(s % 60); return `${d}d ${h}h ${m}m ${sec}s`; }; function createSampler() { let prev = os.cpus().map((c) => ({ ...c.times })); let diskCache = null, diskAt = 0; const getDisk = () => { if (diskCache && Date.now() - diskAt < 30000) return diskCache; let r = null; try { if (typeof fs.statfsSync === "function") { const s = fs.statfsSync(process.cwd()); const total = s.blocks * s.bsize; r = { total, used: total - s.bavail * s.bsize }; } } catch (e) {} if (!r) { try { const o = execSync(`df -k "${process.cwd()}" | tail -1`).toString().trim().split(/\s+/); r = { total: parseInt(o[1]) * 1024, used: parseInt(o[2]) * 1024 }; } catch (e) {} } diskCache = r; diskAt = Date.now(); return r; }; return function sample() { const now = os.cpus(); const perCore = now.map((c, i) => { const p = prev[i] || c.times; let total = 0; for (const k in c.times) total += c.times[k] - (p[k] || 0); const idle = c.times.idle - (p.idle || 0); return total > 0 ? Math.max(0, Math.min(100, (1 - idle / total) * 100)) : 0; }); prev = now.map((c) => ({ ...c.times })); const cpu = perCore.length ? perCore.reduce((a, b) => a + b, 0) / perCore.length : 0; const total = os.totalmem(), free = os.freemem(), used = total - free; const disk = getDisk(); return { cpu, perCore, cpuModel: (now[0] ? now[0].model : "Unknown").replace(/\s+/g, " ").trim(), cores: now.length, ramTotal: total, ramUsed: used, ram: (used / total) * 100, diskTotal: disk ? disk.total : 0, diskUsed: disk ? disk.used : 0, disk: disk ? (disk.used / disk.total) * 100 : 0, load: os.loadavg(), platform: `${os.platform()} ${os.arch()}`, node: process.version, botRam: process.memoryUsage().rss, botUptime: process.uptime(), sysUptime: os.uptime(), t: Date.now() }; }; } // ================= মেসেজ-এডিট লাইভ মোড ================= const bar = (p, n = 14) => { const f = Math.round((Math.max(0, Math.min(100, p)) / 100) * n); return "█".repeat(f) + "░".repeat(n - f); }; const icon = (p) => (p < 50 ? "🟢" : p < 80 ? "🟡" : "🔴"); function buildText(s, left) { return ( `🖥️ SYSTEM MONITOR 🔴 LIVE\n` + `━━━━━━━━━━━━━━━━━━\n` + `${icon(s.cpu)} CPU ${bar(s.cpu)} ${s.cpu.toFixed(1)}%\n` + `${icon(s.ram)} RAM ${bar(s.ram)} ${s.ram.toFixed(1)}%\n` + ` ${fmtBytes(s.ramUsed)} / ${fmtBytes(s.ramTotal)}\n` + `${icon(s.disk)} DISK ${bar(s.disk)} ${s.disk.toFixed(1)}%\n` + ` ${fmtBytes(s.diskUsed)} / ${fmtBytes(s.diskTotal)}\n` + `━━━━━━━━━━━━━━━━━━\n` + `⚙️ ${s.cores} cores • load ${s.load.map((x) => x.toFixed(2)).join(" ")}\n` + `🤖 Bot RAM: ${fmtBytes(s.botRam)}\n` + `⏱️ Bot: ${fmtUptime(s.botUptime)}\n` + `🕒 Sys: ${fmtUptime(s.sysUptime)}\n` + (left > 0 ? `\n🔄 আপডেট চলছে... (${left})` : `\n✅ লাইভ শেষ — আবার দেখতে sysinfo লিখুন`) ); } async function runLiveEdit({ message, api }) { const sample = createSampler(); await new Promise((r) => setTimeout(r, 800)); const first = await message.reply(buildText(sample(), EDIT_TICKS)); const mid = first && first.messageID; if (!mid || typeof api.editMessage !== "function") { return message.reply("⚠️ এই বটের লাইব্রেরিতে মেসেজ এডিট সাপোর্ট নেই। ওয়েব লাইভ ড্যাশবোর্ডের জন্য লিখুন: sysinfo web"); } for (let i = EDIT_TICKS - 1; i >= 0; i--) { await new Promise((r) => setTimeout(r, EDIT_INTERVAL_MS)); try { await new Promise((res, rej) => { const out = api.editMessage(buildText(sample(), i), mid, (err) => (err ? rej(err) : res())); if (out && typeof out.then === "function") out.then(res).catch(rej); }); } catch (e) { // এডিট ফেল করলে চুপচাপ থামো return; } } } // ================= ওয়েব লাইভ ড্যাশবোর্ড ================= const HTML = `