// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const { createCanvas, loadImage } = require("canvas"); const fs = require("fs-extra"); const API_BASE = "https://hridoy-api.onrender.com"; module.exports = { config: { name: "pair6", aliases: ["pr6"], version: "2.1", author: "Jihad", countDown: 5, role: 0, category: "love", guide: "{pn}" }, onStart: async function ({ api, event, usersData }) { const { threadID, senderID, messageID, participantIDs, messageReply, mentions } = event; try { /* * ========================================== * TARGET PRIORITY * ========================================== * 1. Reply * 2. Mention * 3. Random member */ let targetID = null; // 1. Reply target if ( messageReply && ( messageReply.senderID || messageReply.author ) ) { targetID = messageReply.senderID || messageReply.author; } // 2. Mention target else if ( mentions && Object.keys(mentions).length > 0 ) { targetID = Object.keys(mentions)[0]; } // 3. Random group member else { const botID = String( api.getCurrentUserID() ); const availableMembers = Array.isArray(participantIDs) ? participantIDs.filter( id => String(id) !== String(senderID) && String(id) !== botID ) : []; if ( availableMembers.length > 0 ) { targetID = availableMembers[ Math.floor( Math.random() * availableMembers.length ) ]; } } /* * ========================================== * NO TARGET * ========================================== */ if (!targetID) { return api.sendMessage( "⚠️ | Pair করার মতো কোনো member পাওয়া যায়নি! 💗", threadID, messageID ); } /* * ========================================== * SELF PAIR PROTECTION * ========================================== */ if ( String(targetID) === String(senderID) ) { return api.sendMessage( "😅 | নিজেকে নিজের সাথে pair করা যাবে না!", threadID, messageID ); } /* * ========================================== * GET NAMES * ========================================== */ const [ name1, name2 ] = await Promise.all([ usersData.getName( senderID ), usersData.getName( targetID ) ]); /* * ========================================== * GET PAIR6 CONFIG * ========================================== */ const response = await axios.get( `${API_BASE}/api/images/pair6`, { timeout: 15000 } ); const config = response.data; if ( !config || !config.url || !config.positions ) { throw new Error( "Invalid Pair6 API response" ); } /* * ========================================== * FACEBOOK TOKEN * ========================================== */ const token = "6628568379|c1e620fa708a1d5696fb991c1bde5662"; /* * ========================================== * LOAD IMAGES * ========================================== */ const [ bg, img1, img2 ] = await Promise.all([ loadImage( config.url ), loadImage( `https://graph.facebook.com/${senderID}/picture?width=512&height=512&access_token=${token}` ), loadImage( `https://graph.facebook.com/${targetID}/picture?width=512&height=512&access_token=${token}` ) ]); /* * ========================================== * CREATE CANVAS * ========================================== */ const canvas = createCanvas( bg.width, bg.height ); const ctx = canvas.getContext("2d"); /* * ========================================== * DRAW BACKGROUND * ========================================== */ ctx.drawImage( bg, 0, 0, canvas.width, canvas.height ); /* * ========================================== * DRAW PROFILE * ========================================== */ const draw = ( img, pos ) => { if ( !pos || typeof pos.x !== "number" || typeof pos.y !== "number" || typeof pos.w !== "number" || typeof pos.h !== "number" ) { throw new Error( "Invalid Pair6 position" ); } ctx.save(); ctx.beginPath(); ctx.arc( pos.x + pos.w / 2, pos.y + pos.h / 2, Math.min( pos.w, pos.h ) / 2, 0, Math.PI * 2 ); ctx.closePath(); ctx.clip(); ctx.drawImage( img, pos.x, pos.y, pos.w, pos.h ); ctx.restore(); }; /* * ========================================== * YOUR PROFILE * ========================================== */ draw( img1, config.positions.sender ); /* * ========================================== * TARGET PROFILE * ========================================== */ draw( img2, config.positions.target ); /* * ========================================== * CACHE DIRECTORY * ========================================== */ const cacheDir = __dirname + "/cache"; fs.ensureDirSync( cacheDir ); /* * ========================================== * IMAGE PATH * ========================================== */ const pathImg = `${cacheDir}/pair6_${senderID}_${targetID}_${Date.now()}.png`; /* * ========================================== * SAVE IMAGE * ========================================== */ fs.writeFileSync( pathImg, canvas.toBuffer( "image/png" ) ); /* * ========================================== * MESSAGE * ========================================== */ const body = ( config.messages?.[0] || "✨ {sender} ❤️ X ❤️ {target}\n🌸 May this bond be forever beautiful! 🦋" ) .replace( /\{sender\}/g, name1 ) .replace( /\{target\}/g, name2 ); /* * ========================================== * SEND RESULT * ========================================== */ return api.sendMessage( { body, mentions: [ { tag: name1, id: senderID }, { tag: name2, id: targetID } ], attachment: fs.createReadStream( pathImg ) }, threadID, () => { if ( fs.existsSync( pathImg ) ) { try { fs.unlinkSync( pathImg ); } catch {} } }, messageID ); } catch (err) { console.log( "Pair6 Error:", err ); return api.sendMessage( "❌ | Pair system failed! Please try again.", threadID, messageID ); } } };