// 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: "bow", version: "2.0", author: "๐Ÿ”ฐ๐‘๐€๐‡๐€๐“ ๐ˆ๐’๐‹๐€๐Œ๐Ÿ”ฐ", countDown: 5, role: 0, shortDescription: { en: "Generate bow image" }, longDescription: { en: "Generate a bow image for a mentioned/replied user" }, category: "image", guide: { en: "{pn} @mention\n{pn} reply\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"; let mention; try { // ============================== // 1. Reply to a message // ============================== if (event.type === "message_reply") { mention = event.messageReply.senderID; } // ============================== // 2. Mentioned user // ============================== else if (event.mentions && Object.keys(event.mentions).length > 0) { mention = Object.keys(event.mentions)[0]; } // ============================== // 3. UID / Profile link // ============================== else if (args && args.length > 0) { const input = args[0]; if (input.includes("facebook.com")) { mention = await api.getUID(input); } else { mention = input; } } // ============================== // No target // ============================== else { return api.sendMessage( "โŒ ๐—ฃ๐—น๐—ฒ๐—ฎ๐˜€๐—ฒ ๐—บ๐—ฒ๐—ป๐˜๐—ถ๐—ผ๐—ป ๐—ฎ ๐˜‚๐˜€๐—ฒ๐—ฟ\n\n" + "๐—จ๐˜€๐—ฎ๐—ด๐—ฒ:\n" + "โ€ข bow @mention\n" + "โ€ข Reply to a message\n" + "โ€ข bow UID\n" + "โ€ข bow Facebook profile link", event.threadID, event.messageID ); } 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 message // ============================== const waiting = await api.sendMessage( "โณ ๐—ฃ๐—น๐—ฒ๐—ฎ๐˜€๐—ฒ ๐˜„๐—ฎ๐—ถ๐˜....", event.threadID ); // ============================== // Get API list // ============================== const apiResponse = await axios.get(API_JSON_URL, { timeout: 15000 }); const data = apiResponse.data || {}; const commandData = data.bow; if (!commandData || !commandData.api) { throw new Error('โŒ "bow" API เฆชเฆพเฆ“เงŸเฆพ เฆฏเฆพเงŸเฆจเฆฟ'); } const apiList = [ commandData.api, ...(commandData.backupApis || []) ].filter(Boolean); // ============================== // Generate image // ============================== let imageBuffer = null; let captionTemplate = null; let lastError = null; for (const baseApi of apiList) { try { const cleanBase = baseApi.replace(/\/+$/, ""); const apiUrl = `${cleanBase}/api/frame` + `?type=bow` + `&senderId=${encodeURIComponent(senderID)}` + `&mentionId=${encodeURIComponent(mention)}` + `&credit=${encodeURIComponent(credit)}`; const response = await axios.get(apiUrl, { timeout: 30000, responseType: "json" }); const result = response.data; if (result?.image && result?.captionTemplate) { imageBuffer = Buffer.from(result.image, "base64"); captionTemplate = result.captionTemplate; break; } throw new Error("โŒ API เฆฅเง‡เฆ•เง‡ image เฆชเฆพเฆ“เงŸเฆพ เฆฏเฆพเงŸเฆจเฆฟ"); } catch (error) { lastError = error; // Don't try backup API if authentication failed if ( error.response?.status === 401 && error.response?.data?.error ) { throw new Error(error.response.data.error); } } } if (!imageBuffer || !captionTemplate) { throw lastError || new Error("โŒ เฆ•เง‹เฆจเง‹ API เฆ•เฆพเฆœ เฆ•เฆฐเฆ›เง‡ เฆจเฆพ"); } // ============================== // Replace username // ============================== const finalCaption = captionTemplate.replace( /{{name}}/g, mentionName ); // ============================== // Save image // ============================== const cacheDir = path.join(__dirname, "cache"); await fs.ensureDir(cacheDir); const outPath = path.join( cacheDir, `bow_${Date.now()}.png` ); await fs.writeFile(outPath, imageBuffer); // ============================== // Remove loading message // ============================== try { await api.unsendMessage(waiting.messageID); } catch (e) {} // ============================== // Send result // ============================== const sentMessage = await api.sendMessage( { body: finalCaption, mentions: [ { tag: mentionName, id: mention } ], attachment: fs.createReadStream(outPath) }, event.threadID, event.messageID ); // ============================== // Delete cache after 2 minutes // ============================== setTimeout(async () => { try { if (sentMessage?.messageID) { await api.unsendMessage(sentMessage.messageID); } if (await fs.pathExists(outPath)) { await fs.remove(outPath); } } catch (e) {} }, 120000); } catch (error) { console.error("BOW COMMAND ERROR:", error); return api.sendMessage( `โš ๏ธ ${error.message || "Unknown error"}`, event.threadID, event.messageID ); } } };