const fs = require("fs"); const { downloadVideo } = require("sagor-video-downloader"); module.exports = { config: { name: "autolink", version: "2.0.0", author: "๐Œ๐š๐‘๐ฎ๐…", countDown: 5, role: 0, shortDescription: "Auto-download & send videos", 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)]; for (const url of uniqueLinks) { let filePath = null; try { const result = await downloadVideo(url); filePath = result.filePath; if (!filePath || !fs.existsSync(filePath)) { throw new Error("Video file not found"); } const stats = fs.statSync(filePath); const fileSizeInMB = stats.size / (1024 * 1024); if (fileSizeInMB > 25) { fs.unlinkSync(filePath); filePath = null; continue; } await api.sendMessage( { body: `๐ŸŽž๏ธ ๐‡๐ž๐ซ๐ž'๐ฌ ๐˜๐จ๐ฎ๐ซ ๐ƒ๐จ๐ฐ๐ง๐ฅ๐จ๐š๐๐ž๐ ๐•๐ข๐๐ž๐จ โœจ ๐“†ฉโ™ก๐“†ช ๐„๐ง๐ฃ๐จ๐ฒ ๐–๐š๐ญ๐œ๐ก๐ข๐ง๐ ! ๐ŸŽฌ ๐Ÿ‘‘ ๐๐จ๐ญ ๐จ๐ฐ๐ง๐ž๐ซ ยป ๐Œ๐š๐‘๐ฎ๐… ๐Ÿ’ซ๐Ÿชฝ`, attachment: fs.createReadStream(filePath) }, threadID, () => { if (filePath && fs.existsSync(filePath)) { fs.unlinkSync(filePath); } } ); } catch (error) { if (filePath && fs.existsSync(filePath)) { try { fs.unlinkSync(filePath); } catch {} } } } } };