// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const fs = require("fs"); const path = require("path"); const API_BASE = "https://eryxenx.agi.bd/api/nanobanana2"; module.exports = { config: { name: "edit2", aliases: ["nanobanana"], version: "3.3.0", author: "Mehedi Project", countDown: 15, role: 0, shortDescription: "AI Image Edit & Generate", category: "AI", guide: "{pn} (reply to an image to edit)" }, onStart: async function ({ api, event, args }) { const { threadID, messageID, messageReply } = event; const prompt = args.join(" ").trim(); if (!prompt) { return api.sendMessage( "╭━━━〔 ✨ MEHEDI AI 〕━━━╮\n" + "┃ ⚠️ Please enter a prompt!\n" + "┃\n" + "┃ Example:\n" + "┃ edit2 make it cinematic 8K\n" + "╰━━━━━━━━━━━━━━━━━━╯", threadID, messageID ); } const imgUrl = messageReply?.attachments?.[0]?.url; let filePath; api.setMessageReaction("⏳", messageID, () => {}, true); try { const params = new URLSearchParams(); params.set("prompt", prompt); if (imgUrl) { params.set("image", imgUrl); } const res = await axios.get( `${API_BASE}?${params.toString()}`, { timeout: 180000, headers: { Accept: "application/json" } } ); const data = res.data; const imageURL = data?.success ? data.imageUrl : null; if (!imageURL) { api.setMessageReaction("⚠️", messageID, () => {}, true); return api.sendMessage( `╭━━━〔 ⚠️ EDIT FAILED 〕━━━╮\n\n` + `❌ ${data?.error || data?.message || "Image generation failed"}\n\n` + `╰━━━━━━━━━━━━━━━━━━╯`, threadID, messageID ); } const cacheDir = path.join(__dirname, "cache"); fs.mkdirSync(cacheDir, { recursive: true }); const imageResponse = await axios.get(imageURL, { responseType: "arraybuffer", timeout: 60000 }); const contentType = data.contentType || imageResponse.headers["content-type"] || ""; let ext = contentType.split("/").pop().split(";")[0].toLowerCase(); if (!["jpg", "jpeg", "png", "webp"].includes(ext)) { ext = "png"; } filePath = path.join( cacheDir, `mehedi_${Date.now()}.${ext}` ); fs.writeFileSync(filePath, Buffer.from(imageResponse.data)); const mode = data.mode || (imgUrl ? "Edit" : "Generate"); const model = data.model || "Nano Banana 2"; const time = data.timeTaken || "N/A"; const operator = "ᥫ᭡፝֟፝֟ ϻꫝɪ֟፝ꜱʜꫝ ᥫ᭡፝֟፝֟𓍯_ 𝐌"; const body = `🔗━━━ 𝐌𝐞𝐡𝐞𝐝𝐢 𝐏𝐫𝐨𝐣𝐞𝐜𝐭 ━━━🖇️\n` + `╭━━━━━━━━━━━━━━━━━━━━╮\n` + `│\n` + `│ ✨ 𝐄𝐝𝐢𝐭 𝐂𝐨𝐦𝐩𝐥𝐞𝐭𝐞\n` + `│\n` + `│ 🎨 Mode: ${mode}\n` + `│ 🤖 Model: ${model}\n` + `│ ⏱️ Time: ${time}\n` + `│ 👤 Operator: ${operator}\n` + `│\n` + `╰━━━━━━━━━━━━━━━━━━━━╯\n\n` + `💎 Your Imagination, Our AI\n` + `━━━━━━━━━━━━━━━━━━━━`; api.setMessageReaction("✅", messageID, () => {}, true); api.sendMessage( { body, attachment: fs.createReadStream(filePath) }, threadID, () => { try { if (filePath && fs.existsSync(filePath)) { fs.unlinkSync(filePath); } } catch (_) {} }, messageID ); } catch (err) { console.error( "EDIT2 ERROR:", err?.response?.data || err.message ); if (filePath) { try { if (fs.existsSync(filePath)) { fs.unlinkSync(filePath); } } catch (_) {} } api.setMessageReaction("❌", messageID, () => {}, true); const reason = err?.response?.data?.error || err?.response?.data?.message || err.message || "Unknown error"; api.sendMessage( `╭━━━〔 ❌ EDIT FAILED 〕━━━╮\n\n` + `⚠️ Reason: ${reason}\n\n` + `╰━━━━━━━━━━━━━━━━━━╯`, threadID, messageID ); } } };