(senderId, sock = null, chatId = null)
| 2 | const { isSudo } = require('./index'); |
| 3 | |
| 4 | async function isOwnerOrSudo(senderId, sock = null, chatId = null) { |
| 5 | const ownerJid = settings.ownerNumber + "@s.whatsapp.net"; |
| 6 | const ownerNumberClean = settings.ownerNumber.split(':')[0].split('@')[0]; |
| 7 | |
| 8 | // Direct JID match |
| 9 | if (senderId === ownerJid) { |
| 10 | return true; |
| 11 | } |
| 12 | |
| 13 | // Extract sender's numeric parts |
| 14 | const senderIdClean = senderId.split(':')[0].split('@')[0]; |
| 15 | const senderLidNumeric = senderId.includes('@lid') ? senderId.split('@')[0].split(':')[0] : ''; |
| 16 | |
| 17 | // Check if sender's phone number matches owner number |
| 18 | if (senderIdClean === ownerNumberClean) { |
| 19 | return true; |
| 20 | } |
| 21 | |
| 22 | // In groups, check if sender's LID matches bot's LID (owner uses same account as bot) |
| 23 | if (sock && chatId && chatId.endsWith('@g.us') && senderId.includes('@lid')) { |
| 24 | try { |
| 25 | // Get bot's LID numeric |
| 26 | const botLid = sock.user?.lid || ''; |
| 27 | const botLidNumeric = botLid.includes(':') ? botLid.split(':')[0] : (botLid.includes('@') ? botLid.split('@')[0] : botLid); |
| 28 | |
| 29 | // Check if sender's LID numeric matches bot's LID numeric |
| 30 | if (senderLidNumeric && botLidNumeric && senderLidNumeric === botLidNumeric) { |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | // Also check participant data for additional matching |
| 35 | const metadata = await sock.groupMetadata(chatId); |
| 36 | const participants = metadata.participants || []; |
| 37 | |
| 38 | const participant = participants.find(p => { |
| 39 | const pLid = p.lid || ''; |
| 40 | const pLidNumeric = pLid.includes(':') ? pLid.split(':')[0] : (pLid.includes('@') ? pLid.split('@')[0] : pLid); |
| 41 | const pId = p.id || ''; |
| 42 | const pIdClean = pId.split(':')[0].split('@')[0]; |
| 43 | |
| 44 | return ( |
| 45 | p.lid === senderId || |
| 46 | p.id === senderId || |
| 47 | pLidNumeric === senderLidNumeric || |
| 48 | pIdClean === senderIdClean || |
| 49 | pIdClean === ownerNumberClean |
| 50 | ); |
| 51 | }); |
| 52 | |
| 53 | if (participant) { |
| 54 | const participantId = participant.id || ''; |
| 55 | const participantLid = participant.lid || ''; |
| 56 | const participantIdClean = participantId.split(':')[0].split('@')[0]; |
| 57 | const participantLidNumeric = participantLid.includes(':') ? participantLid.split(':')[0] : (participantLid.includes('@') ? participantLid.split('@')[0] : participantLid); |
| 58 | |
| 59 | if (participantId === ownerJid || |
| 60 | participantIdClean === ownerNumberClean || |
| 61 | participantLidNumeric === botLidNumeric) { |
no test coverage detected