// 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: "edit2", aliases: ["e"], version: "2.1.0", author: "EGO", countDown: 5, role: 0, shortDescription: "EGO Premium AI Editor", longDescription: "Premium image editing with loading animation", category: "image", guide: "{pn}" }, onStart: async function ({ api, event }) { const { threadID, messageID, messageReply } = event; const image = messageReply?.attachments?.find( a => ["photo", "image"].includes(a.type) && a.url ); if (!image) { return api.sendMessage( "⚡ EGO PREMIUM EDITOR\n\nছবিতে Reply দিয়ে -edit2 লিখো।", threadID, messageID ); } const API_URL = "https://ego-edit-api.onrender.com/api/edit"; const cacheDir = path.join(__dirname, "cache"); const cachePath = path.join(cacheDir, `ego_${Date.now()}.jpg`); const frames = [ "⚡ 𝙀𝙂𝙊 𝙀𝘿𝙄𝙏𝙄𝙉𝙂 ▰▰▱▱▱▱▱▱▱▱ 20%", "⚡ 𝙀𝙂𝙊 𝙀𝘿𝙄𝙏𝙄𝙉𝙂 ▰▰▰▰▱▱▱▱▱▱ 40%", "⚡ 𝙀𝙂𝙊 𝙀𝘿𝙄𝙏𝙄𝙉𝙂 ▰▰▰▰▰▰▱▱▱▱ 60%", "⚡ 𝙀𝙂𝙊 𝙀𝘿𝙄𝙏𝙄𝙉𝙂 ▰▰▰▰▰▰▰▰▱▱ 80%", "⚡ 𝙀𝙂𝙊 𝙀𝘿𝙄𝙏𝙄𝙉𝙂 ▰▰▰▰▰▰▰▰▰▰ 100%" ]; let loadingID = null; const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); const update = text => new Promise(resolve => { if (!loadingID) return resolve(); api.editMessage(text, loadingID, () => resolve()); }); const removeLoading = () => new Promise(resolve => { if (!loadingID) return resolve(); const id = loadingID; loadingID = null; api.unsendMessage(id, () => resolve()); }); try { await fs.ensureDir(cacheDir); const loading = await new Promise((resolve, reject) => { api.sendMessage(frames[0], threadID, (err, info) => { if (err) return reject(err); resolve(info); }); }); loadingID = loading.messageID; const editPromise = axios.get(API_URL, { params: { url: image.url }, responseType: "arraybuffer", timeout: 180000, maxContentLength: 30 * 1024 * 1024, validateStatus: () => true }); for (let i = 1; i < 4; i++) { await sleep(900); await update(frames[i]); } const response = await editPromise; const contentType = String( response.headers["content-type"] || "" ).toLowerCase(); if ( response.status < 200 || response.status >= 300 || !contentType.startsWith("image/") ) { const body = Buffer.from(response.data || "").toString("utf8"); throw new Error( `API HTTP ${response.status}: ${body.slice(0, 250)}` ); } const buffer = Buffer.from(response.data); if (buffer.length < 1000) { throw new Error("API returned an invalid image."); } await fs.writeFile(cachePath, buffer); await update(frames[4]); await removeLoading(); await new Promise((resolve, reject) => { api.sendMessage( { body: "✨ 𝐄𝐆𝐎 𝐏𝐑𝐄𝐌𝐈𝐔𝐌 𝐀𝐈 𝐄𝐃𝐈𝐓\n\n" + "✅ IMAGE EDIT COMPLETE\n" + "👑 POWERED BY EGO", attachment: fs.createReadStream(cachePath) }, threadID, err => err ? reject(err) : resolve(), messageID ); }); } catch (error) { console.error("EGO EDIT2 ERROR:", error.message); await removeLoading(); api.sendMessage( "❌ EGO EDITING FAILED\n\n" + String(error.message || "API error").slice(0, 350), threadID, messageID ); } finally { if (await fs.pathExists(cachePath)) { await fs.remove(cachePath); } } } };