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