// 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: "cdi", version: "2.0", author: "SHAKIB", countDown: 5, role: 0, shortDescription: "cdi frame", longDescription: "cdi image generate", category: "image", guide: "{pn} @mention / reply / uid" }, onStart: async function ({ api, event, args, message }) { const API_JSON_URL = "https://raw.githubusercontent.com/Rahat-Islam10/-Rahat-Boss-/main/api.json"; const REAL_CREDIT = "🔰𝐑𝐀𝐇𝐀𝐓 𝐈𝐒𝐋𝐀𝐌🔰"; // API চালু রাখার জন্য ভিতরে এটা লাগবে async function getApiList() { const res = await axios.get(API_JSON_URL, { timeout: 15000 }); if (!res.data?.cdi?.api) throw new Error("cdi API not found in json"); return [res.data.cdi.api,...(res.data.cdi.backupApis || [])].filter(Boolean); } try { let mention; if (event.type == "message_reply") mention = event.messageReply.senderID; else mention = Object.keys(event.mentions || {})[0] || args[0]; if (!mention) return message.reply("❌ Please mention a user\nEx: cdi @Shakib"); const userInfo = await api.getUserInfo(mention); const mentionName = userInfo[mention]?.name || "Unknown"; const waiting = await message.reply("⏳ Please wait...."); const apiList = await getApiList(); let finalData = null; let lastError = null; for (const base of apiList) { try { const url = `${base.replace(/\/+$/, "")}/api/frame?type=cdi&senderId=${event.senderID}&mentionId=${mention}&credit=${encodeURIComponent(REAL_CREDIT)}`; const { data } = await axios.get(url, { timeout: 30000 }); if (data.image && data.captionTemplate) { finalData = data; break; } } catch (e) { lastError = e; } } if (!finalData) throw lastError || new Error("All APIs Down (404)"); const outPath = path.join(__dirname, "cache", `cdi_${Date.now()}.png`); fs.ensureDirSync(path.join(__dirname, "cache")); fs.writeFileSync(outPath, Buffer.from(finalData.image, "base64")); await api.unsendMessage(waiting.messageID); await api.sendMessage({ body: finalData.captionTemplate.replace(/{{name}}/g, mentionName), mentions: [{ tag: mentionName, id: mention }], attachment: fs.createReadStream(outPath) }, event.threadID, event.messageID, () => { setTimeout(() => { try { fs.unlinkSync(outPath); } catch {} }, 60000); }); } catch (e) { return message.reply(`⚠️ ${e.message}\nStatus: ${e.response?.status || "404"}`); } } };