// code from goatstore // api: https://store.agi.bd const { drive } = global.utils; const { createCanvas, loadImage } = require("canvas"); const fs = require("fs-extra"); const path = require("path"); const axios = require("axios"); module.exports = { config: { name: "welcome", version: "9.0", author: "Shakib x EryXenX", category: "events" }, langs: { en: { defaultWelcomeMessage: "🌸 HELLO {userName} šŸŽ€\nWELCOME TO OUR GROUP — CRAZY SQUAD\nšŸ“Œ YOU'RE THE {memberCount}th MEMBER!\n✨ Added by {inviterName}", botAddedMessage: "Thanks for adding me!" } }, onStart: async ({ threadsData, message, event, api, usersData, getLang }) => { if (event.logMessageType!== "log:subscribe") return; const { threadID } = event; const threadData = await threadsData.get(threadID); if (!threadData.settings.sendWelcomeMessage) return; const addedMembers = event.logMessageData.addedParticipants; const threadName = threadData.threadName || "CRAZY SQUAD"; const inviterID = event.author; for (const user of addedMembers) { const userID = user.userFbId; const botID = api.getCurrentUserID(); if (userID == botID) return; const userName = user.fullName; const inviterName = await usersData.getName(inviterID); const memberCount = event.participantIDs.length; let { welcomeMessage = getLang("defaultWelcomeMessage") } = threadData.data; welcomeMessage = welcomeMessage .replace(/\{userName\}/g, userName) .replace(/\{threadName\}/g, threadName) .replace(/\{memberCount\}/g, memberCount) .replace(/\{inviterName\}/g, inviterName); let welcomeImagePath = null; try { welcomeImagePath = await createWelcomeCard({ userName, threadName, memberCount, inviterName, newUserID: userID, inviterID, threadID, api }); } catch (e) { console.log(e); } const form = { body: welcomeMessage, mentions: [{ tag: userName, id: userID }] }; if (welcomeImagePath && fs.existsSync(welcomeImagePath)) { form.attachment = fs.createReadStream(welcomeImagePath); } message.send(form); if (welcomeImagePath) setTimeout(() => fs.unlinkSync(welcomeImagePath), 5000); } } }; const ACCESS_TOKEN = "6628568379%7Cc1e620fa708a1d5696fb991c1bde5662"; async function downloadHighQualityProfile(userID) { try { const url = `https://graph.facebook.com/${userID}/picture?width=500&height=500&access_token=${ACCESS_TOKEN}`; const res = await axios({ method: 'GET', url, responseType: 'arraybuffer', timeout: 10000 }); return Buffer.from(res.data, 'binary'); } catch { return null; } } async function downloadImage(url) { try { const res = await axios({ method: 'GET', url, responseType: 'arraybuffer', timeout: 10000 }); return Buffer.from(res.data, 'binary'); } catch { return null; } } function ordinal(n) { const s = ['th','st','nd','rd'], v = n%100; return n+(s[(v-20)%10]||s[v]||s[0]); } function roundRect(ctx,x,y,w,h,r){ctx.beginPath();ctx.moveTo(x+r,y);ctx.lineTo(x+w-r,y);ctx.quadraticCurveTo(x+w,y,x+w,y+r);ctx.lineTo(x+w,y+h-r);ctx.quadraticCurveTo(x+w,y+h,x+w-r,y+h);ctx.lineTo(x+r,y+h);ctx.quadraticCurveTo(x,y+h,x,y+h-r);ctx.lineTo(x,y+r);ctx.quadraticCurveTo(x,y,x+r,y);ctx.closePath();} function drawCircleAvatar(ctx,img,cx,cy,r){ctx.save();ctx.beginPath();ctx.arc(cx,cy,r,0,Math.PI*2);ctx.clip();ctx.drawImage(img,cx-r,cy-r,r*2,r*2);ctx.restore();} async function createWelcomeCard({ userName, memberCount, newUserID, inviterID, api }) { const W = 1200, H = 630; const canvas = createCanvas(W, H); const ctx = canvas.getContext('2d'); // RED FOREST BACKGROUND let bgImg = null; try { const localBgPath = path.join(__dirname, "red_bg.jpg"); if (fs.existsSync(localBgPath)) bgImg = await loadImage(localBgPath); } catch {} if (!bgImg) { // fallback online red forest try { const buf = await downloadImage("https://i.ibb.co/3s6Q2jP/red-forest.jpg"); if(buf) bgImg = await loadImage(buf); } catch {} } if (bgImg) ctx.drawImage(bgImg, 0, 0, W, H); else { ctx.fillStyle = '#2b0a0a'; ctx.fillRect(0,0,W,H); } // Dark overlay for text readable ctx.fillStyle = 'rgba(0,0,0,0.55)'; ctx.fillRect(0,0,W,H); // Profile async function loadProfile(uid){ const buf = await downloadHighQualityProfile(uid); if(buf) return loadImage(buf).catch(()=>null); return null; } const [newUserImg, inviterImg] = await Promise.all([loadProfile(newUserID), loadProfile(inviterID)]); const splitX = Math.round(W*0.38); // Left side dark ctx.fillStyle = 'rgba(0,0,0,0.6)'; ctx.fillRect(0,0,splitX,H); const leftCX = splitX/2; const avatarR = 115; const avatarY = H/2 - 20; // Green glow ring like your old code ctx.save(); ctx.shadowColor = 'rgba(46,204,113,0.7)'; ctx.shadowBlur = 25; ctx.strokeStyle = 'rgba(46,204,113,0.9)'; ctx.lineWidth = 3; ctx.beginPath(); ctx.arc(leftCX, avatarY, avatarR+8, 0, Math.PI*2); ctx.stroke(); ctx.restore(); if(newUserImg) drawCircleAvatar(ctx, newUserImg, leftCX, avatarY, avatarR); ctx.textAlign = 'center'; ctx.font = 'bold 30px Arial'; ctx.fillStyle = '#fff'; ctx.fillText(userName.slice(0,22), leftCX, avatarY+avatarR+35); ctx.font = 'bold 16px Arial'; ctx.fillStyle = '#00ff99'; ctx.fillText(`✦ ${ordinal(memberCount)} Member ✦`, leftCX, avatarY+avatarR+65); // Right side text const rX = splitX + 40; ctx.textAlign = 'left'; ctx.font = 'bold 42px Arial'; ctx.fillStyle = '#fff'; ctx.fillText('Welcome To', rX, 120); ctx.fillStyle = '#ff4d4d'; ctx.fillText('CRAZY SQUAD', rX, 170); ctx.font = '18px Arial'; ctx.fillStyle = 'rgba(255,255,255,0.8)'; ctx.fillText(`Hi ${userName}, you're now part of our family!`, rX, 230); ctx.fillText(`Invited by: ${inviterName}`, rX, 260); // Powered by ctx.textAlign = 'center'; ctx.font = 'bold 22px Arial'; const grad = ctx.createLinearGradient(W/2-100,0,W/2+100,0); grad.addColorStop(0,'#fff'); grad.addColorStop(1,'#2ecc71'); ctx.fillStyle = grad; ctx.fillText('Powered By MEHEDI KHAN', rX + (W-rX)/2 - 20, H-80); const tempPath = path.join(__dirname, `temp_welcome_${Date.now()}.png`); await fs.writeFile(tempPath, canvas.toBuffer('image/png')); return tempPath; }