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

Function handler

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

Source from the content-addressed store, hash-verified

21 usage: '.sudo add|del|list <@user|number>',
22 strictOwnerOnly: true,
23 async handler(sock, message, args, context) {
24 const chatId = context.chatId || message.key.remoteJid;
25 const config = context.config;
26 const _senderJid = message.key.participant || message.key.remoteJid;
27 const isGroup = chatId.endsWith('@g.us');
28 const isOwner = message.key.fromMe || isOwnerOrSudo;
29 const sub = (args[0] || '').toLowerCase();
30 if (!sub || !['add', 'del', 'remove', 'list'].includes(sub)) {
31 await sock.sendMessage(chatId, {
32 text: '╭━━━〔 *SUDO MANAGER* 〕━━━┈\n┃\n┃ 📝 *Usage:*\n┃ ▢ .sudo add <@tag/reply/num>\n┃ ▢ .sudo del <@tag/reply/num>\n┃ ▢ .sudo list\n┃\n╰━━━━━━━━━━━━━━━━━━┈'
33 }, { quoted: message });
34 return;
35 }
36 if (sub === 'list') {
37 const list = await getSudoList();
38 if (list.length === 0) {
39 await sock.sendMessage(chatId, { text: '❌ No sudo users found.' }, { quoted: message });
40 return;
41 }
42 const textList = list.map((j, i) => `┃ ${i + 1}. @${cleanJid(j)}`).join('\n');
43 await sock.sendMessage(chatId, {
44 text: `╭━━〔 *SUDO USERS* 〕━━┈\n┃\n${textList}\n┃\n╰━━━━━━━━━━━━━━━┈`,
45 mentions: list
46 }, { quoted: message });
47 return;
48 }
49 if (!isOwner) {
50 await sock.sendMessage(chatId, { text: '❌ *Access Denied:* Only the Main Owner can manage Sudo privileges.' }, { quoted: message });
51 return;
52 }
53 const targetJid = extractTargetJid(message, args.slice(1));
54 if (!targetJid) {
55 await sock.sendMessage(chatId, { text: '❌ Please mention a user, reply to a message, or provide a number.' }, { quoted: message });
56 return;
57 }
58 let displayId = cleanJid(targetJid);
59 if (targetJid.includes('@lid') && isGroup) {
60 try {
61 const metadata = await sock.groupMetadata(chatId);
62 const found = metadata.participants.find((p) => p.lid === targetJid || p.id === targetJid);
63 if (found && found.id && !found.id.includes('@lid')) {
64 displayId = cleanJid(found.id);
65 }
66 }
67 catch (e) { }
68 }
69 if (sub === 'add') {
70 const ok = await addSudo(targetJid);
71 await sock.sendMessage(chatId, {
72 text: ok ? `✅ *Success:* @${displayId} has been granted Sudo privileges.` : `❌ *Error:* Failed to add sudo.`,
73 mentions: [targetJid]
74 }, { quoted: message });
75 return;
76 }
77 if (sub === 'del' || sub === 'remove') {
78 const ownerNumberClean = cleanJid(config.ownerNumber);
79 if (displayId === ownerNumberClean) {
80 await sock.sendMessage(chatId, { text: '❌ *Action Denied:* Cannot remove the Main Owner.' }, { quoted: message });

Callers

nothing calls this directly

Calls 5

getSudoListFunction · 0.90
cleanJidFunction · 0.90
addSudoFunction · 0.90
removeSudoFunction · 0.90
extractTargetJidFunction · 0.85

Tested by

no test coverage detected