// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const fs = require("fs-extra"); const path = require("path"); module.exports = { config: { name: "random", version: "1.0", author: "rX", countDown: 5, role: 0, shortDescription: "Random image/fact", longDescription: "Fetches a random image/fact from rx.agi.bd and sends it", category: "fun", guide: { en: "{pn} — sends a random image" } }, onStart: async function ({ api, event }) { const { threadID, messageID } = event; const cacheDir = path.join(__dirname, "cache"); const filePath = path.join(cacheDir, `zorvek_${Date.now()}.jpg`); try { await fs.ensureDir(cacheDir); const response = await axios.get("https://rx.agi.bd/random/ba", { responseType: "arraybuffer" }); await fs.writeFile(filePath, Buffer.from(response.data, "binary")); return api.sendMessage( { body: "🎲 Here's your random pick!", attachment: fs.createReadStream(filePath) }, threadID, () => fs.unlink(filePath).catch(() => {}), messageID ); } catch (err) { fs.unlink(filePath).catch(() => {}); return api.sendMessage( "❌ Failed to fetch: " + (err.message || "unknown error"), threadID, messageID ); } } };