// code from goatstore // api: https://store.agi.bd const os = require("os"), fs = require("fs"), path = require("path"); const W = 800, H = 450, N = 40, TAU = 6.2832; const K = { cy: "#22d3ee", vi: "#8b5cf6", mg: "#e879f9", gr: "#34d399", am: "#fbbf24", t: "#f1f5f9", d: "#7c8aa5" }; module.exports = { config: { name: "uptime3", version: "1.0", author: "GoatBot", countDown: 10, cooldowns: 10, role: 0, hasPermssion: 0, usePrefix: true, category: "system", commandCategory: "system", description: "Premium PC-style live uptime GIF", shortDescription: { en: "Premium PC-style live uptime GIF" }, longDescription: { en: "Desktop-style system monitor: ticking uptime, per-core CPU, RAM, terminal and network in an animated GIF" }, guide: { en: "{pn}" } }, onStart: async function ({ api, event, message }) { const send = message ? (m => message.reply(m)) : (m => new Promise(r => api.sendMessage(m, event.threadID, (e, i) => r(i || {}), event.messageID))); let createCanvas, GIFEncoder; try { createCanvas = need("canvas").createCanvas; GIFEncoder = need("gifencoder"); } catch (e) { return send("❌ Module install hoyni. Terminal e chalao:\nnpm i canvas gifencoder\n\n" + e.message); } const t0 = Date.now(); const wait = await send("⏳ Generating...").catch(() => ({})); const ping = Math.max(1, Date.now() - t0); const cpu = await cpuUsage(); const tm = os.totalmem(), fm = os.freemem(), mu = process.memoryUsage(); const d = { up: process.uptime(), host: os.uptime(), ping, cores: cpu.cores, cpu: cpu.total, ram: (tm - fm) / tm * 100, heap: mu.heapUsed / mu.heapTotal * 100, rss: mu.rss / tm * 100, used: (tm - fm) / 1073741824, total: tm / 1073741824, heapMB: mu.heapUsed / 1048576, rssMB: mu.rss / 1048576, model: (os.cpus()[0] || {}).model || "Unknown CPU", nCores: os.cpus().length || 1, plat: `${os.type()} ${os.arch()}`, node: process.version, base: Date.now() }; const file = path.join(os.tmpdir(), `uptime3_${Date.now()}.gif`); try { await new Promise((res, rej) => { const enc = new GIFEncoder(W, H), out = fs.createWriteStream(file); enc.createReadStream().pipe(out); out.on("finish", res); out.on("error", rej); enc.start(); enc.setRepeat(0); enc.setDelay(250); enc.setQuality(20); const c = createCanvas(W, H).getContext("2d"); for (let f = 0; f < N; f++) { frame(c, d, f); enc.addFrame(c); } enc.finish(); }); await send({ body: "", attachment: fs.createReadStream(file) }); } catch (e) { console.error(e); await send("❌ GIF error: " + e.message); } finally { try { fs.unlinkSync(file); } catch (e) { } try { if (wait && wait.messageID) api.unsendMessage(wait.messageID); } catch (e) { } } } }; module.exports.run = module.exports.onStart; function need(m) { return require(m); } async function cpuUsage() { const s = () => os.cpus().map(c => ({ i: c.times.idle, t: Object.values(c.times).reduce((x, y) => x + y, 0) })); const a = s(); await new Promise(r => setTimeout(r, 500)); const b = s(); let cores = b.map((x, i) => { const dt = x.t - a[i].t; return dt > 0 ? Math.min(100, Math.max(0, (1 - (x.i - a[i].i) / dt) * 100)) : 0; }); if (!cores.length) cores = [0]; return { cores, total: cores.reduce((x, y) => x + y, 0) / cores.length }; } const fmt = s => { s = Math.floor(s); return `${Math.floor(s / 86400)}d ${Math.floor(s % 86400 / 3600)}h ${Math.floor(s % 3600 / 60)}m ${s % 60}s`; }; const R = (c, x, y, w, h, r) => { c.beginPath(); c.moveTo(x + r, y); c.arcTo(x + w, y, x + w, y + h, r); c.arcTo(x + w, y + h, x, y + h, r); c.arcTo(x, y + h, x, y, r); c.arcTo(x, y, x + w, y, r); c.closePath(); }; const T = (c, s, x, y, z, col, al = "left", b = false, fam = "sans-serif") => { c.font = `${b ? "bold " : ""}${z}px ${fam}`; c.fillStyle = col; c.textAlign = al; c.fillText(String(s), x, y); }; const arc = (c, x, y, r, a, b, w, s) => { c.beginPath(); c.arc(x, y, r, a, b); c.lineWidth = w; c.strokeStyle = s; c.lineCap = "round"; c.stroke(); }; const dot = (c, x, y, r, f) => { c.beginPath(); c.arc(x, y, r, 0, TAU); c.fillStyle = f; c.fill(); }; const lg = (c, x0, y0, x1, y1, a, b) => { const g = c.createLinearGradient(x0, y0, x1, y1); g.addColorStop(0, a); g.addColorStop(1, b); return g; }; const glow = (c, x, y, r, rgb, a) => { const g = c.createRadialGradient(x, y, 0, x, y, r); g.addColorStop(0, `rgba(${rgb},${a})`); g.addColorStop(1, `rgba(${rgb},0)`); c.fillStyle = g; c.fillRect(0, 0, W, H); }; const panel = (c, x, y, w, h, t, fill = "rgba(255,255,255,0.04)") => { R(c, x, y, w, h, 12); c.fillStyle = fill; c.fill(); c.strokeStyle = "rgba(255,255,255,0.08)"; c.lineWidth = 1; c.stroke(); T(c, t, x + 12, y + 18, 10, K.d, "left", true); }; const seg = (c, x, y, w, pct, p, blinkIdx) => { const n = 40, sw = (w - (n - 1) * 2) / n, lit = Math.max(pct > 0 ? 1 : 0, Math.round(pct / 100 * n)), sweep = Math.floor(p * (lit + 8)); for (let i = 0; i < n; i++) { const sx = x + i * (sw + 2); R(c, sx, y, sw, 12, 2); c.fillStyle = i < lit ? `hsl(${190 + i / n * 140},85%,${Math.abs(i - sweep) <= 1 ? 75 : 58}%)` : "rgba(255,255,255,0.07)"; c.fill(); } }; const MON = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; const p2 = n => String(n).padStart(2, "0"); function frame(c, d, f) { const p = f / N, tk = Math.floor(f / 4), upf = d.up + f / 4, upi = Math.floor(d.up) + tk, pu = (Math.sin(p * TAU) + 1) / 2, blink = f % 4 < 2; const now = new Date(d.base + tk * 1000); c.fillStyle = lg(c, 0, 0, W, H, "#05070f", "#0b1020"); c.fillRect(0, 0, W, H); glow(c, 400 + Math.cos(p * TAU) * 280, 120 + Math.sin(p * TAU) * 40, 320, "34,211,238", 0.22); glow(c, 400 - Math.cos(p * TAU) * 280, 380, 320, "139,92,246", 0.25); c.strokeStyle = "rgba(255,255,255,0.03)"; c.lineWidth = 1; for (let x = 0; x < W; x += 40) { c.beginPath(); c.moveTo(x, 0); c.lineTo(x, H); c.stroke(); } for (let y = 0; y < H; y += 40) { c.beginPath(); c.moveTo(0, y); c.lineTo(W, y); c.stroke(); } for (let i = 0; i < 16; i++) dot(c, (i * 97) % W, ((i * 61) % H - p * H * (1 + i % 3) + H * 4) % H, 1 + i % 2, "rgba(150,220,255,0.25)"); c.save(); c.shadowColor = "rgba(0,0,0,0.7)"; c.shadowBlur = 30; R(c, 16, 12, 768, 380, 16); c.fillStyle = "rgba(14,20,38,0.84)"; c.fill(); c.restore(); R(c, 16, 12, 768, 380, 16); c.strokeStyle = "rgba(255,255,255,0.1)"; c.lineWidth = 1; c.stroke(); c.save(); R(c, 16, 12, 768, 380, 16); c.clip(); c.fillStyle = "rgba(255,255,255,0.05)"; c.fillRect(16, 12, 768, 32); c.restore(); dot(c, 34, 28, 5, "#ff5f57"); dot(c, 50, 28, 5, "#febc2e"); dot(c, 66, 28, 5, "#28c840"); T(c, "UPTIME · System Monitor", 400, 32, 12, K.d, "center", true); dot(c, 738, 28, 4, `rgba(52,211,153,${blink ? 1 : 0.25})`); T(c, "LIVE", 770, 32, 10, K.gr, "right", true); panel(c, 28, 54, 215, 330, "UPTIME"); const cx = 135, cy = 165, r = 58, sec = Math.floor(upf % 60); glow2(c, cx, cy, 80); for (let i = 0; i < 60; i++) { const a = -1.5708 + i * TAU / 60, cur = i === sec, r0 = r + 7, r1 = r + (cur ? 18 : i % 5 === 0 ? 15 : 12); c.beginPath(); c.moveTo(cx + Math.cos(a) * r0, cy + Math.sin(a) * r0); c.lineTo(cx + Math.cos(a) * r1, cy + Math.sin(a) * r1); c.lineWidth = cur ? 3 : 2; c.lineCap = "round"; c.strokeStyle = cur ? "#ffffff" : i < sec ? `hsl(${190 + i * 1.33},90%,60%)` : "rgba(255,255,255,0.12)"; c.stroke(); } arc(c, cx, cy, r - 2, 0, TAU, 2, "rgba(34,211,238,0.18)"); c.save(); c.setLineDash([2, 6]); c.lineDashOffset = -p * 32; arc(c, cx, cy, r - 12, 0, TAU, 2, "rgba(139,92,246,0.6)"); c.restore(); const dd = Math.floor(upi / 86400), hh = Math.floor(upi % 86400 / 3600), mm = Math.floor(upi % 3600 / 60), ss = upi % 60; T(c, `${dd} DAYS`, cx, cy - 12, 10, K.d, "center", true); c.shadowColor = K.cy; c.shadowBlur = 10; T(c, `${p2(hh)}:${p2(mm)}:${p2(ss)}`, cx, cy + 9, 20, K.t, "center", true); c.shadowBlur = 0; dot(c, cx - 22, cy + 24, 3, K.gr); T(c, "ONLINE", cx - 14, cy + 28, 10, K.gr, "left", true); c.strokeStyle = "rgba(255,255,255,0.08)"; c.beginPath(); c.moveTo(42, 252); c.lineTo(229, 252); c.stroke(); [["Ping", `${d.ping} ms`], ["Host Up", fmt(d.host + tk)], ["Platform", d.plat], ["Node", d.node], ["Cores", d.nCores]].forEach((v, i) => { T(c, v[0], 42, 272 + i * 22, 10, K.d); T(c, v[1], 229, 272 + i * 22, 11, K.t, "right", true); }); panel(c, 253, 54, 300, 330, "CPU"); T(c, `${d.cpu.toFixed(0)}%`, 541, 78, 16, K.cy, "right", true); c.font = "10px sans-serif"; let mdl = d.model.replace(/\s+/g, " "); while (mdl.length > 3 && c.measureText(mdl).width > 270) mdl = mdl.slice(0, -1); T(c, mdl, 269, 94, 10, K.d); const n = Math.min(d.cores.length, 12), slot = 268 / n, bw = Math.min(26, slot - 6), top = 108, hm = 98; for (let i = 0; i < n; i++) { const x = 269 + i * slot + (slot - bw) / 2, h = Math.max(3, d.cores[i] / 100 * hm), y = top + hm - h; R(c, x, top, bw, hm, 5); c.fillStyle = "rgba(255,255,255,0.06)"; c.fill(); R(c, x, y, bw, h, 5); c.fillStyle = lg(c, 0, top + hm, 0, top, K.vi, K.cy); c.fill(); c.save(); R(c, x, y, bw, h, 5); c.clip(); const by = top + hm - ((p * 2) % 1) * (hm + 14); c.fillStyle = lg(c, 0, by - 7, 0, by + 7, "rgba(255,255,255,0)", "rgba(255,255,255,0.4)"); c.fillRect(x, by - 7, bw, 14); c.restore(); c.fillStyle = "#fff"; c.fillRect(x, y, bw, 2); T(c, i + 1, x + bw / 2, 220, 8, K.d, "center"); } c.save(); c.setLineDash([4, 4]); c.strokeStyle = "rgba(251,191,36,0.6)"; c.lineWidth = 1; c.beginPath(); c.moveTo(269, top + hm - d.cpu / 100 * hm); c.lineTo(537, top + hm - d.cpu / 100 * hm); c.stroke(); c.restore(); c.strokeStyle = "rgba(255,255,255,0.08)"; c.beginPath(); c.moveTo(269, 232); c.lineTo(537, 232); c.stroke(); const pc = v => v < 1 && v > 0 ? v.toFixed(1) : v.toFixed(0); [["RAM", d.ram, `${d.used.toFixed(1)} / ${d.total.toFixed(1)} GB`], ["HEAP", d.heap, `${d.heapMB.toFixed(0)} MB`], ["RSS", d.rss, `${d.rssMB.toFixed(0)} MB`]].forEach((m, i) => { const y = 252 + i * 42; T(c, `${m[0]} ${pc(m[1])}%`, 269, y, 11, K.t, "left", true); T(c, m[2], 537, y, 11, K.d, "right"); seg(c, 269, y + 8, 268, m[1], p); }); panel(c, 563, 54, 209, 182, "TERMINAL", "rgba(0,0,0,0.45)"); const lines = [["$ ", "uptime --status", K.cy], ["uptime : ", `${dd}d ${hh}h ${mm}m ${ss}s`, K.t], ["ping : ", `${d.ping} ms`, K.t], ["cpu : ", `${d.cpu.toFixed(0)}% x${d.nCores}`, K.t], ["ram : ", `${d.ram.toFixed(0)}% ${d.used.toFixed(0)}/${d.total.toFixed(0)}G`, K.t], ["node : ", d.node, K.t], ["status : ", "ONLINE", K.gr]]; let rem = f * 8, cur = null; lines.forEach((l, i) => { const full = l[0] + l[1], vis = Math.max(0, Math.min(full.length, rem)); rem -= full.length; if (vis <= 0 && cur) return; const y = 94 + i * 18, kv = Math.min(l[0].length, vis); c.font = "10px monospace"; T(c, l[0].slice(0, kv), 575, y, 10, i ? K.d : K.gr, "left", false, "monospace"); const kw = c.measureText(l[0]).width; T(c, l[1].slice(0, Math.max(0, vis - l[0].length)), 575 + kw, y, 10, l[2], "left", i === 6, "monospace"); if (vis < full.length || i === 6) { c.font = "10px monospace"; cur = [575 + (vis < full.length ? c.measureText(full.slice(0, vis)).width : c.measureText(full).width) + 3, y]; } }); if (cur && blink) { c.fillStyle = K.cy; c.fillRect(cur[0], cur[1] - 9, 6, 11); } panel(c, 563, 244, 209, 140, "NETWORK"); T(c, `${d.ping} ms`, 760, 262, 14, K.cy, "right", true); const gx = 575, gy = 276, gw = 185, gh = 70, pts = []; c.strokeStyle = "rgba(255,255,255,0.06)"; c.lineWidth = 1; for (let i = 0; i <= 3; i++) { c.beginPath(); c.moveTo(gx, gy + gh * i / 3); c.lineTo(gx + gw, gy + gh * i / 3); c.stroke(); } for (let i = 0; i < 24; i++) { const x = i * 0.6, v = 0.5 + (Math.sin(x * 0.9 + p * TAU) * 0.35 + Math.sin(x * 2.1 + 1 - p * TAU * 2) * 0.2 + Math.sin(x * 0.37 + p * TAU) * 0.25) * 0.5; pts.push([gx + gw * i / 23, gy + gh - (v * 0.8 + 0.1) * gh]); } c.beginPath(); c.moveTo(gx, gy + gh); pts.forEach(q => c.lineTo(q[0], q[1])); c.lineTo(gx + gw, gy + gh); c.closePath(); c.fillStyle = lg(c, 0, gy, 0, gy + gh, "rgba(34,211,238,0.4)", "rgba(34,211,238,0)"); c.fill(); c.beginPath(); pts.forEach((q, i) => i ? c.lineTo(q[0], q[1]) : c.moveTo(q[0], q[1])); c.strokeStyle = K.cy; c.lineWidth = 2; c.lineJoin = "round"; c.shadowColor = K.cy; c.shadowBlur = 8; c.stroke(); c.shadowBlur = 0; const si = Math.min(23, Math.floor(p * 23)); dot(c, pts[si][0], pts[si][1], 4, K.t); T(c, d.ping < 150 ? "Excellent" : d.ping < 400 ? "Good" : "Slow", 575, 372, 11, d.ping < 400 ? K.gr : K.am, "left", true); R(c, 16, 400, 768, 38, 14); c.fillStyle = "rgba(14,20,38,0.88)"; c.fill(); c.strokeStyle = "rgba(255,255,255,0.1)"; c.stroke(); [[32, 410], [41, 410], [32, 419], [41, 419]].forEach((q, i) => { R(c, q[0], q[1], 7, 7, 2); c.fillStyle = i % 2 ? K.vi : K.cy; c.fill(); }); [["Monitor", 64, true], ["Terminal", 154, false]].forEach(a => { R(c, a[1], 405, 82, 28, 8); c.fillStyle = a[2] ? "rgba(255,255,255,0.1)" : "rgba(255,255,255,0.04)"; c.fill(); T(c, a[0], a[1] + 41, 423, 11, a[2] ? K.t : K.d, "center", true); if (a[2]) { c.fillStyle = K.cy; c.fillRect(a[1] + 26, 431, 30, 2); } }); T(c, `CPU ${d.cpu.toFixed(0)}%`, 640, 423, 11, K.d, "right", true); [0, 1, 2, 3].forEach(i => { c.fillStyle = i <= 2 ? K.t : "rgba(255,255,255,0.25)"; c.fillRect(656 + i * 5, 429 - (i + 1) * 4, 3, (i + 1) * 4); }); T(c, now.toLocaleTimeString("en-GB"), 768, 418, 12, K.t, "right", true); T(c, `${p2(now.getDate())} ${MON[now.getMonth()]} ${now.getFullYear()}`, 768, 431, 9, K.d, "right"); } function glow2(c, x, y, r) { const g = c.createRadialGradient(x, y, 0, x, y, r); g.addColorStop(0, "rgba(34,211,238,0.14)"); g.addColorStop(1, "rgba(34,211,238,0)"); c.fillStyle = g; c.fillRect(x - r, y - r, r * 2, r * 2); }