// code from goatstore // api: https://store.agi.bd exports.config = { name: "imgbb", version: "1.0.0", author: "𝐌𝐚𝐑𝐮𝐅", countDown: 5, role: 0, shortDescription: "Upload image to ImgBB", longDescription: "Reply to an image with imgbb to upload and get image link", category: "utility", guide: { en: "Reply to a photo with: imgbb" } }; const axios = require("axios"); const API_KEY = "36a6775c9b57cfae359c449491eaedf9"; exports.onStart = async function () {}; exports.onChat = async function ({ event, api }) { const message = (event.body || "").trim().toLowerCase(); if (message !== "imgbb") return; const reply = event.messageReply; const attachments = reply && reply.attachments; if (!attachments || attachments.length === 0) { return api.sendMessage( "❌ একটি ছবিতে Reply দিয়ে imgbb লিখুন।", event.threadID, event.messageID ); } const photo = attachments.find( attachment => attachment.type === "photo" || attachment.type === "image" ); if (!photo || !photo.url) { return api.sendMessage( "❌ Reply করা মেসেজে কোনো বৈধ ছবি পাওয়া যায়নি।", event.threadID, event.messageID ); } if (!API_KEY || API_KEY === "YOUR_IMGBB_API_KEY") { return api.sendMessage( "❌ ImgBB API key configure করুন।", event.threadID, event.messageID ); } try { await api.sendMessage( "⏳ 𝐈𝐦𝐚𝐠𝐞 𝐮𝐩𝐥𝐨𝐚𝐝𝐢𝐧𝐠...", event.threadID, event.messageID ); const imageResponse = await axios.get(photo.url, { responseType: "arraybuffer", timeout: 30000, maxRedirects: 5, validateStatus: status => status >= 200 && status < 300 }); const imageBuffer = Buffer.from(imageResponse.data); if (!imageBuffer.length) { throw new Error("Downloaded image is empty."); } const contentType = imageResponse.headers["content-type"] || ""; if (!contentType.startsWith("image/")) { throw new Error( "The replied URL did not return an image." ); } const form = new URLSearchParams(); form.append("key", API_KEY); form.append("image", imageBuffer.toString("base64")); const response = await axios.post( "https://api.imgbb.com/1/upload", form.toString(), { headers: { "Content-Type": "application/x-www-form-urlencoded" }, timeout: 60000, maxBodyLength: Infinity, maxContentLength: Infinity, validateStatus: status => status >= 200 && status < 300 } ); const result = response.data; if (!result || !result.success || !result.data?.url) { const reason = result?.error?.message || result?.error?.code || "ImgBB upload failed."; throw new Error(String(reason)); } return api.sendMessage( result.data.url, event.threadID, event.messageID ); } catch (error) { const responseData = error.response?.data; const apiError = responseData?.error?.message || responseData?.error || responseData?.message; const errorMessage = typeof apiError === "string" ? apiError : error.message || "Unknown error"; console.error( "[IMGBB ERROR]", JSON.stringify({ message: error.message, status: error.response?.status, response: responseData }) ); return api.sendMessage( "❌ 𝐔𝐩𝐥𝐨𝐚𝐝 𝐅𝐚𝐢𝐥𝐞𝐝!\n" + "𝐑𝐞𝐚𝐬𝐨𝐧: " + errorMessage, event.threadID, event.messageID ); } };