// 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: "bow3", version: "2.0", author: "🔰𝐑𝐀𝐇𝐀𝐓 𝐈𝐒𝐋𝐀𝐌🔰", countDown: 5, role: 0, shortDescription: { en: "Image generate" }, longDescription: { en: "Generate a bow3 image for a mentioned, replied or specified user." }, category: "image", guide: { en: "{pn} @mention\n" + "{pn} reply to a message\n" + "{pn} UID\n" + "{pn} Facebook profile link" } }, onStart: async function ({ api, event, args }) { const API_JSON_URL = "https://raw.githubusercontent.com/Rahat-Islam10/-Rahat-Boss-/refs/heads/main/api.json"; // ============================== // Find UID by full name // ============================== async function getUIDByFullName(threadID, body) { if (!body || !body.includes("@")) { return null; } const match = body.match(/@(.+)/); if (!match) { return null; } const targetName = match[1] .trim() .toLowerCase() .replace(/\s+/g, " "); try { const threadInfo = await api.getThreadInfo(threadID); const users = threadInfo.userInfo || []; const user = users.find(u => { if (!u.name) return false; const fullName = u.name .trim() .toLowerCase() .replace(/\s+/g, " "); return fullName === targetName; }); return user ? user.id : null; } catch (error) { return null; } } // ============================== // Get API list // ============================== async function getApiList(commandName) { const res = await axios.get(API_JSON_URL, { timeout: 15000 }); const data = res.data || {}; const cmdData = data[commandName]; if (!cmdData || !cmdData.api) { throw new Error( `❌ "${commandName}" API পাওয়া যায়নি` ); } const apiList = [ cmdData.api, ...(cmdData.backupApis || []) ].filter(Boolean); if (!apiList.length) { throw new Error( `❌ "${commandName}" API পাওয়া যায়নি` ); } return apiList; } // ============================== // Generate frame with fallback // ============================== async function generateFrameWithFallback({ senderID, mention, credit, apiList }) { let lastError = null; for (const baseApi of apiList) { try { const cleanBase = baseApi.replace(/\/+$/, ""); const apiUrl = `${cleanBase}/api/frame` + `?type=bow3` + `&senderId=${encodeURIComponent(senderID)}` + `&mentionId=${encodeURIComponent(mention)}` + `&credit=${encodeURIComponent(credit)}`; const response = await axios.get( apiUrl, { timeout: 30000, responseType: "json" } ); const data = response.data; if ( data && data.image && data.captionTemplate ) { const imageBuffer = Buffer.from( data.image, "base64" ); return { imageBuffer, captionTemplate: data.captionTemplate }; } throw new Error( "❌ API থেকে image পাওয়া যায়নি" ); } catch (error) { lastError = error; // 401 হলে backup API ব্যবহার না করে // API থেকে পাওয়া error দেখাবে if ( error.response?.status === 401 && error.response?.data?.error ) { throw new Error( error.response.data.error ); } } } throw ( lastError || new Error("❌ কোনো API কাজ করছে না") ); } try { let mention; // ============================== // 1. Reply // ============================== if ( event.type === "message_reply" && event.messageReply ) { mention = event.messageReply.senderID; } // ============================== // 2. Direct mention // ============================== else if ( event.mentions && Object.keys(event.mentions).length > 0 ) { mention = Object.keys(event.mentions)[0]; } // ============================== // 3. UID / Facebook link / @name // ============================== else if ( args && args.length > 0 ) { const input = args[0]; // Facebook profile link if ( input.includes(".com/") ) { try { mention = await api.getUID(input); } catch (e) { mention = null; } } // @username / @name else if ( args.join(" ").includes("@") ) { mention = Object.keys( event.mentions || {} )[0]; if (!mention) { mention = await getUIDByFullName( event.threadID, args.join(" ") ); } } // Direct UID else { mention = input; } } // ============================== // No target // ============================== else { return api.sendMessage( "❌ 𝗣𝗹𝗲𝗮𝘀𝗲 𝗺𝗲𝗻𝘁𝗶𝗼𝗻 𝗮 𝘂𝘀𝗲𝗿\n\n" + "𝗨𝘀𝗮𝗴𝗲:\n" + "• bow3 @mention\n" + "• Reply to a message\n" + "• bow3 UID\n" + "• bow3 Facebook profile link", event.threadID, event.messageID ); } // ============================== // Validate UID // ============================== if (!mention) { return api.sendMessage( "❌ 𝗨𝘀𝗲𝗿 𝗻𝗼𝘁 𝗳𝗼𝘂𝗻𝗱 🐸\n" + "𝗣𝗹𝗲𝗮𝘀𝗲 𝗰𝗵𝗲𝗰𝗸 𝘁𝗵𝗲 𝘂𝘀𝗲𝗿 𝗽𝗿𝗼𝗳𝗶𝗹𝗲.", event.threadID, event.messageID ); } // ============================== // Get user information // ============================== const userInfo = await api.getUserInfo(mention); const mentionName = userInfo?.[mention]?.name || "Unknown"; const senderID = event.senderID; const credit = "🔰𝐑𝐀𝐇𝐀𝐓 𝐈𝐒𝐋𝐀𝐌🔰"; // ============================== // Loading // ============================== const waiting = await api.sendMessage( "⏳𝗣𝗹𝗲𝗮𝘀𝗲 𝘄𝗮𝗶𝘁....", event.threadID ); try { // ============================== // Get API list // ============================== const apiConfigList = await getApiList("bow3"); // ============================== // Generate image // ============================== const { imageBuffer, captionTemplate } = await generateFrameWithFallback({ senderID, mention, credit, apiList: apiConfigList }); // ============================== // Caption // ============================== const finalCaption = captionTemplate.replace( /{{name}}/g, mentionName ); // ============================== // Cache directory // ============================== const cacheDir = path.join( __dirname, "cache" ); await fs.ensureDir(cacheDir); // ============================== // Save image // ============================== const outPath = path.join( cacheDir, `bow3_${Date.now()}.png` ); await fs.writeFile( outPath, imageBuffer ); // ============================== // Remove loading // ============================== try { await api.unsendMessage( waiting.messageID ); } catch (e) {} // ============================== // Send result // ============================== const messageInfo = await api.sendMessage( { body: finalCaption, mentions: [ { tag: mentionName, id: mention } ], attachment: fs.createReadStream( outPath ) }, event.threadID, event.messageID ); // ============================== // Delete after 2 minutes // ============================== setTimeout( async () => { try { if ( messageInfo?.messageID ) { await api.unsendMessage( messageInfo.messageID ); } if ( await fs.pathExists( outPath ) ) { await fs.remove( outPath ); } } catch (e) {} }, 120000 ); } catch (error) { // Generation failed: // remove loading message try { await api.unsendMessage( waiting.messageID ); } catch (e) {} throw error; } } catch (error) { console.error( "BOW3 ERROR:", error ); return api.sendMessage( `⚠️ ${error.message || "Unknown error"}`, event.threadID, event.messageID ); } } };