// code from goatstore // api: https://store.agi.bd const { createCanvas, loadImage } = require("canvas"); const fs = require("fs-extra"); const path = require("path"); module.exports = { config: { name: "cry", version: "1.0", author: "Mehedi-saito", countDown: 5, role: 0, shortDescription: "Cry meme generator", longDescription: "Generates a cry meme with the replied/mentioned user's avatar placed on the smiling face", category: "fun", guide: { en: "{pn} reply to someone's message or mention them\nExample: {pn} @Someone" } }, onStart: async function ({ api, event, usersData, message }) { const { threadID, messageID, senderID, type, messageReply, mentions } = event; let targetID; if (type === "message_reply") { targetID = messageReply.senderID; } else if (mentions && Object.keys(mentions).length > 0) { targetID = Object.keys(mentions)[0]; } if (!targetID) { return message.reply( "❌ Please reply to someone's message or mention them to use this command." ); } if (targetID === senderID) { return message.reply("❌ You can't use this command on yourself."); } try { const templateUrl = "https://drive.google.com/uc?export=download&id=1lKaNsH-prD8Ccm2sLf4STBWDfu788OCj"; const avatarTargetUrl = `https://graph.facebook.com/${targetID}/picture?width=512&height=512&access_token=6628568379%7Cc1e620fa708a1d5696fb991c1bde5662`; const [template, avatarTarget] = await Promise.all([ loadImage(templateUrl), loadImage(avatarTargetUrl) ]); // Canvas size matching original image (736 x 981) const canvas = createCanvas(736, 981); const ctx = canvas.getContext("2d"); // Draw background template ctx.drawImage(template, 0, 0, 736, 981); // Draw avatar in circle function const drawAvatarInCircle = (img, cx, cy, radius) => { ctx.save(); ctx.beginPath(); ctx.arc(cx, cy, radius, 0, Math.PI * 2); ctx.closePath(); ctx.clip(); ctx.drawImage( img, cx - radius, cy - radius, radius * 2, radius * 2 ); ctx.restore(); }; // Optional thin border around the avatar (white) const drawCircleBorder = (cx, cy, radius) => { ctx.beginPath(); ctx.arc(cx, cy, radius + 3, 0, Math.PI * 2); ctx.strokeStyle = "#FFFFFF"; ctx.lineWidth = 6; ctx.stroke(); }; // Position of the smiling face // cx = 260 (horizontal), cy = 540 (lower), radius = 160 (bigger) const cx = 260; const cy = 540; const radius = 160; // Draw border then avatar drawCircleBorder(cx, cy, radius); drawAvatarInCircle(avatarTarget, cx, cy, radius); const cacheDir = path.join(__dirname, "cache"); await fs.ensureDir(cacheDir); const filePath = path.join(cacheDir, `cry_${senderID}.png`); await fs.writeFile(filePath, canvas.toBuffer("image/png")); await message.reply({ body: "😭 Cry detected! 💔", attachment: fs.createReadStream(filePath) }); fs.unlink(filePath, () => {}); } catch (err) { console.error("[CRY ERROR]", err); return message.reply("❌ Failed to generate the image. Please try again."); } } };