// code from goatstore // api: https://store.agi.bd const fs = require("fs"); const { downloadVideo } = require("sagor-video-downloader"); module.exports = { config: { name: "autolink", version: "2.2.0", author: "ᴍᴇʜᴇᴅɪ × Maisha", countDown: 5, role: 0, shortDescription: "Auto-download & send videos (Fastest + Real Loading Animation)", category: "media", }, onStart: async function () {}, onChat: async function ({ api, event }) { const threadID = event.threadID; const message = event.body || ""; const linkMatches = message.match(/(https?:\/\/[^\s]+)/g); if (!linkMatches || linkMatches.length === 0) return; const uniqueLinks = [...new Set(linkMatches)]; // 〽️ React to the original message if (event.messageID && typeof api.setMessageReaction === "function") { try { api.setMessageReaction("〽️", event.messageID, () => {}, true); } catch {} } for (const url of uniqueLinks) { let filePath = null; let loadingMessageID = null; let stopTyping = null; let animationInterval = null; let isDownloading = true; try { // 🔥 Typing Indicator if (typeof api.sendTypingIndicator === "function") { try { stopTyping = await api.sendTypingIndicator(threadID); } catch {} } // Send Initial Loading Message (Stylish) const loadingMsg = await new Promise((resolve, reject) => { api.sendMessage( { body: "🌸 𝐌𝐚𝐢𝐬𝐡𝐚 𝐋𝐨𝐚𝐝𝐢𝐧𝐠. 🌸" }, threadID, (err, info) => { if (err) reject(err); else resolve(info); } ); }); if (loadingMsg && loadingMsg.messageID) { loadingMessageID = loadingMsg.messageID; } // 🎬 Real Loading Animation (Stylish + dots rotating) const frames = [ "🌸 𝐌𝐚𝐢𝐬𝐡𝐚 𝐋𝐨𝐚𝐝𝐢𝐧𝐠. 🌸", "🌸 𝐌𝐚𝐢𝐬𝐡𝐚 𝐋𝐨𝐚𝐝𝐢𝐧𝐠.. 🌸", "🌸 𝐌𝐚𝐢𝐬𝐡𝐚 𝐋𝐨𝐚𝐝𝐢𝐧𝐠... 🌸", "🌸 𝐌𝐚𝐢𝐬𝐡𝐚 𝐋𝐨𝐚𝐝𝐢𝐧𝐠.... 🌸", "🌸 𝐌𝐚𝐢𝐬𝐡𝐚 𝐋𝐨𝐚𝐝𝐢𝐧𝐠..... 🌸", "🌸 𝐌𝐚𝐢𝐬𝐡𝐚 𝐋𝐨𝐚𝐝𝐢𝐧𝐠...... 🌸", "🌸 𝐌𝐚𝐢𝐬𝐡𝐚 𝐋𝐨𝐚𝐝𝐢𝐧𝐠....... 🌸", "🌸 𝐌𝐚𝐢𝐬𝐡𝐚 𝐋𝐨𝐚𝐝𝐢𝐧𝐠........ 🌸" ]; let frameIndex = 0; if (loadingMessageID && typeof api.editMessage === "function") { animationInterval = setInterval(async () => { if (!isDownloading) return; frameIndex = (frameIndex + 1) % frames.length; try { await new Promise((resolve) => { api.editMessage(frames[frameIndex], loadingMessageID, () => resolve()); }); } catch {} }, 400); } // ⚡ Fastest Download const result = await downloadVideo(url); filePath = result?.filePath; // Download শেষ → অ্যানিমেশন বন্ধ isDownloading = false; if (animationInterval) { clearInterval(animationInterval); animationInterval = null; } if (!filePath || !fs.existsSync(filePath)) { throw new Error("Video file not found"); } const stats = fs.statSync(filePath); const fileSizeInMB = stats.size / (1024 * 1024); // ২৫MB এর বেশি হলে স্কিপ if (fileSizeInMB > 25) { if (filePath && fs.existsSync(filePath)) { try { fs.unlinkSync(filePath); } catch {} } filePath = null; if (loadingMessageID && typeof api.unsendMessage === "function") { try { await api.unsendMessage(loadingMessageID); } catch {} } continue; } // ভিডিও পাঠাও await new Promise((resolve, reject) => { api.sendMessage( { body: `🤡 𝐇𝐞𝐫𝐞 𝐃𝐨𝐰𝐧𝐥𝐨𝐚𝐝𝐞𝐝 𝐕𝐢𝐝𝐞𝐨 𓆩♡𓆪𝐄𝐧𝐣𝐨𝐲 𝐖𝐚𝐭𝐜𝐡𝐢𝐧𝐠𓆩♡𓆪 𝐁𝐨𝐭 𝗢𝘄𝗻𝗲𝗿 ♡𝐌𝙴ʜ𝐄ᴅ𝐈♡ `, attachment: fs.createReadStream(filePath) }, threadID, (err) => { if (filePath && fs.existsSync(filePath)) { try { fs.unlinkSync(filePath); } catch {} } filePath = null; if (err) reject(err); else resolve(); } ); }); // ✅ সফল হলে লোডিং মেসেজ আনসেন্ড করো if (loadingMessageID && typeof api.unsendMessage === "function") { try { await api.unsendMessage(loadingMessageID); } catch {} } } catch (error) { isDownloading = false; if (animationInterval) { clearInterval(animationInterval); animationInterval = null; } if (filePath && fs.existsSync(filePath)) { try { fs.unlinkSync(filePath); } catch {} } if (loadingMessageID && typeof api.unsendMessage === "function") { try { await api.unsendMessage(loadingMessageID); } catch {} } } finally { if (typeof stopTyping === "function") { try { stopTyping(); } catch {} } } } } };