// code from goatstore // api: https://store.agi.bd const fs = require("fs-extra"); const path = require("path"); const axios = require("axios"); const cache = new Map(); const cacheDir = path.join(__dirname, "cache"); fs.ensureDirSync(cacheDir); // এই UID দুটির মেসেজ Resend হবে না const ignoredUIDs = [ "61594606478715", "61557481486342" ]; module.exports = { config: { name: "resend", version: "5.5", author: "Jihad Hasan", role: 0, category: "events" }, // Default ON onStart: async function () {}, onChat: async function ({ api, event, usersData }) { try { // ========================= // SAVE MESSAGE // ========================= if ( event.type === "message" || event.type === "message_reply" ) { if (!event.messageID) return; // Ignore করা UID-এর মেসেজ cache-এ রাখবে না if ( event.senderID && ignoredUIDs.includes(String(event.senderID)) ) { return; } cache.set(event.messageID, { body: event.body || "", senderID: event.senderID, threadID: event.threadID, attachments: event.attachments || [] }); // Cache limit if (cache.size > 2000) { const firstKey = cache.keys().next().value; cache.delete(firstKey); } return; } // ========================= // UNSEND DETECT // ========================= if (event.type !== "message_unsend") return; const oldMessage = cache.get(event.messageID); if (!oldMessage) return; // ========================= // IGNORE SELECTED UID // ========================= if ( oldMessage.senderID && ignoredUIDs.includes(String(oldMessage.senderID)) ) { cache.delete(event.messageID); return; } // ========================= // USER NAME // ========================= let name = "Unknown User"; try { const user = await usersData.get(oldMessage.senderID); if (user && user.name) name = user.name; } catch (e) {} // ========================= // ORIGINAL MESSAGE // ========================= const originalText = oldMessage.body || "Media"; // ========================= // UNSEND NOTICE // ========================= const notice = `কে কোথায় আছো সবাই দেখো @${name} এই মেসেজটা আনসেন্ড করছে 😁🤧 ᴜɴsᴇɴᴅ ᴍᴇssᴀɢᴇ: ${originalText}`; // ========================= // TEXT ONLY // ========================= if ( !oldMessage.attachments || oldMessage.attachments.length === 0 ) { cache.delete(event.messageID); return api.sendMessage( { body: notice, mentions: [ { tag: `@${name}`, id: oldMessage.senderID } ] }, event.threadID ); } // ========================= // DOWNLOAD MEDIA // ========================= const files = []; for (const attachment of oldMessage.attachments) { try { if (!attachment.url) continue; let ext = ".bin"; if (attachment.type === "photo") ext = ".jpg"; else if (attachment.type === "video") ext = ".mp4"; else if (attachment.type === "audio") ext = ".mp3"; else if (attachment.type === "animated_image") ext = ".gif"; const filePath = path.join( cacheDir, `resend_${Date.now()}_${Math.random() .toString(36) .slice(2)}${ext}` ); const response = await axios.get( attachment.url, { responseType: "arraybuffer", timeout: 30000 } ); await fs.writeFile( filePath, Buffer.from(response.data) ); files.push(filePath); } catch (err) { console.log( "[RESEND MEDIA ERROR]", err.message ); } } // ========================= // SEND MEDIA + MESSAGE // ========================= if (files.length > 0) { const streams = files.map(file => fs.createReadStream(file) ); cache.delete(event.messageID); return api.sendMessage( { body: notice, mentions: [ { tag: `@${name}`, id: oldMessage.senderID } ], attachment: streams }, event.threadID, () => { for (const file of files) { try { if (fs.existsSync(file)) fs.unlinkSync(file); } catch (e) {} } } ); } // ========================= // MEDIA DOWNLOAD FAILED // ========================= cache.delete(event.messageID); return api.sendMessage( { body: notice, mentions: [ { tag: `@${name}`, id: oldMessage.senderID } ] }, event.threadID ); } catch (error) { console.error( "[RESEND ERROR]", error ); } } };