const moment = require("moment-timezone"); const axios = require("axios"); const fs = require("fs-extra"); const path = require("path"); module.exports.config = { name: "prayerTimer", version: "2.2", role: 0, author: "HR ID OY", description: "নামাজ টাইমে ভিডিও + Random Dua সহ মেসেজ যাবে (Auto-updated Dhaka prayer times)", category: "Utility", guide: "{pn}", countDown: 5, }; if (module.exports.config.author !== "HR ID OY") { console.log("❌ Credit changed! File stopped."); return; } module.exports.onLoad = async function ({ api }) { if (global.prayerTimerInterval) { clearInterval(global.prayerTimerInterval); console.log("♻️ পুরনো Prayer Timer interval বন্ধ করা হলো, নতুন করে শুরু হচ্ছে..."); } const LAT = 23.8103; const LON = 90.4125; const METHOD = 1; const prayerLabels = { Fajr: "🕌 ফজরের নামাজের সময় হয়েছে", Dhuhr: "🕌 যোহরের নামাজের সময় হয়েছে", Asr: "🕌 আসরের নামাজের সময় হয়েছে", Maghrib: "🕌 মাগরিবের নামাজের সময় হয়েছে", Isha: "🕌 এশার নামাজের সময় হয়েছে" }; const jummahLabel = "🕌 জুম্মার নামাজের সময় হয়েছে (Friday)"; const duas = [ "🤲 اللّهُمَّ اغْفِرْ لِي وَارْحَمْنِي\nহে আল্লাহ, আমাকে ক্ষমা করুন ও দয়া করুন", "🤲 رَبِّ زِدْنِي عِلْمًا\nহে আমার রব, আমার জ্ঞান বৃদ্ধি করুন", "🤲 اللّهُمَّ اهْدِنِي الصِّرَاطَ الْمُسْتَقِيمَ\nহে আল্লাহ, আমাকে সরল পথে পরিচালিত করুন", "🤲 رَبَّنَا تَقَبَّلْ مِنَّا\nহে আমাদের রব, আমাদের আমল কবুল করুন", "🤲 اللّهُمَّ ارْزُقْنِي حَلَالًا طَيِّبًا\nহে আল্লাহ, আমাকে হালাল রিযিক দান করুন" ]; let cachedDate = null; let cachedTimes = {}; let sentToday = {}; let isChecking = false; console.log("🕌 Prayer Timer Loaded with Auto Time Update..."); const fetchTodayPrayerTimes = async () => { // ✅ FIX: moment দিয়ে আজকের date নাও, তারপর DD-MM-YYYY format করো const now = moment().tz("Asia/Dhaka"); const today = now.format("DD-MM-YYYY"); if (cachedDate === today) return; try { // ✅ FIX: API-তে date parameter যোগ করা হলো, নইলে ভুল দিনের time আসতে পারে const day = now.format("DD"); const month = now.format("MM"); const year = now.format("YYYY"); const url = `https://api.aladhan.com/v1/timings/${day}-${month}-${year}?latitude=${LAT}&longitude=${LON}&method=${METHOD}`; const res = await axios.get(url, { timeout: 10000 }); const t = res.data.data.timings; // ✅ FIX: trim() করে extra space বা suffix সরানো হলো cachedTimes = { Fajr: t.Fajr.trim().substring(0, 5), Dhuhr: t.Dhuhr.trim().substring(0, 5), Asr: t.Asr.trim().substring(0, 5), Maghrib: t.Maghrib.trim().substring(0, 5), Isha: t.Isha.trim().substring(0, 5) }; cachedDate = today; sentToday = {}; console.log(`✅ ${today} এর নামাজের সময় আপডেট হলো:`, cachedTimes); } catch (err) { console.error("❌ Prayer time fetch করতে সমস্যা হয়েছে:", err.message); } }; const checkPrayer = async () => { if (isChecking) return; isChecking = true; try { await fetchTodayPrayerTimes(); if (!cachedDate || Object.keys(cachedTimes).length === 0) return; // ✅ FIX: সময় তুলনার জন্য Dhaka timezone থেকে HH:mm নেওয়া হচ্ছে const nowDhaka = moment().tz("Asia/Dhaka"); const nowStr = nowDhaka.format("HH:mm"); const today = cachedDate; const isFriday = nowDhaka.day() === 5; console.log(`🕐 এখন Dhaka সময়: ${nowStr}`); // debug এর জন্য, ঠিক হলে সরিয়ে দিতে পারো for (const [prayerName, prayerTime] of Object.entries(cachedTimes)) { const isJummahSlot = isFriday && prayerName === "Dhuhr"; const key = `${today}_${prayerName}`; if (prayerTime === nowStr && !sentToday[key]) { sentToday[key] = true; const timeNow = nowDhaka.format("hh:mm A"); const dateNow = today; const randomDua = duas[Math.floor(Math.random() * duas.length)]; const label = isJummahSlot ? jummahLabel : prayerLabels[prayerName]; const finalMsg = `━━━━━━━━━━━━━━━━━━ ${label} 🕒 সময়: ${timeNow} 📅 তারিখ: ${dateNow} ━━━━━━━━━━━━━━━━━━ 📿 দোয়া: ${randomDua} ◢◤━━━━━━━━━━━━━━━━◥◣ 🤖 ʙᴏᴛ ᴏᴡɴᴇʀ: ʜʀ ɪᴅ ᴏʏ 🤲 সবাই নামাজ আদায় করুন ◥◣━━━━━━━━━━━━━━━━◢◤`; try { const allThreads = await api.getThreadList(100, null, ["INBOX"]); const groupThreads = allThreads.filter(t => t.isGroup); const cacheDir = path.join(__dirname, "cache"); const filePath = path.join(cacheDir, "azan.mp4"); if (!fs.existsSync(cacheDir)) { fs.mkdirSync(cacheDir); } if (!fs.existsSync(filePath)) { const res = await axios({ url: "https://files.catbox.moe/gr8zqw.mp4", method: "GET", responseType: "stream" }); await new Promise((resolve, reject) => { const writer = fs.createWriteStream(filePath); res.data.pipe(writer); writer.on("finish", resolve); writer.on("error", reject); }); } for (const thread of groupThreads) { try { await api.sendMessage({ body: finalMsg, attachment: fs.createReadStream(filePath) }, thread.threadID); } catch (sendErr) { console.error(`❌ ${thread.threadID} তে পাঠাতে সমস্যা:`, sendErr.message); } } console.log(`✅ ${prayerName} এর নামাজ + দোয়া + আজান পাঠানো হয়েছে`); } catch (err) { console.error("❌ Prayer Timer Error:", err.message); } } } } finally { isChecking = false; } }; global.prayerTimerInterval = setInterval(checkPrayer, 30000); checkPrayer(); }; module.exports.onStart = () => {};