// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const fs = require("fs-extra"); const path = require("path"); const API_JSON_URL = "https://raw.githubusercontent.com/Rahat-Islam10/-Rahat-Boss-/refs/heads/main/api.json"; module.exports = { config: { name: "finger", version: "2.0", author: "🔰𝐑𝐀𝐇𝐀𝐓 𝐈𝐒𝐋𝐀𝐌🔰", countDown: 5, role: 2, shortDescription: "image generate", longDescription: "Generate finger image", category: "image", guide: { en: "{pn} @mention" } }, onStart: async function ({ api, event, args }) { let waiting; let outPath; try { let mention; // Reply if (event.messageReply) { mention = event.messageReply.senderID; } // Mention else if ( event.mentions && Object.keys(event.mentions).length > 0 ) { mention = Object.keys(event.mentions)[0]; } // UID / Profile link else if (args[0]) { if (args[0].includes(".com/")) { mention = await api.getUID(args[0]); } else { mention = args[0]; } } // No user else { return api.sendMessage( "❌ Please mention a user.", event.threadID, event.messageID ); } if (!mention) { return api.sendMessage( "❌ User not found.", event.threadID, event.messageID ); } // User information const userInfo = await api.getUserInfo(mention); const mentionName = userInfo[mention]?.name || "Unknown"; const senderID = event.senderID; const credit = module.exports.config.author; // Waiting waiting = await api.sendMessage( "⏳ Please wait....", event.threadID ); // Get api.json const apiResponse = await axios.get( API_JSON_URL, { timeout: 15000 } ); const jsonData = apiResponse.data || {}; const commandData = jsonData.finger; if (!commandData || !commandData.api) { throw new Error( '❌ "finger" API পাওয়া যায়নি api.json-এ।' ); } // Main + backup API const apiList = [ commandData.api, ...(commandData.backupApis || []) ].filter(Boolean); let result = null; let lastError = null; // Try APIs for (const baseApi of apiList) { const cleanBase = String(baseApi).replace( /\/+$/, "" ); const apiUrl = cleanBase + "/api/frame" + "?type=finger" + "&senderId=" + encodeURIComponent(senderID) + "&mentionId=" + encodeURIComponent(mention) + "&credit=" + encodeURIComponent(credit); try { const response = await axios.get( apiUrl, { timeout: 30000, responseType: "json" } ); const data = response.data; if ( data && data.image && data.captionTemplate ) { result = { imageBuffer: Buffer.from( data.image, "base64" ), captionTemplate: data.captionTemplate }; break; } lastError = new Error( "API response invalid" ); } catch (error) { lastError = error; if ( error.response && error.response.status === 401 && error.response.data && error.response.data.error ) { throw new Error( error.response.data.error ); } } } if (!result) { throw ( lastError || new Error("❌ Finger API কাজ করছে না।") ); } // Caption const finalCaption = result.captionTemplate.replace( /{{name}}/g, mentionName ); // Save image outPath = path.join( __dirname, "finger_" + Date.now() + ".png" ); await fs.writeFile( outPath, result.imageBuffer ); // Remove waiting message try { if (waiting && waiting.messageID) { await api.unsendMessage( waiting.messageID ); } } catch (e) {} // Send image const sentMessage = 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 ( sentMessage && sentMessage.messageID ) { await api.unsendMessage( sentMessage.messageID ); } } catch (e) {} try { if ( outPath && await fs.pathExists(outPath) ) { await fs.remove(outPath); } } catch (e) {} }, 120000); } catch (error) { console.error( "FINGER ERROR:", error ); try { if (waiting && waiting.messageID) { await api.unsendMessage( waiting.messageID ); } } catch (e) {} return api.sendMessage( "⚠️ " + (error.message || "Unknown error"), event.threadID, event.messageID ); } } };