// code from goatstore // api: https://store.agi.bd const fs = require("fs"), path = require("path"), os = require("os"); const { box } = require("../../bot/v3ui.js"); module.exports = { config: { name: "diag", aliases: ["selfcheck", "doctor"], version: "3.0", author: "R S Rifat", countDown: 10, role: 2, description: { en: "Self-check: session cookies, config, database, backups, disk, memory" }, category: "system", guide: { en: "{pn}" } }, onStart: async function ({ api, message }) { const R = [], ok = t => R.push("✔ " + t), bad = t => R.push("✖ " + t), warn = t => R.push("⚠ " + t); const cfg = global.GoatBot.config; // session try { const raw = JSON.parse(fs.readFileSync(path.join(process.cwd(), "account.txt"), "utf8")); const names = (Array.isArray(raw) ? raw : []).map(c => c.key || c.name); ["c_user", "xs"].every(n => names.includes(n)) ? ok("Session cookies: c_user + xs present") : bad("Session cookies: c_user/xs missing in account.txt"); } catch (_) { warn("account.txt is not a cookie array (token/other login mode?)"); } try { const id = api.getCurrentUserID(); id ? ok(`Logged in as ${id}`) : bad("No logged-in user ID"); } catch (_) { bad("api.getCurrentUserID failed"); } global.statusAccountBot === "good" ? ok("Account status: good") : bad(`Account status: ${global.statusAccountBot}`); // config (cfg.adminBot || []).length ? ok(`Bot admins: ${cfg.adminBot.length}`) : bad("adminBot is empty in config.json"); cfg.prefix ? ok(`Prefix: ${cfg.prefix}`) : bad("prefix is empty"); // database const dbType = (cfg.database || {}).type; if (dbType === "sqlite") { const f = path.join(process.cwd(), "database", "data", "data.sqlite"); fs.existsSync(f) ? ok(`SQLite: ${(fs.statSync(f).size / 1024).toFixed(0)} KB`) : bad("SQLite file not found"); } else ok(`Database: ${dbType}`); // backups try { const b = require("../../bot/autoBackup.js").list(); b.length ? ok(`Backups: ${b.length}, newest ${((Date.now() - b[0].time) / 3600000).toFixed(1)}h ago`) : warn("No backups yet (use: backup now)"); } catch (_) { warn("Backup module unavailable"); } // system const [maj, min] = process.versions.node.split(".").map(Number); (maj > 20 || (maj === 20 && min >= 17)) ? ok(`Node ${process.version}`) : bad(`Node ${process.version} (need 20.17+)`); try { const s = fs.statfsSync(process.cwd()); const gb = s.bavail * s.bsize / 1073741824; gb > 0.5 ? ok(`Disk free: ${gb.toFixed(1)} GB`) : warn(`Disk free only ${gb.toFixed(2)} GB`); } catch (_) {} const used = 1 - os.freemem() / os.totalmem(); used < 0.9 ? ok(`System memory used: ${(used * 100).toFixed(0)}%`) : warn(`System memory used: ${(used * 100).toFixed(0)}%`); const fails = R.filter(x => x.startsWith("✖")).length; return message.reply(box("🩺", "SELF CHECK", R, fails ? `${fails} problem(s) need attention` : "All good")); } };