(sock, chatId, message, match)
| 68 | } |
| 69 | |
| 70 | async function handleChatbotCommand(sock, chatId, message, match) { |
| 71 | if (!match) { |
| 72 | await showTyping(sock, chatId); |
| 73 | return sock.sendMessage(chatId, { |
| 74 | text: `*CHATBOT SETUP*\n\n*.chatbot on*\nEnable chatbot\n\n*.chatbot off*\nDisable chatbot in this group`, |
| 75 | quoted: message |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | const data = loadUserGroupData(); |
| 80 | |
| 81 | // Get bot's number |
| 82 | const botNumber = sock.user.id.split(':')[0] + '@s.whatsapp.net'; |
| 83 | |
| 84 | // Check if sender is bot owner |
| 85 | const senderId = message.key.participant || message.participant || message.pushName || message.key.remoteJid; |
| 86 | const isOwner = senderId === botNumber; |
| 87 | |
| 88 | // If it's the bot owner, allow access immediately |
| 89 | if (isOwner) { |
| 90 | if (match === 'on') { |
| 91 | await showTyping(sock, chatId); |
| 92 | if (data.chatbot[chatId]) { |
| 93 | return sock.sendMessage(chatId, { |
| 94 | text: '*Chatbot is already enabled for this group*', |
| 95 | quoted: message |
| 96 | }); |
| 97 | } |
| 98 | data.chatbot[chatId] = true; |
| 99 | saveUserGroupData(data); |
| 100 | console.log(`✅ Chatbot enabled for group ${chatId}`); |
| 101 | return sock.sendMessage(chatId, { |
| 102 | text: '*Chatbot has been enabled for this group*', |
| 103 | quoted: message |
| 104 | }); |
| 105 | } |
| 106 | |
| 107 | if (match === 'off') { |
| 108 | await showTyping(sock, chatId); |
| 109 | if (!data.chatbot[chatId]) { |
| 110 | return sock.sendMessage(chatId, { |
| 111 | text: '*Chatbot is already disabled for this group*', |
| 112 | quoted: message |
| 113 | }); |
| 114 | } |
| 115 | delete data.chatbot[chatId]; |
| 116 | saveUserGroupData(data); |
| 117 | console.log(`✅ Chatbot disabled for group ${chatId}`); |
| 118 | return sock.sendMessage(chatId, { |
| 119 | text: '*Chatbot has been disabled for this group*', |
| 120 | quoted: message |
| 121 | }); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // For non-owners, check admin status |
| 126 | let isAdmin = false; |
| 127 | if (chatId.endsWith('@g.us')) { |
nothing calls this directly
no test coverage detected