// code from goatstore // api: https://store.agi.bd const fs = require("fs-extra"); const axios = require("axios"); const path = require("path"); const messageCache = new Map(); const processedUnsend = new Set(); async function handleResend({ api, event, users }) { const { threadID, messageID, senderID, body, attachments, type } = event; try { const botID = api.getCurrentUserID(); // নিজের মেসেজ ignore if (senderID === botID) return; // ============================== // NORMAL MESSAGE SAVE // ============================== if (type !== "message_unsend") { messageCache.set(messageID, { msgBody: body || "", attachment: attachments || [], senderID, threadID, time: Date.now() }); // Cache limit if (messageCache.size > 5000) { const firstKey = messageCache.keys().next().value; if (firstKey) { messageCache.delete(firstKey); } } return; } // ============================== // UNSEND // ============================== if (type !== "message_unsend") return; if (processedUnsend.has(messageID)) return; processedUnsend.add(messageID); setTimeout(() => { processedUnsend.delete(messageID); }, 60000); const msg = messageCache.get(messageID); if (!msg) { console.log( "[RESEND] Message not found:", messageID ); return; } // ============================== // USER NAME // ============================== let userName = "⎯⎯বাহহহহ মিস্টার বাঁধন বাহহহহ -)🌝🫦"; try { if ( users && typeof users.getName === "function" ) { userName = await users.getName(senderID); } else if ( users && typeof users.getNameUser === "function" ) { userName = await users.getNameUser(senderID); } } catch (e) {} // ============================== // TEXT ONLY // ============================== if ( !msg.attachment || msg.attachment.length === 0 ) { return api.sendMessage( `🕊️ϻꫝɪ֟፝ꜱʜꫝ𓍯_Dekho Nao\n${userName} Remove korche.🍒🐸:\n${msg.msgBody || ""}`, threadID ); } // ============================== // CACHE // ============================== const cacheDir = path.join( __dirname, "cache" ); await fs.ensureDir(cacheDir); const files = []; let count = 0; // ============================== // DOWNLOAD ATTACHMENTS // ============================== for (const attachment of msg.attachment) { if (!attachment?.url) continue; try { count++; let ext = "bin"; try { const url = new URL(attachment.url); const extension = path.extname(url.pathname); if (extension) { ext = extension .replace(".", "") .toLowerCase(); } } catch (e) {} const filePath = path.join( cacheDir, `resend_${Date.now()}_${count}.${ext}` ); const response = await axios.get( attachment.url, { responseType: "arraybuffer", timeout: 60000, maxContentLength: Infinity, maxBodyLength: Infinity } ); await fs.writeFile( filePath, Buffer.from(response.data) ); files.push( fs.createReadStream(filePath) ); // 60 seconds পরে delete setTimeout(async () => { try { await fs.remove(filePath); } catch (e) {} }, 60000); } catch (error) { console.log( "[RESEND] Download error:", error.message ); } } // ============================== // SEND ATTACHMENT // ============================== if (files.length > 0) { return api.sendMessage( { body: `🕊️ϻꫝɪ֟፝ꜱʜꫝ𓍯_Dekho Nao` + `${userName} Remove korche.🍒🐸:\n` + `${msg.msgBody || ""}`, attachment: files }, threadID ); } // ============================== // FALLBACK // ============================== return api.sendMessage( `🕊️ϻꫝɪ֟፝ꜱʜꫝ𓍯_Dekho Nao\n${userName} Remove korche.🍒🐸:\n${msg.msgBody || ""}`, threadID ); } catch (error) { console.error( "[RESEND] Error:", error ); } } module.exports = { config: { name: "resend2", version: "3.1.0", author: "TUHIN → GoatBot V2", countDown: 0, role: 0, description: "Auto resend removed messages", category: "utility" }, // GoatBot V2 installer-এর জন্য onStart: async function () { return; }, // Message listener onChat: async function ({ api, event, users }) { return handleResend({ api, event, users }); } };