// code from goatstore // api: https://store.agi.bd const fs = require("fs"); const path = require("path"); const os = require("os"); module.exports = { config: { name: "up", version: "5.0.0", author: "๐Œ๐š๐‘๐ฎ๐… โ†’ Goat Bot V2", countDown: 5, role: 0, shortDescription: { en: "Show bot uptime and system information" }, longDescription: { en: "Shows uptime, response time, CPU, RAM, disk and system information." }, category: "system", guide: { en: "{pn}" }, aliases: ["uptime"] }, onStart: async function ({ api, event }) { const startTime = Date.now(); let filePath = null; try { // ========================================== // LOAD CANVAS // ========================================== let createCanvas; try { ({ createCanvas } = require("canvas")); } catch (err) { console.error("โŒ Canvas package error:", err); return api.sendMessage( "โŒ | Canvas package เฆชเฆพเฆ“เงŸเฆพ เฆฏเฆพเฆšเงเฆ›เง‡ เฆจเฆพ!\n\n" + "เฆเฆ‡ command เฆšเฆพเฆฒเฆพเฆคเง‡ Node.js canvas package เฆฒเฆพเฆ—เฆฌเง‡เฅค\n\n" + "Error: " + err.message, event.threadID, event.messageID ); } // ========================================== // FORMAT UPTIME // ========================================== function formatUptime(seconds) { seconds = Math.floor(seconds); const days = Math.floor(seconds / 86400); seconds %= 86400; const hours = Math.floor(seconds / 3600); seconds %= 3600; const minutes = Math.floor(seconds / 60); const secs = seconds % 60; const result = []; if (days > 0) result.push(`${days}d`); if (hours > 0) result.push(`${hours}h`); if (minutes > 0) result.push(`${minutes}m`); result.push(`${secs}s`); return result.join(" "); } // ========================================== // CPU USAGE // ========================================== function getCPUUsage() { try { const cpus = os.cpus(); if (!cpus || !cpus.length) return 0; let idle = 0; let total = 0; for (const cpu of cpus) { const times = cpu.times; idle += times.idle; total += times.user + times.nice + times.sys + times.idle + times.irq; } if (!total) return 0; return Math.max( 0, Math.min( 100, 100 - (idle / total) * 100 ) ); } catch (e) { return 0; } } // ========================================== // DISK USAGE // ========================================== function getDiskUsage() { try { if (typeof fs.statfsSync !== "function") { return { used: 0, total: 0, percent: 0 }; } const stat = fs.statfsSync("/"); const total = Number(stat.blocks) * Number(stat.bsize); const free = Number(stat.bfree) * Number(stat.bsize); const used = Math.max( 0, total - free ); const percent = total > 0 ? (used / total) * 100 : 0; return { used, total, percent }; } catch (e) { return { used: 0, total: 0, percent: 0 }; } } // ========================================== // ROUND RECTANGLE // ========================================== function roundRect( ctx, x, y, width, height, radius ) { ctx.beginPath(); ctx.moveTo( x + radius, y ); ctx.lineTo( x + width - radius, y ); ctx.quadraticCurveTo( x + width, y, x + width, y + radius ); ctx.lineTo( x + width, y + height - radius ); ctx.quadraticCurveTo( x + width, y + height, x + width - radius, y + height ); ctx.lineTo( x + radius, y + height ); ctx.quadraticCurveTo( x, y + height, x, y + height - radius ); ctx.lineTo( x, y + radius ); ctx.quadraticCurveTo( x, y, x + radius, y ); ctx.closePath(); } // ========================================== // CIRCLE // ========================================== function circle( ctx, x, y, radius, color, alpha = 1 ) { ctx.save(); ctx.globalAlpha = alpha; ctx.fillStyle = color; ctx.beginPath(); ctx.arc( x, y, radius, 0, Math.PI * 2 ); ctx.fill(); ctx.restore(); } // ========================================== // SPARKLE // ========================================== function sparkle( ctx, x, y, size, color ) { ctx.save(); ctx.fillStyle = color; ctx.beginPath(); ctx.moveTo( x, y - size ); ctx.lineTo( x + size * 0.3, y - size * 0.3 ); ctx.lineTo( x + size, y ); ctx.lineTo( x + size * 0.3, y + size * 0.3 ); ctx.lineTo( x, y + size ); ctx.lineTo( x - size * 0.3, y + size * 0.3 ); ctx.lineTo( x - size, y ); ctx.lineTo( x - size * 0.3, y - size * 0.3 ); ctx.closePath(); ctx.fill(); ctx.restore(); } // ========================================== // CLOUD // ========================================== function cloud( ctx, x, y, scale = 1 ) { ctx.save(); ctx.fillStyle = "#FFFFFF"; ctx.globalAlpha = 0.65; ctx.beginPath(); ctx.arc( x, y + 20 * scale, 28 * scale, 0, Math.PI * 2 ); ctx.arc( x + 35 * scale, y, 38 * scale, 0, Math.PI * 2 ); ctx.arc( x + 75 * scale, y + 20 * scale, 30 * scale, 0, Math.PI * 2 ); ctx.fill(); ctx.restore(); } // ========================================== // CANVAS // ========================================== const WIDTH = 1280; const HEIGHT = 760; const canvas = createCanvas( WIDTH, HEIGHT ); const ctx = canvas.getContext("2d"); // ========================================== // BACKGROUND // ========================================== const background = ctx.createLinearGradient( 0, 0, WIDTH, HEIGHT ); background.addColorStop( 0, "#E8F6FF" ); background.addColorStop( 0.5, "#F1ECFF" ); background.addColorStop( 1, "#FFF0F6" ); ctx.fillStyle = background; ctx.fillRect( 0, 0, WIDTH, HEIGHT ); // ========================================== // DECORATION // ========================================== cloud(ctx, 70, 70, 1); cloud(ctx, 1010, 70, 1.2); cloud(ctx, 1100, 285, 0.55); circle( ctx, 110, 300, 55, "#D7C8FF", 0.22 ); circle( ctx, 1180, 500, 75, "#B9DFF7", 0.22 ); circle( ctx, 1010, 580, 45, "#F4C7D9", 0.25 ); sparkle( ctx, 1050, 180, 10, "#BDA9EE" ); sparkle( ctx, 180, 180, 7, "#9FCBE8" ); sparkle( ctx, 1125, 330, 6, "#DCA7BE" ); // ========================================== // MAIN PANEL // ========================================== ctx.save(); ctx.shadowColor = "rgba(80, 65, 110, 0.18)"; ctx.shadowBlur = 40; ctx.shadowOffsetY = 18; roundRect( ctx, 65, 55, 1150, 650, 48 ); const panel = ctx.createLinearGradient( 65, 55, 1215, 705 ); panel.addColorStop( 0, "rgba(255,255,255,0.96)" ); panel.addColorStop( 1, "rgba(255,249,253,0.92)" ); ctx.fillStyle = panel; ctx.fill(); ctx.restore(); // ========================================== // HEADER // ========================================== ctx.fillStyle = "#443A5B"; ctx.font = "bold 42px Sans"; ctx.fillText( "UPTIME", 115, 125 ); ctx.fillStyle = "#9389A6"; ctx.font = "17px Sans"; ctx.fillText( "Live system information", 118, 153 ); circle( ctx, 1080, 115, 9, "#AFA0E2" ); ctx.fillStyle = "#817797"; ctx.font = "bold 13px Sans"; ctx.fillText( "ONLINE", 1100, 120 ); // ========================================== // HERO BOX // ========================================== const heroX = 115; const heroY = 185; const heroW = 1050; const heroH = 165; ctx.save(); ctx.shadowColor = "rgba(100, 85, 140, 0.13)"; ctx.shadowBlur = 25; ctx.shadowOffsetY = 10; roundRect( ctx, heroX, heroY, heroW, heroH, 38 ); const hero = ctx.createLinearGradient( heroX, heroY, heroX + heroW, heroY + heroH ); hero.addColorStop( 0, "#DDF3FF" ); hero.addColorStop( 0.5, "#EDE6FF" ); hero.addColorStop( 1, "#FFE7F0" ); ctx.fillStyle = hero; ctx.fill(); ctx.restore(); ctx.fillStyle = "#817596"; ctx.font = "bold 15px Sans"; ctx.fillText( "BOT RUNNING FOR", 155, 228 ); ctx.fillStyle = "#403652"; ctx.font = "bold 48px Sans"; ctx.fillText( formatUptime(process.uptime()), 155, 282 ); ctx.fillStyle = "#9489A7"; ctx.font = "16px Sans"; ctx.fillText( "process uptime", 158, 313 ); circle( ctx, 1030, 260, 50, "#FFFFFF", 0.55 ); circle( ctx, 1080, 285, 32, "#FFFFFF", 0.42 ); circle( ctx, 990, 290, 25, "#FFFFFF", 0.35 ); sparkle( ctx, 1075, 230, 9, "#B39DEB" ); // ========================================== // SYSTEM DATA // ========================================== const responseTime = Date.now() - startTime; const cpu = getCPUUsage(); const totalMemory = os.totalmem(); const freeMemory = os.freemem(); const usedMemory = Math.max( 0, totalMemory - freeMemory ); const ramPercent = totalMemory > 0 ? (usedMemory / totalMemory) * 100 : 0; const disk = getDiskUsage(); // ========================================== // INFO CARDS // ========================================== const cards = [ { x: 115, title: "RESPONSE", value: `${responseTime} ms`, bg: "#FFF0E5", dot: "#E8AE80", bottom: "current value" }, { x: 380, title: "CPU", value: `${cpu.toFixed(1)}%`, bg: "#EAE5FF", dot: "#9E8BD7", bottom: "processor usage" }, { x: 645, title: "RAM", value: `${ramPercent.toFixed(1)}%`, bg: "#E4F3FF", dot: "#82B8D8", bottom: `${Math.round( usedMemory / 1024 / 1024 )} MB used` }, { x: 910, title: "DISK", value: `${disk.percent.toFixed(1)}%`, bg: "#FFE8F0", dot: "#D89AB4", bottom: `${Math.round( disk.used / 1024 / 1024 / 1024 )} GB used` } ]; for (const card of cards) { ctx.save(); ctx.shadowColor = "rgba(100, 85, 125, 0.09)"; ctx.shadowBlur = 18; ctx.shadowOffsetY = 9; roundRect( ctx, card.x, 385, 235, 120, 30 ); ctx.fillStyle = card.bg; ctx.fill(); ctx.restore(); circle( ctx, card.x + 28, 415, 6, card.dot ); ctx.fillStyle = "#827791"; ctx.font = "bold 12px Sans"; ctx.fillText( card.title, card.x + 43, 420 ); ctx.fillStyle = "#463B58"; ctx.font = "bold 27px Sans"; ctx.fillText( card.value, card.x + 25, 463 ); ctx.fillStyle = "#A39AAD"; ctx.font = "12px Sans"; ctx.fillText( card.bottom, card.x + 25, 486 ); } // ========================================== // DETAILS // ========================================== const details = [ [ "PLATFORM", process.platform ], [ "NODE", process.version ], [ "CORES", String(os.cpus().length) ], [ "LOAD", typeof os.loadavg === "function" ? (os.loadavg()[0] || 0).toFixed(2) : "0.00" ] ]; details.forEach( (item, index) => { const x = 115 + index * 265; ctx.fillStyle = "#978CA9"; ctx.font = "bold 11px Sans"; ctx.fillText( item[0], x, 548 ); ctx.fillStyle = "#554967"; ctx.font = "bold 17px Sans"; ctx.fillText( item[1], x, 578 ); } ); // ========================================== // BOTTOM DECORATION // ========================================== ctx.save(); ctx.globalAlpha = 0.8; ctx.fillStyle = "#D9CEFA"; ctx.beginPath(); ctx.ellipse( 135, 650, 70, 25, -0.15, 0, Math.PI * 2 ); ctx.fill(); ctx.fillStyle = "#C9E7FA"; ctx.beginPath(); ctx.ellipse( 235, 660, 100, 27, 0.12, 0, Math.PI * 2 ); ctx.fill(); ctx.fillStyle = "#F4D4E0"; ctx.beginPath(); ctx.ellipse( 1090, 650, 95, 26, -0.1, 0, Math.PI * 2 ); ctx.fill(); ctx.restore(); sparkle( ctx, 320, 630, 6, "#B5A3E9" ); sparkle( ctx, 930, 625, 8, "#D9A8BE" ); // ========================================== // DATE & TIME // ========================================== const now = new Date(); const dateText = now.toLocaleDateString( "en-GB", { day: "2-digit", month: "short", year: "numeric" } ); const timeText = now.toLocaleTimeString( "en-US", { hour: "2-digit", minute: "2-digit", second: "2-digit" } ); ctx.fillStyle = "#A097A9"; ctx.font = "12px Sans"; ctx.fillText( `${dateText} โ€ข ${timeText}`, 115, 670 ); // ========================================== // SAVE IMAGE // ========================================== filePath = path.join( __dirname, `uptime_${Date.now()}.png` ); const buffer = canvas.toBuffer("image/png"); fs.writeFileSync( filePath, buffer ); console.log( `โœ… Uptime image created: ${filePath}` ); // ========================================== // SEND IMAGE // ========================================== await api.sendMessage( { body: "", attachment: fs.createReadStream( filePath ) }, event.threadID, event.messageID ); console.log( "โœ… Uptime image sent successfully" ); // ========================================== // DELETE FILE // ========================================== setTimeout(() => { try { if ( filePath && fs.existsSync(filePath) ) { fs.unlinkSync(filePath); console.log( "๐Ÿ—‘๏ธ Uptime image deleted" ); } } catch (e) { console.error( "โŒ Could not delete uptime image:", e.message ); } }, 5000); } catch (error) { // ========================================== // ERROR // ========================================== console.error( "\nโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" ); console.error( "โŒ [UP COMMAND ERROR]" ); console.error( error ); console.error( "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n" ); // Delete file if created if (filePath) { try { if ( fs.existsSync(filePath) ) { fs.unlinkSync(filePath); } } catch (e) {} } // Send error try { await api.sendMessage( "โŒ | Uptime command failed!\n\n" + `Error: ${error.message}`, event.threadID, event.messageID ); } catch (sendError) { console.error( "โŒ Could not send error message:", sendError ); } } } };