// code from goatstore // api: https://store.agi.bd const os = require("os"); const { box, dur } = require("../../bot/v3ui.js"); module.exports = { config: { name: "status", aliases: ["botstatus", "health"], version: "3.0", author: "R S Rifat", countDown: 5, role: 2, description: { en: "Live bot health: uptime, connection, memory, database, counters" }, category: "system", guide: { en: "{pn}" } }, onStart: async function ({ api, message, threadsData, usersData }) { const st = (global.GoatBot.stats || { startedAt: Date.now(), events: 0, commands: 0, errors: 0, lastEventAt: 0, perCommand: {} }); let e2ee = "off"; try { if (api.e2ee && typeof api.e2ee.isConnected === "function") e2ee = api.e2ee.isConnected() ? "connected" : "disconnected"; } catch (_) {} let groups = "?", users = "?"; try { groups = (await threadsData.getAll()).length; users = (await usersData.getAll()).length; } catch (_) {} const mem = process.memoryUsage().rss / 1048576, tot = os.totalmem() / 1048576; const top = Object.entries(st.perCommand).sort((a, b) => b[1] - a[1]).slice(0, 3).map(([n, c]) => `${n} (${c})`).join(", ") || "none yet"; const ok = global.statusAccountBot === "good"; const last = st.lastEventAt ? dur((Date.now() - st.lastEventAt) / 1000) + " ago" : "no events yet"; return message.reply(box("📊", "STATUS", [ `◈ Account ⟶ ${ok ? "● good" : "○ " + global.statusAccountBot}`, `◈ E2EE ⟶ ${e2ee}`, `◈ Uptime ⟶ ${dur(process.uptime())}`, `◈ Last event ⟶ ${last}`, `◈ Events ⟶ ${st.events} · Commands ⟶ ${st.commands} · Errors ⟶ ${st.errors}`, `◈ Top commands ⟶ ${top}`, `◈ Memory ⟶ ${mem.toFixed(0)} MB of ${tot.toFixed(0)} MB`, `◈ Database ⟶ ${(global.GoatBot.config.database || {}).type} · ${groups} groups · ${users} users`, `◈ Commands loaded ⟶ ${global.GoatBot.commands.size}`, `◈ Node ⟶ ${process.version}` ].concat(st.lastError ? [`◈ Last error ⟶ ${st.lastError}`] : []))); } };