// code from goatstore // api: https://store.agi.bd const fs = require("fs"); const path = require("path"); const os = require("os"); const axios = require("axios"); const API_BASE = "https://eryxenx.agi.bd/api/alldl"; module.exports = { config: { name: "autolink", version: "4.0.0", author: "EryXenXยปยป๐— ๐—ฎ๐—ฅ๐˜‚๐—™", countDown: 5, role: 0, shortDescription: "Auto-download & send videos silently", category: "media", }, onStart: async function () {}, onChat: async function ({ api, event }) { const threadID = event.threadID; const messageID = event.messageID; const message = event.body || ""; try { const linkMatches = message.match(/(https?:\/\/[^\s]+)/g); if (!linkMatches || linkMatches.length === 0) return; const uniqueLinks = [...new Set(linkMatches)]; const supportedLinks = uniqueLinks.filter(detectPlatform); if (supportedLinks.length === 0) return; try { api.setMessageReaction("๐ŸŽ—๏ธ", messageID, () => {}, true); } catch {} let successCount = 0; let failCount = 0; for (const url of supportedLinks) { const filePath = path.join( os.tmpdir(), `autolink_${Date.now()}_${Math.floor(Math.random() * 1e6)}.mp4` ); try { const response = await axios.get(API_BASE, { params: { url }, responseType: "stream", timeout: 150000, headers: { "User-Agent": "Mozilla/5.0" }, maxContentLength: 25 * 1024 * 1024, maxBodyLength: 25 * 1024 * 1024 }); const contentType = String(response.headers["content-type"] || "").toLowerCase(); if (contentType.includes("json") || contentType.includes("text/") || contentType.includes("html")) { try { response.data.destroy(); } catch {} failCount++; continue; } await new Promise((resolve, reject) => { const writer = fs.createWriteStream(filePath); response.data.pipe(writer); writer.on("finish", resolve); writer.on("error", reject); response.data.on("error", reject); }); if (!fs.existsSync(filePath)) { failCount++; continue; } const stats = fs.statSync(filePath); const fileSizeInMB = stats.size / (1024 * 1024); if (fileSizeInMB < 0.01 || fileSizeInMB > 25) { try { fs.unlinkSync(filePath); } catch {} failCount++; continue; } const title = extractTitleFromHeaders(response.headers) || "Video File"; const platform = detectPlatform(url) || "media"; // ๐ŸŽจ เฆ†เฆชเฆจเฆพเฆฐ เฆšเฆพเฆ“เฆฏเฆผเฆพ style const styledBody = `๐—ฉ๐—ถ๐—ฑ๐—ฒ๐—ผ ๐——๐—ผ๐˜„๐—ป๐—น๐—ผ๐—ฎ๐—ฑ๐—ฒ๐—ฑ โŽฏโŽฏ )๐ŸŽ‰๐ŸŒท โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” ๐ŸŽฌ ๐—ง๐—ถ๐˜๐—น๐—ฒ : ${truncate(title, 40)} ๐Ÿ“ฆ ๐—ฆ๐—ถ๐˜‡๐—ฒ : ${fileSizeInMB.toFixed(2)} MB ๐ŸŒ ๐—ฃ๐—น๐—ฎ๐˜๐—ณ๐—ผ๐—ฟ๐—บ : ${platform.toUpperCase()} ๐Ÿ‘‘ ๐—ข๐˜„๐—ป๐—ฒ๐—ฟ : โŽฏโŽฏ( ๐— ๐—ฎ๐—ฅ๐˜‚๐—™ ๐ŸŽ€๐ŸŒท โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”`; await api.sendMessage( { body: styledBody, attachment: fs.createReadStream(filePath) }, threadID, () => { try { fs.unlinkSync(filePath); } catch {} } ); successCount++; } catch (err) { try { if (fs.existsSync(filePath)) fs.unlinkSync(filePath); } catch {} failCount++; } } const finalReaction = successCount > 0 && failCount === 0 ? "๐ŸŒท" : successCount > 0 ? "โš ๏ธ" : "โŒ"; try { api.setMessageReaction(finalReaction, messageID, () => {}, true); } catch {} } catch (err) { try { api.setMessageReaction("โŒ", messageID, () => {}, true); } catch {} } } }; function detectPlatform(url) { if (/instagram\.com/i.test(url)) return "instagram"; if (/tiktok\.com/i.test(url)) return "tiktok"; if (/facebook\.com|fb\.watch/i.test(url)) return "facebook"; if (/youtube\.com|youtu\.be/i.test(url)) return "youtube"; return null; } function extractTitleFromHeaders(headers) { const disposition = headers["content-disposition"]; if (!disposition) return null; const match = disposition.match(/filename="(.+?)\.mp4"/); return match ? match[1].replace(/_/g, " ") : null; } function truncate(str, n) { return str.length > n ? str.slice(0, n - 1) + "โ€ฆ" : str; }