goat
command
autolink
Auto-download & send videos
0
views
0
likes
0
installs
raw source
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 {}
}
}
}
}
};