// code from goatstore // api: https://store.agi.bd const ADMIN_UID = "61595102226262"; const TIME_ZONE = "Asia/Dhaka"; const awaitingTimeFor = new Set(); let shutdownTimer = null; function parseTime(text) { const match = String(text).trim().match( /^(0?[1-9]|1[0-2]):([0-5]\d)\s*(am|pm)$/i ); if (!match) return null; return { hour: Number(match[1]), minute: Number(match[2]), ampm: match[3].toLowerCase() }; } function delayUntil(hour, minute, ampm) { let targetHour = hour % 12; if (ampm.toLowerCase() === "pm") { targetHour += 12; } const parts = new Intl.DateTimeFormat("en-GB", { timeZone: TIME_ZONE, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23" }).formatToParts(new Date()); const values = Object.fromEntries( parts.map(part => [part.type, part.value]) ); const now = Date.UTC( Number(values.year), Number(values.month) - 1, Number(values.day), Number(values.hour), Number(values.minute), Number(values.second) ); let target = Date.UTC( Number(values.year), Number(values.month) - 1, Number(values.day), targetHour, minute, 0 ); // নির্ধারিত সময় পার হয়ে গেলে পরের দিনের সময় ধরবে if (target <= now) { target += 24 * 60 * 60 * 1000; } return target - now; } function isAdmin(event) { return ( event && String(event.senderID) === ADMIN_UID ); } async function handleIncomingText({ event, message }) { if (!event || !message || typeof event.body !== "string") { return; } if (!isAdmin(event)) { return; } const sender = String(event.senderID); const body = event.body.trim(); // সময় চাওয়ার পরের মেসেজটি সময় হিসেবে পরীক্ষা করবে if (awaitingTimeFor.has(sender)) { const parsed = parseTime(body); if (!parsed) { return message.reply( "❌ সময়ের ফরম্যাট ভুল!\nউদাহরণ: 02:37 am অথবা 04:15 pm\n\nবাতিল করতে: cancel" ); } awaitingTimeFor.delete(sender); if (shutdownTimer) { clearTimeout(shutdownTimer); shutdownTimer = null; } const delay = delayUntil( parsed.hour, parsed.minute, parsed.ampm ); const displayTime = `${String(parsed.hour).padStart(2, "0")}:` + `${String(parsed.minute).padStart(2, "0")} ` + parsed.ampm.toUpperCase(); await message.reply( `✅ Bot off-time সেট হয়েছে!\n` + `🕒 সময়: ${displayTime}\n` + `🇧🇩 বাংলাদেশ সময়\n` + `⏳ নির্ধারিত সময়ে bot process বন্ধ করার চেষ্টা করবে।` ); shutdownTimer = setTimeout(() => { console.log("[offtime] Scheduled shutdown time reached."); process.exit(0); }, delay); return; } if (/^cancel$/i.test(body)) { awaitingTimeFor.delete(sender); return message.reply("✅ Off-time সেট করার অনুরোধ বাতিল করা হয়েছে।"); } if (/^offtime$/i.test(body)) { awaitingTimeFor.add(sender); return message.reply( "⏰ Bot কখন বন্ধ করতে চাও?\n" + "পরের মেসেজে সময় পাঠাও।\n\n" + "উদাহরণ: 02:37 am\n" + "অথবা: 04:15 pm\n\n" + "বাতিল করতে: cancel" ); } } module.exports = { config: { name: "offtime", aliases: ["off"], version: "4.2.0", author: "OpenAI", countDown: 2, role: 2, shortDescription: "Set bot shutdown time", longDescription: "Set a custom daily-clock time to stop the bot process", category: "admin", guide: "{pn}" }, onStart: async function ({ event, message }) { if (!event || !message) return; if (!isAdmin(event)) { return message.reply( "❌ এই কমান্ড ব্যবহার করার অনুমতি তোমার নেই।" ); } awaitingTimeFor.add(String(event.senderID)); return message.reply( "⏰ Bot কখন বন্ধ করতে চাও?\n" + "পরের মেসেজে সময় পাঠাও।\n\n" + "উদাহরণ: 02:37 am\n" + "অথবা: 04:15 pm\n\n" + "বাতিল করতে: cancel" ); }, onChat: async function ({ event, message }) { return handleIncomingText({ event, message }); } };