(sock, chatId, senderId, message)
| 1 | const isAdmin = require('../lib/isAdmin'); // Move isAdmin to helpers |
| 2 | |
| 3 | async function tagAllCommand(sock, chatId, senderId, message) { |
| 4 | try { |
| 5 | const { isSenderAdmin, isBotAdmin } = await isAdmin(sock, chatId, senderId); |
| 6 | |
| 7 | |
| 8 | if (!isBotAdmin) { |
| 9 | await sock.sendMessage(chatId, { text: 'Please make the bot an admin first.' }, { quoted: message }); |
| 10 | return; |
| 11 | } |
| 12 | |
| 13 | if (!isSenderAdmin) { |
| 14 | await sock.sendMessage(chatId, { text: 'Only group admins can use the .tagall command.' }, { quoted: message }); |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | // Get group metadata |
| 19 | const groupMetadata = await sock.groupMetadata(chatId); |
| 20 | const participants = groupMetadata.participants; |
| 21 | |
| 22 | if (!participants || participants.length === 0) { |
| 23 | await sock.sendMessage(chatId, { text: 'No participants found in the group.' }); |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | // Create message with each member on a new line |
| 28 | let messageText = '🔊 *Hello Everyone:*\n\n'; |
| 29 | participants.forEach(participant => { |
| 30 | messageText += `@${participant.id.split('@')[0]}\n`; // Add \n for new line |
| 31 | }); |
| 32 | |
| 33 | // Send message with mentions |
| 34 | await sock.sendMessage(chatId, { |
| 35 | text: messageText, |
| 36 | mentions: participants.map(p => p.id) |
| 37 | }); |
| 38 | |
| 39 | } catch (error) { |
| 40 | console.error('Error in tagall command:', error); |
| 41 | await sock.sendMessage(chatId, { text: 'Failed to tag all members.' }); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | module.exports = tagAllCommand; // Export directly |
no test coverage detected