// code from goatstore // api: https://store.agi.bd module.exports.config = { name: "status", version: "1.0.0", author: "Zihad", countDown: 5, role: 2, shortDescription: "Server status notification", longDescription: "Automatically sends server online/recovery notifications.", category: "system", guide: { en: "{pn} on | {pn} off | {pn} test" } }; const fs = require("fs"); const path = require("path"); const DATA_FILE = path.join(__dirname, "status_data.json"); // কত মিনিট পরপর check করবে const CHECK_MINUTES = 2; // Runtime state let timer = null; let started = false; function loadData() { try { if (!fs.existsSync(DATA_FILE)) { fs.writeFileSync( DATA_FILE, JSON.stringify({ enabled: true, threads: [] }, null, 2) ); } return JSON.parse(fs.readFileSync(DATA_FILE, "utf8")); } catch (e) { return { enabled: true, threads: [] }; } } function saveData(data) { try { fs.writeFileSync( DATA_FILE, JSON.stringify(data, null, 2) ); } catch (e) {} } async function sendStatus(api, threadID, message) { try { await api.sendMessage(message, threadID); } catch (e) {} } function startMonitor(api) { if (started) return; started = true; const check = async () => { const data = loadData(); if (!data.enabled || !data.threads.length) return; const uptime = process.uptime(); const days = Math.floor(uptime / 86400); const hours = Math.floor((uptime % 86400) / 3600); const minutes = Math.floor((uptime % 3600) / 60); const seconds = Math.floor(uptime % 60); let uptimeText = ""; if (days > 0) uptimeText += `${days}d `; if (hours > 0) uptimeText += `${hours}h `; if (minutes > 0) uptimeText += `${minutes}m `; uptimeText += `${seconds}s`; const message = `╭━━〔 🟢 SERVER ONLINE 〕━━╮ ┃ ┃ 🤖 Bot Status : ONLINE ┃ ⚡ Server : RUNNING ┃ ⏱️ Uptime : ${uptimeText} ┃ ┃ 🔄 Auto Status Monitor ┃ 👤 Author : Zihad ┃ ╰━━━━━━━━━━━━━━━━━━━━━━╯`; // প্রথমবার monitor শুরু হলে শুধু status save করবে // প্রতিবার message পাঠাবে না if (!data.lastStatus) { data.lastStatus = "online"; saveData(data); return; } // Restart হলে online notification if (data.lastStatus === "offline") { for (const threadID of data.threads) { await sendStatus(api, threadID, message); } data.lastStatus = "online"; saveData(data); } }; // Bot চালু হওয়ার কিছুক্ষণ পর প্রথম check setTimeout(check, 10000); // এরপর নির্দিষ্ট সময় পরপর timer = setInterval( check, CHECK_MINUTES * 60 * 1000 ); } module.exports.onStart = async function ({ api, event, args }) { const threadID = event.threadID; const data = loadData(); const command = args[0] ? args[0].toLowerCase() : "on"; // ON if (command === "on") { if (!data.threads.includes(threadID)) { data.threads.push(threadID); } data.enabled = true; saveData(data); startMonitor(api); return api.sendMessage( `╭━━〔 🔔 STATUS MONITOR 〕━━╮ ┃ ┃ ✅ Auto notification : ON ┃ ┃ 🤖 Server status monitor ┃ 🔄 Automatic recovery alert ┃ ⏱️ Check interval : ${CHECK_MINUTES} min ┃ ┃ এখন থেকে server restart ┃ হলে notification আসবে। ┃ ╰━━━━━━━━━━━━━━━━━━━━━━╯`, threadID ); } // OFF if (command === "off") { data.threads = data.threads.filter( id => id !== threadID ); saveData(data); return api.sendMessage( `╭━━〔 🔕 STATUS MONITOR 〕━━╮ ┃ ┃ ❌ Auto notification : OFF ┃ ┃ এই গ্রুপে আর status ┃ notification আসবে না। ┃ ╰━━━━━━━━━━━━━━━━━━━━━━╯`, threadID ); } // TEST if (command === "test") { return api.sendMessage( `╭━━〔 🟢 SERVER STATUS 〕━━╮ ┃ ┃ 🤖 Bot : ONLINE ┃ ⚡ Server : RUNNING ┃ 👤 Author : Zihad ┃ ┃ ✅ Status system working! ┃ ╰━━━━━━━━━━━━━━━━━━━━━━╯`, threadID ); } return api.sendMessage( `╭━━〔 📖 STATUS HELP 〕━━╮ ┃ ┃ ${global.GoatBot?.config?.prefix || ""}status on ┃ ${global.GoatBot?.config?.prefix || ""}status off ┃ ${global.GoatBot?.config?.prefix || ""}status test ┃ ╰━━━━━━━━━━━━━━━━━━━━━━╯`, threadID ); }; // Bot restart হলে monitor আবার চালু module.exports.onLoad = async function ({ api }) { startMonitor(api); };