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

Function handler

plugins/gcadd.js:23–123  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

21 groupOnly: true,
22 adminOnly: true,
23 async handler(sock, message, args, context) {
24 const { chatId, channelInfo } = context;
25 let targetNumber = null;
26 if (message.message?.extendedTextMessage?.contextInfo?.quotedMessage) {
27 const quotedMsg = message.message.extendedTextMessage.contextInfo.quotedMessage;
28 const quotedParticipant = message.message.extendedTextMessage.contextInfo.participant;
29 if (quotedMsg.contactMessage) {
30 const vcard = quotedMsg.contactMessage.vcard;
31 const phoneMatch = vcard.match(/waid=(\d+)/);
32 if (phoneMatch) {
33 targetNumber = phoneMatch[1];
34 }
35 else {
36 const telMatch = vcard.match(/TEL.*?:(\+?\d+)/);
37 if (telMatch) {
38 targetNumber = telMatch[1].replace(/\D/g, '');
39 }
40 }
41 }
42 else if (quotedMsg.conversation || quotedMsg.extendedTextMessage?.text) {
43 const text = quotedMsg.conversation || quotedMsg.extendedTextMessage.text;
44 const numberMatch = text.match(/(\+?\d{10,15})/);
45 if (numberMatch) {
46 targetNumber = numberMatch[1].replace(/\D/g, '');
47 }
48 }
49 else if (quotedParticipant) {
50 targetNumber = quotedParticipant.split('@')[0];
51 }
52 }
53 if (!targetNumber && args.length > 0) {
54 const input = args.join(' ');
55 const cleaned = input.replace(/[^\d+]/g, '');
56 targetNumber = cleaned.replace(/^\+/, '');
57 }
58 if (!targetNumber) {
59 return await sock.sendMessage(chatId, {
60 text: `❌ *Please provide a number to add!*
61
62*Usage:*
63• \`.add 923051234567\`
64• \`.add +923051234567\`
65• \`.add 92 305 1234567\`
66• Reply to a vcard with \`.add\`
67• Reply to a message with \`.add\``,
68 ...channelInfo
69 }, { quoted: message });
70 }
71 if (!targetNumber.startsWith('1') && !targetNumber.startsWith('2') && !targetNumber.startsWith('3') &&
72 !targetNumber.startsWith('4') && !targetNumber.startsWith('5') && !targetNumber.startsWith('6') &&
73 !targetNumber.startsWith('7') && !targetNumber.startsWith('8') && !targetNumber.startsWith('9')) {
74 return await sock.sendMessage(chatId, {
75 text: '❌ *Invalid number format!*\n\nPlease include the country code.\nExample: 923051234567',
76 ...channelInfo
77 }, { quoted: message });
78 }
79 const targetJid = `${targetNumber}@s.whatsapp.net`;
80 try {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected