Skip to content

Instantly share code, notes, and snippets.

@dipto-008
Created July 9, 2025 17:37
Show Gist options
  • Save dipto-008/c55359f4045482c8d29d7b1e78edf2f0 to your computer and use it in GitHub Desktop.
Save dipto-008/c55359f4045482c8d29d7b1e78edf2f0 to your computer and use it in GitHub Desktop.
Hey noob ๐Ÿ‘‹๐Ÿ‘‹
const { createCanvas, loadImage } = require("canvas");
const axios = require("axios");
const fs = require("fs-extra");
const path = require("path");
module.exports = {
config: {
name: "pair4",
version: "3.6",
author: "Ew'r Saim",
role: 0,
shortDescription: "Pair 2 random users or pair mention user",
category: "love",
guide: "{pn} [@mention (optional)]"
},
onStart: async function ({ api, event, usersData }) {
const W = 760, H = 400;
const canvas = createCanvas(W, H);
const ctx = canvas.getContext("2d");
const userID1 = event.senderID;
const name1 = await usersData.getName(userID1);
const mentionID = event.mentions && Object.keys(event.mentions)[0];
const threadInfo = await api.getThreadInfo(event.threadID);
const allUsers = threadInfo.userInfo;
const botID = api.getCurrentUserID();
let userID2 = mentionID;
if (!userID2) {
const gender1 = allUsers.find(u => u.id == userID1)?.gender || "UNKNOWN";
let candidates = allUsers.filter(u => u.id !== userID1 && u.id !== botID);
if (gender1 === "MALE")
candidates = candidates.filter(u => u.gender === "FEMALE");
else if (gender1 === "FEMALE")
candidates = candidates.filter(u => u.gender === "MALE");
userID2 = candidates[Math.floor(Math.random() * candidates.length)]?.id;
}
if (!userID2 || userID2 === userID1)
return api.sendMessage("โŒ No valid match found. Mention someone or try again.", event.threadID);
const name2 = await usersData.getName(userID2);
const lovePercent = Math.floor(Math.random() * 31) + 70;
// Avatar fetching
const getAvatar = async (id, outPath) => {
const url = `https://graph.facebook.com/${id}/picture?width=720&height=720&access_token=6628568379%7Cc1e620fa708a1d5696fb991c1bde5662`;
const res = await axios.get(url, { responseType: "arraybuffer" });
fs.writeFileSync(outPath, res.data);
};
const tmpDir = path.join(__dirname, "cache");
fs.ensureDirSync(tmpDir);
const avt1Path = path.join(tmpDir, "avt1.png");
const avt2Path = path.join(tmpDir, "avt2.png");
await getAvatar(userID1, avt1Path);
await getAvatar(userID2, avt2Path);
const avt1 = await loadImage(avt1Path);
const avt2 = await loadImage(avt2Path);
// Background gradient
const gradient = ctx.createLinearGradient(0, 0, 0, H);
gradient.addColorStop(0, "#1f0036");
gradient.addColorStop(0.5, "#360060");
gradient.addColorStop(1, "#1b002e");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, W, H);
// Sparkles
for (let i = 0; i < 30; i++) {
const x = Math.random() * W;
const y = Math.random() * H;
const r = Math.random() * 2 + 1;
ctx.beginPath();
ctx.arc(x, y, r, 0, 2 * Math.PI);
ctx.fillStyle = `rgba(255,255,255,${Math.random()})`;
ctx.fill();
}
// Avatar draw
const drawGlowingAvatar = (img, x, y, size, glowColor) => {
const r = size / 2;
ctx.save();
ctx.beginPath();
ctx.arc(x + r, y + r, r + 3, 0, Math.PI * 2);
ctx.shadowColor = glowColor;
ctx.shadowBlur = 30;
ctx.fill();
ctx.clip();
ctx.drawImage(img, x, y, size, size);
ctx.restore();
};
drawGlowingAvatar(avt1, 90, 80, 160, "#ff66cc");
drawGlowingAvatar(avt2, 510, 80, 160, "#66ffff");
// ๐Ÿ’– Heart
ctx.font = "bold 93px Arial";
ctx.fillStyle = "#ff4da6";
ctx.shadowColor = "#ff99cc";
ctx.shadowBlur = 25;
ctx.textAlign = "center";
ctx.fillText("๐Ÿ’", W / 2, 220);
// Names
ctx.font = "bold 26px Arial";
ctx.fillStyle = "#ffffff";
ctx.shadowColor = "#ffccff";
ctx.shadowBlur = 12;
ctx.fillText(name1, 170, 270);
ctx.fillText(name2, 590, 270);
// Love %
ctx.font = "bold 30px Arial";
ctx.fillStyle = "#00ffff";
ctx.shadowColor = "#00ccff";
ctx.shadowBlur = 20;
ctx.fillText(`๐Ÿ’˜ Love Percentage ${lovePercent}% ๐Ÿ’˜`, W / 2, 330);
// Footer
ctx.font = "20px monospace";
ctx.fillStyle = "#999999";
ctx.shadowBlur = 0;
ctx.fillText("โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”", W / 2, 365);
// Save image
const outputPath = path.join(tmpDir, `pair-${event.senderID}.png`);
fs.writeFileSync(outputPath, canvas.toBuffer("image/png"));
// Stylish message body with mentions
const messageBody =
`๐Ÿ’˜ [ ๐๐š๐ข๐ซ ๐’๐ฎ๐œ๐œ๐ž๐ฌ๐ฌ๐Ÿ๐ฎ๐ฅ๐ฅ ] ๐Ÿ’–
ยป ${name1} โœจ
ยป ${name2} โœจ
๐Ÿ’Œ ๐…๐จ๐ซ๐ž๐ฏ๐ž๐ซ ๐ž๐ง๐ญ๐ฐ๐ข๐ง๐ž๐ ๐ข๐ง ๐ก๐š๐ฉ๐ฉ๐ข๐ง๐ž๐ฌ๐ฌ ๐š๐ง๐ ๐ž๐ง๐๐ฅ๐ž๐ฌ๐ฌ ๐š๐Ÿ๐Ÿ๐ž๐œ๐ญ๐ข๐จ๐ง. ๐Ÿ’žโœจ
๐Ÿ’˜ ๐‹๐จ๐ฏ๐ž ๐๐ž๐ซ๐œ๐ž๐ง๐ญ๐š๐ ๐ž: ${lovePercent}% โœจ`;
return api.sendMessage(
{
body: messageBody,
mentions: [{ tag: name2, id: userID2 }],
attachment: fs.createReadStream(outputPath),
},
event.threadID,
() => fs.unlinkSync(outputPath)
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment