* Advanced bot mode system with multiple access control options * Modes: * - public: Everyone can use (groups + private) * - private: Owner/sudo only * - groups: Only works in groups (everyone in groups) * - inbox: Only works in private chats (everyone in DM) * - self: Owner/sudo only (alias f
(sock, message, args, context)
| 9 | * - self: Owner/sudo only (alias for private) |
| 10 | */ |
| 11 | async function modeCommand(sock, message, args, context) { |
| 12 | const { chatId, channelInfo } = context; |
| 13 | const _senderId = message.key.participant || message.key.remoteJid; |
| 14 | const isOwnerOrSudoCheck = message.key.fromMe || context.senderIsOwnerOrSudo || context.isOwnerOrSudoCheck; |
| 15 | if (!isOwnerOrSudoCheck) { |
| 16 | return await sock.sendMessage(chatId, { |
| 17 | text: '❌ Only the owner or sudo users can change bot mode!', |
| 18 | ...channelInfo |
| 19 | }, { quoted: message }); |
| 20 | } |
| 21 | const subCommand = args[0]?.toLowerCase(); |
| 22 | const currentMode = await store.getBotMode() || 'public'; |
| 23 | if (!subCommand || subCommand === 'status' || subCommand === 'check') { |
| 24 | const modeEmojis = { |
| 25 | public: '🌍', |
| 26 | private: '🔒', |
| 27 | groups: '👥', |
| 28 | inbox: '💬', |
| 29 | self: '👤' |
| 30 | }; |
| 31 | const modeDescriptions = { |
| 32 | public: 'Everyone can use bot (groups + private chats)', |
| 33 | private: 'Only owner and sudo users can use bot', |
| 34 | groups: 'Only works in group chats (everyone in groups)', |
| 35 | inbox: 'Only works in private chats (everyone in DMs)', |
| 36 | self: 'Owner and sudo only (same as private)' |
| 37 | }; |
| 38 | let statusText = `📊 *BOT MODE STATUS*\n\n`; |
| 39 | statusText += `Current Mode: ${modeEmojis[currentMode]} *${currentMode.toUpperCase()}*\n`; |
| 40 | statusText += `Description: ${modeDescriptions[currentMode]}\n\n`; |
| 41 | statusText += `━━━━━━━━━━━━━━━━━━━━\n\n`; |
| 42 | statusText += `*Available Modes:*\n\n`; |
| 43 | Object.entries(modeDescriptions).forEach(([mode, desc]) => { |
| 44 | const current = mode === currentMode ? '✓ ' : ''; |
| 45 | statusText += `${current}${modeEmojis[mode]} \`${mode}\`\n${desc}\n\n`; |
| 46 | }); |
| 47 | statusText += `*Usage:*\n`; |
| 48 | statusText += `• \`.mode <mode>\` - Change mode\n`; |
| 49 | statusText += `• \`.mode status\` - Show current mode\n\n`; |
| 50 | statusText += `*Examples:*\n`; |
| 51 | statusText += `• \`.mode public\` - Enable for everyone\n`; |
| 52 | statusText += `• \`.mode groups\` - Groups only\n`; |
| 53 | statusText += `• \`.mode inbox\` - Private chats only\n`; |
| 54 | statusText += `• \`.mode private\` - Owner/sudo only`; |
| 55 | return await sock.sendMessage(chatId, { |
| 56 | text: statusText, |
| 57 | ...channelInfo |
| 58 | }, { quoted: message }); |
| 59 | } |
| 60 | const validModes = ['public', 'private', 'groups', 'inbox', 'self']; |
| 61 | if (!validModes.includes(subCommand)) { |
| 62 | return await sock.sendMessage(chatId, { |
| 63 | text: `❌ Invalid mode: *${subCommand}*\n\nValid modes: ${validModes.join(', ')}\n\nUse \`.mode\` to see all available modes.`, |
| 64 | ...channelInfo |
| 65 | }, { quoted: message }); |
| 66 | } |
| 67 | await store.setBotMode(subCommand); |
| 68 | const modeEmojis = { |
nothing calls this directly
no outgoing calls
no test coverage detected