MCPcopy
hub / github.com/mruniquehacker/Knightbot-MD / isOwnerOrSudo

Function isOwnerOrSudo

lib/isOwner.js:4–82  ·  view source on GitHub ↗
(senderId, sock = null, chatId = null)

Source from the content-addressed store, hash-verified

2const { isSudo } = require('./index');
3
4async 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) {

Callers 12

handleMessagesFunction · 0.85
autoreadCommandFunction · 0.85
setProfilePictureFunction · 0.85
pmblockerCommandFunction · 0.85
handleAntideleteCommandFunction · 0.85
clearTmpCommandFunction · 0.85
sudoCommandFunction · 0.85
clearSessionCommandFunction · 0.85
autoStatusCommandFunction · 0.85
updateCommandFunction · 0.85
autotypingCommandFunction · 0.85
settingsCommandFunction · 0.85

Calls 1

isSudoFunction · 0.85

Tested by

no test coverage detected