// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const FormData = require("form-data"); const https = require("https"); // Keep-alive connection = দ্রুত রিকোয়েস্ট const agent = new https.Agent({ keepAlive: true }); const API_URL = "https://xrahat-image-edit.vercel.app/api/edit"; module.exports = { config: { name: "edit", aliases: ["imgedit", "aiedit"], version: "2.0.0", author: "🔰𝐑𝐀𝐇𝐀𝐓 𝐈𝐒𝐋𝐀𝐌🔰", countDown: 10, role: 0, description: { en: "AI image editor" }, category: "image", guide: { en: "{pn} (reply to an image)" } }, onStart: async function ({ api, event, args, message }) { const { messageID, messageReply } = event; // ছবির URL খোঁজা (reply → না পেলে নিজের মেসেজের attachment) const findImage = (attachments = []) => { const img = attachments.find(a => a.type === "photo" || a.type === "image"); return img ? img.url || img.image_data?.url : null; }; const imageUrl = findImage(messageReply?.attachments) || findImage(event.attachments); if (!imageUrl) { return message.reply( "❌ একটি ছবির মেসেজে reply করে command দিন।\n\nউদাহরণ:\n!edit make the background beautiful" ); } const prompt = args.join(" ").trim(); if (!prompt) { return message.reply( "❌ Prompt দিন।\n\nউদাহরণ:\n!edit make the sky sunset" ); } // await ছাড়া reaction, যাতে সময় নষ্ট না হয় api.setMessageReaction("⏳", messageID, () => {}, true); try { // ১. ইনপুট ছবি memory তে নামানো (disk এ save না করে) const { data: imgBuffer } = await axios.get(imageUrl, { responseType: "arraybuffer", timeout: 30000, httpsAgent: agent }); // ২. API তে পাঠানো const form = new FormData(); form.append("image", Buffer.from(imgBuffer), { filename: "image.jpg", contentType: "image/jpeg" }); form.append("prompt", prompt); form.append("resolution", "2K"); form.append("ratio", "match_input_image"); const { data } = await axios.post(API_URL, form, { headers: form.getHeaders(), timeout: 120000, maxContentLength: Infinity, maxBodyLength: Infinity, httpsAgent: agent }); if (!data?.success || !data?.imageUrl) { throw new Error(data?.error || "Image generation failed"); } // ৩. আউটপুট সরাসরি stream করে পাঠানো (cache/cleanup লাগে না) const stream = await global.utils.getStreamFromURL(data.imageUrl); api.setMessageReaction("✅", messageID, () => {}, true); return message.reply({ body: `✅ Image Edit Complete!\n📝 Prompt: ${prompt}`, attachment: stream }); } catch (error) { console.error("edit error:", error); api.setMessageReaction("❌", messageID, () => {}, true); let errorMessage = "❌ Image edit failed."; const reason = error.response?.data?.error || error.message; if (reason) errorMessage += `\n\n${reason}`; return message.reply(errorMessage); } } };