(sock, message, args, context)
| 7 | groupOnly: true, |
| 8 | adminOnly: true, |
| 9 | async handler(sock, message, args, context) { |
| 10 | const chatId = context.chatId || message.key.remoteJid; |
| 11 | const isBotAdmin = context.isBotAdmin; |
| 12 | if (!isBotAdmin) { |
| 13 | await sock.sendMessage(chatId, { |
| 14 | text: '❌ *Please make the bot an admin first*' |
| 15 | }, { quoted: message }); |
| 16 | return; |
| 17 | } |
| 18 | let usersToKick = []; |
| 19 | const mentionedJids = message.message?.extendedTextMessage?.contextInfo?.mentionedJid; |
| 20 | if (mentionedJids && mentionedJids.length > 0) { |
| 21 | usersToKick = mentionedJids; |
| 22 | } |
| 23 | else if (message.message?.extendedTextMessage?.contextInfo?.participant) { |
| 24 | usersToKick = [message.message.extendedTextMessage.contextInfo.participant]; |
| 25 | } |
| 26 | if (usersToKick.length === 0) { |
| 27 | await sock.sendMessage(chatId, { |
| 28 | text: '❌ *Please mention a user or reply to their message*\n\nUsage: `.kick @user` or reply with `.kick`' |
| 29 | }, { quoted: message }); |
| 30 | return; |
| 31 | } |
| 32 | const botId = sock.user?.id || ''; |
| 33 | const botLid = sock.user?.lid || ''; |
| 34 | const botPhoneNumber = botId.includes(':') ? botId.split(':')[0] : (botId.includes('@') ? botId.split('@')[0] : botId); |
| 35 | const botIdFormatted = `${botPhoneNumber }@s.whatsapp.net`; |
| 36 | const botLidNumeric = botLid.includes(':') ? botLid.split(':')[0] : (botLid.includes('@') ? botLid.split('@')[0] : botLid); |
| 37 | const botLidWithoutSuffix = botLid.includes('@') ? botLid.split('@')[0] : botLid; |
| 38 | const metadata = await sock.groupMetadata(chatId); |
| 39 | const participants = metadata.participants || []; |
| 40 | const isTryingToKickBot = usersToKick.some((userId) => { |
| 41 | const userPhoneNumber = userId.includes(':') ? userId.split(':')[0] : (userId.includes('@') ? userId.split('@')[0] : userId); |
| 42 | const userLidNumeric = userId.includes('@lid') ? userId.split('@')[0].split(':')[0] : ''; |
| 43 | const directMatch = (userId === botId || |
| 44 | userId === botLid || |
| 45 | userId === botIdFormatted || |
| 46 | userPhoneNumber === botPhoneNumber || |
| 47 | (userLidNumeric && botLidNumeric && userLidNumeric === botLidNumeric)); |
| 48 | if (directMatch) { |
| 49 | return true; |
| 50 | } |
| 51 | const participantMatch = participants.some((p) => { |
| 52 | const pPhoneNumber = p.phoneNumber ? p.phoneNumber.split('@')[0] : ''; |
| 53 | const pId = p.id ? p.id.split('@')[0] : ''; |
| 54 | const pLid = p.lid ? p.lid.split('@')[0] : ''; |
| 55 | const pFullId = p.id || ''; |
| 56 | const pFullLid = p.lid || ''; |
| 57 | const pLidNumeric = pLid.includes(':') ? pLid.split(':')[0] : pLid; |
| 58 | const isThisParticipantBot = (pFullId === botId || |
| 59 | pFullLid === botLid || |
| 60 | pLidNumeric === botLidNumeric || |
| 61 | pPhoneNumber === botPhoneNumber || |
| 62 | pId === botPhoneNumber || |
| 63 | p.phoneNumber === botIdFormatted || |
| 64 | (botLid && pLid && botLidWithoutSuffix === pLid)); |
| 65 | if (isThisParticipantBot) { |
| 66 | return (userId === pFullId || |
nothing calls this directly
no outgoing calls
no test coverage detected