// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const fs = require("fs"); const path = require("path"); module.exports = { config: { name: "tiktok", aliases: ["tt"], version: "1.4", author: "๐Œ๐™ดสœ๐„แด…๐ˆ", role: 0, shortDescription: "Fetch a TikTok video", longDescription: "Search TikTok and send video", category: "media", }, onStart: async function ({ message, args }) { return this.run({ message, args }); }, onChat: async function ({ message, args, event }) { const body = (event.body || "").toLowerCase(); if (!body.startsWith("tt ") && !body.startsWith("tiktok ")) return; args = body.split(" ").slice(1); return this.run({ message, args }); }, run: async function ({ message, args }) { try { const query = args.join(" ").trim(); if (!query) return message.reply("โš ๏ธ Please enter a search keyword!"); await message.reply(`๐Ÿ” Searching for *${query}*...`); const apiUrl = `https://azadx69x-all-apis-top.vercel.app/api/tiktok?query=${encodeURIComponent(query)}`; const { data } = await axios.get(apiUrl); if (!data?.data || !data.data.length) { return message.reply("โŒ No video found!"); } const videos = data.data.slice(0, 10); const video = videos[Math.floor(Math.random() * videos.length)]; const videoUrl = video.video_url.replace(/^\[|\]$/g, ""); const filePath = path.join(__dirname, `tiktok_${Date.now()}.mp4`); const writer = fs.createWriteStream(filePath); const response = await axios({ url: videoUrl, method: "GET", responseType: "stream", }); response.data.pipe(writer); writer.on("finish", async () => { const bodyMsg = `๐Ÿคก ๐‡๐ž๐ซ๐ž ๐ƒ๐จ๐ฐ๐ง๐ฅ๐จ๐š๐๐ž๐ ๐•๐ข๐๐ž๐จ ๐“†ฉโ™ก๐“†ช ๐„๐ง๐ฃ๐จ๐ฒ ๐–๐š๐ญ๐œ๐ก๐ข๐ง๐  ๐“†ฉโ™ก๐“†ช ๐—ข๐˜„๐—ป๐—ฒ๐—ฟ โ™ก๐Œ๐™ดสœ๐„แด…๐ˆโ™ก`; await message.reply({ body: bodyMsg, attachment: fs.createReadStream(filePath), }); fs.unlinkSync(filePath); }); writer.on("error", () => message.reply("โŒ Error downloading video!")); } catch (err) { console.error("TikTok error:", err); return message.reply("โŒ API error. Please try again later."); } }, };