// code from goatstore // api: https://store.agi.bd const fs = require("fs"); const os = require("os"); const path = require("path"); const axios = require("axios"); module.exports.config = { name: "nt", version: "3.3.0", author: "SAJU ISLAM", role: 2, countDown: 30, description: "Broadcast replied text and media", category: "owner", guide: { en: "Reply to media and type: nt your message" } }; function sendMessage(api, payload, threadID) { return new Promise((resolve, reject) => { api.sendMessage(payload, threadID, (err, info) => { if (err) return reject(err); resolve(info); }); }); } function getThreadList(api) { return new Promise((resolve, reject) => { if (typeof api.getThreadList !== "function") { return reject(new Error("getThreadList is not supported")); } api.getThreadList(100, null, ["INBOX"], (err, list) => { if (err) return reject(err); resolve(Array.isArray(list) ? list : []); }); }); } function getCaption(event, args) { const body = String(event.body || "").trim(); const caption = body.replace(/^nt(?:\s+|$)/i, "").trim(); if (caption) return caption; if (Array.isArray(args)) return args.join(" ").trim(); return ""; } async function downloadAttachments(attachments) { const files = []; try { for (let i = 0; i < attachments.length; i++) { const item = attachments[i]; if (!item || !item.url) continue; const type = String(item.type || "").toLowerCase(); let ext = ".bin"; if (type.includes("video")) ext = ".mp4"; else if (type.includes("audio")) ext = ".mp3"; else if (type.includes("photo") || type.includes("image")) { ext = ".jpg"; } const filePath = path.join( os.tmpdir(), `saju_nt_${Date.now()}_${i}${ext}` ); const response = await axios.get(item.url, { responseType: "stream", timeout: 30000, maxRedirects: 5 }); await new Promise((resolve, reject) => { const output = fs.createWriteStream(filePath); response.data.pipe(output); output.on("finish", resolve); output.on("error", reject); response.data.on("error", reject); }); files.push(filePath); } return files; } catch (err) { for (const file of files) { try { fs.unlinkSync(file); } catch (_) {} } throw err; } } async function main({ api, event, args }) { const currentThread = event.threadID; const reply = event.messageReply; if (!reply) { return sendMessage( api, "╭━━━〔 💗 SAJU NT 〕━━━╮\n" + "┃ ⚠️ কোনো মেসেজ/ভিডিওতে Reply দাও\n" + "┃ তারপর লেখো: nt তোমার মেসেজ\n" + "╰━━━〔 👑 SAJU ISLAM 〕━━━╯", currentThread ); } const caption = getCaption(event, args); const repliedText = String(reply.body || "").trim(); const text = [caption, repliedText] .filter(Boolean) .filter((value, index, arr) => arr.indexOf(value) === index) .join("\n"); const attachments = Array.isArray(reply.attachments) ? reply.attachments : []; if (!text && attachments.length === 0) { return sendMessage( api, "⚠️ Reply করা মেসেজে Text বা Media পাওয়া যায়নি।", currentThread ); } let files = []; let success = 0; let failed = 0; try { files = await downloadAttachments(attachments); const threads = await getThreadList(api); const groupIDs = Array.from(new Set( threads .filter(thread => thread && thread.isGroup && thread.threadID ) .map(thread => String(thread.threadID)) )); if (groupIDs.length === 0) { throw new Error("কোনো group পাওয়া যায়নি।"); } for (const groupID of groupIDs) { try { // প্রথমে ক্যাপশন ও Reply করা টেক্সট পাঠাবে। if (text) { await sendMessage(api, text, groupID); } // এরপর Reply করা ভিডিও/ছবি/অডিও পাঠাবে। for (const file of files) { await sendMessage( api, { attachment: fs.createReadStream(file) }, groupID ); } success++; } catch (err) { failed++; console.error( "[SAJU NT] Group error:", groupID, err.message || err ); } } return sendMessage( api, "╭━━━〔 👾 SAJU NOTI 〕━━━╮\n" + `┃ ✅ সফল: ${success} টি GC\n` + `┃ ❌ ব্যর্থ: ${failed} টি GC\n` + "┃ 👑 Owner: SAJU ISLAM\n" + "╰━━━〔 💗 CYBER CORE 〕━━━╯", currentThread ); } catch (err) { console.error("[SAJU NT ERROR]", err); return sendMessage( api, "❌ NT FAILED\nকারণ: " + (err.message || err), currentThread ); } finally { for (const file of files) { try { fs.unlinkSync(file); } catch (_) {} } } } module.exports.onStart = main; module.exports.run = main;