MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MDX / handler

Function handler

plugins/getpp.ts:9–84  ·  view source on GitHub ↗
(sock: any, message: any, args: any, _context: BotContext)

Source from the content-addressed store, hash-verified

7 usage: '.getpp @user or reply or number',
8
9 async handler(sock: any, message: any, args: any, _context: BotContext) {
10 const chatId = message.key.remoteJid;
11 const isGroup = chatId.endsWith('@g.us');
12
13 let target;
14 let displayName = 'Unknown';
15 let displayNumber = '';
16
17 const quoted = message.message?.extendedTextMessage?.contextInfo;
18
19 if (quoted?.mentionedJid?.[0]) {
20 target = quoted.mentionedJid[0];
21 } else if (quoted?.participant) {
22 target = quoted.participant;
23 if (quoted.pushName) displayName = quoted.pushName;
24 } else if (args[0]) {
25 const input = args[0].replace(/[^0-9]/g, '');
26 if (input.length >= 10) {
27 target = input + '@s.whatsapp.net';
28 displayName = ''; // Will be resolved later, don't show Unknown
29 } else {
30 return await sock.sendMessage(chatId, {
31 text: '❌ Invalid number. Use format: 923051234567 or +923051234567'
32 }, { quoted: message });
33 }
34 } else {
35 return await sock.sendMessage(chatId, {
36 text: '📸 *Get Profile Picture*\n\nUsage:\n• Reply to a message\n• Mention someone: `.getpp @user`\n• Provide a number: `.getpp 923001234567`'
37 }, { quoted: message });
38 }
39
40 try {
41 let realJid = target;
42
43 if (target.endsWith('@lid') && isGroup) {
44 const metadata = await sock.groupMetadata(chatId);
45 const participant = metadata.participants.find((p: any) => p.lid === target || p.id === target);
46 if (participant?.id) {
47 realJid = participant.id;
48 }
49 }
50
51 const cleanNumber = realJid.replace(/@s\.whatsapp\.net|@lid/g, '').split(':')[0];
52 // Only show number if it looks like a real phone number (10+ digits)
53 displayNumber = cleanNumber.length >= 10 ? `+${cleanNumber}` : '';
54
55 if (displayName === 'Unknown') {
56 try {
57 const name = await sock.getName(realJid);
58 if (name && !name.startsWith('+')) displayName = name;
59 } catch(e: any) {}
60 }
61
62 let ppUrl = null;
63 try {
64 ppUrl = await sock.profilePictureUrl(realJid, 'image');
65 } catch(e: any) {
66 return await sock.sendMessage(chatId, {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected