(sock, message, args, context)
| 37 | usage: '.unban [@user] or reply to message', |
| 38 | ownerOnly: false, |
| 39 | async handler(sock, message, args, context) { |
| 40 | const { chatId, isGroup, channelInfo, senderIsOwnerOrSudo, isSenderAdmin, isBotAdmin } = context; |
| 41 | if (isGroup) { |
| 42 | if (!isBotAdmin) { |
| 43 | await sock.sendMessage(chatId, { |
| 44 | text: 'Please make the bot an admin to use .unban', |
| 45 | ...channelInfo |
| 46 | }, { quoted: message }); |
| 47 | return; |
| 48 | } |
| 49 | if (!isSenderAdmin && !message.key.fromMe && !senderIsOwnerOrSudo) { |
| 50 | await sock.sendMessage(chatId, { |
| 51 | text: 'Only group admins can use .unban', |
| 52 | ...channelInfo |
| 53 | }, { quoted: message }); |
| 54 | return; |
| 55 | } |
| 56 | } |
| 57 | else { |
| 58 | if (!message.key.fromMe && !senderIsOwnerOrSudo) { |
| 59 | await sock.sendMessage(chatId, { |
| 60 | text: 'Only owner/sudo can use .unban in private chat', |
| 61 | ...channelInfo |
| 62 | }, { quoted: message }); |
| 63 | return; |
| 64 | } |
| 65 | } |
| 66 | let userToUnban; |
| 67 | if (message.message?.extendedTextMessage?.contextInfo?.mentionedJid?.length > 0) { |
| 68 | userToUnban = message.message.extendedTextMessage.contextInfo.mentionedJid[0]; |
| 69 | } |
| 70 | else if (message.message?.extendedTextMessage?.contextInfo?.participant) { |
| 71 | userToUnban = message.message.extendedTextMessage.contextInfo.participant; |
| 72 | } |
| 73 | if (!userToUnban) { |
| 74 | await sock.sendMessage(chatId, { |
| 75 | text: 'Please mention the user or reply to their message to unban!', |
| 76 | ...channelInfo |
| 77 | }, { quoted: message }); |
| 78 | return; |
| 79 | } |
| 80 | try { |
| 81 | const bannedUsers = await getBannedUsers(); |
| 82 | const index = bannedUsers.indexOf(userToUnban); |
| 83 | if (index > -1) { |
| 84 | bannedUsers.splice(index, 1); |
| 85 | await saveBannedUsers(bannedUsers); |
| 86 | await sock.sendMessage(chatId, { |
| 87 | text: `✅ Successfully unbanned @${userToUnban.split('@')[0]}!\n\nStorage: ${HAS_DB ? 'Database' : 'File System'}`, |
| 88 | mentions: [userToUnban], |
| 89 | ...channelInfo |
| 90 | }, { quoted: message }); |
| 91 | } |
| 92 | else { |
| 93 | await sock.sendMessage(chatId, { |
| 94 | text: `@${userToUnban.split('@')[0]} is not banned!`, |
| 95 | mentions: [userToUnban], |
| 96 | ...channelInfo |
nothing calls this directly
no test coverage detected