// code from goatstore // api: https://store.agi.bd module.exports = { config: { name: "rayhan1", aliases: ["oldclear", "oldmsg", "purgeold"], version: "6.0.0", author: "𝐑𝐀𝐘𝐇𝐀𝐍-𝐒𝐀𝐁𝐁𝐈𝐑", countDown: 10, role: 2, category: "owner", shortDescription: "Delete old bot messages", longDescription: "পুরাতন মেসেজ সহ সব বটের মেসেজ ডিলিট করবে", guide: "{pn} 50 - পুরাতন 50 টা মেসেজ ডিলিট" }, onStart: async function ({ api, event, args }) { const threadID = event.threadID; const botID = api.getCurrentUserID(); let amount = parseInt(args[0]) || 30; if (amount > 200) amount = 200; api.sendMessage(`🧹 | RAYHAN-SABBIR Old Cleaner\n🔍 পুরাতন ${amount} টা মেসেজ খুঁজছি... ⏳`, threadID, async (err, statusMsg) => { try { // পুরাতন history নেওয়া api.getThreadHistory(threadID, amount + 50, undefined, async (err, history) => { if (err) { api.unsendMessage(statusMsg.messageID); return api.sendMessage(`❌ History Error: ${err.error || err.message}\n\n⚠️ বটকে গ্রুপে Admin দাও`, threadID); } // শুধু বটের মেসেজ const botMsgs = history.filter(m => m.senderID == botID); if (botMsgs.length === 0) { api.unsendMessage(statusMsg.messageID); return api.sendMessage("❌ পুরাতন বটের কোনো মেসেজ পাই নাই", threadID); } api.unsendMessage(statusMsg.messageID); api.sendMessage(`✅ ${botMsgs.length} টা পুরাতন মেসেজ পাইছি\n🧹 ডিলিট শুরু করলাম...`, threadID, async (e, info) => { setTimeout(() => api.unsendMessage(info.messageID).catch(()=>{}), 2000); }); let deleted = 0; // পুরাতন থেকে নতুনের দিকে ডিলিট for (let i = botMsgs.length - 1; i >= 0; i--) { if (deleted >= amount) break; try { await api.unsendMessage(botMsgs[i].messageID); deleted++; await new Promise(r => setTimeout(r, 600)); // 0.6s delay } catch (err) { // পুরাতন মেসেজ অনেক সময় unsend fail করে, skip } } return api.sendMessage( `✅ | OLD CLEAR DONE 🔥\n\n` + `👤 Author: 𝐑𝐀𝐘𝐇𝐀𝐍-𝐒𝐀𝐁𝐁𝐈𝐑\n` + `🧹 Total Deleted: ${deleted} টা\n` + `📅 Type: পুরাতন মেসেজ\n\n` + `⚠️ Note: 10 মিনিটের বেশি পুরাতন মেসেজ অনেক সময় ফেসবুক ডিলিট করতে দেয় না`, threadID ); }); } catch (error) { return api.sendMessage(`❌ Error: ${error.message}`, threadID); } }); } };