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