MCPcopy
hub / github.com/mruniquehacker/Knightbot-MD / tagNotAdminCommand

Function tagNotAdminCommand

commands/tagnotadmin.js:3–36  ·  view source on GitHub ↗
(sock, chatId, senderId, message)

Source from the content-addressed store, hash-verified

1const isAdmin = require('../lib/isAdmin');
2
3async function tagNotAdminCommand(sock, chatId, senderId, message) {
4 try {
5 const { isSenderAdmin, isBotAdmin } = await isAdmin(sock, chatId, senderId);
6
7 if (!isBotAdmin) {
8 await sock.sendMessage(chatId, { text: 'Please make the bot an admin first.' }, { quoted: message });
9 return;
10 }
11
12 if (!isSenderAdmin) {
13 await sock.sendMessage(chatId, { text: 'Only admins can use the .tagnotadmin command.' }, { quoted: message });
14 return;
15 }
16
17 const groupMetadata = await sock.groupMetadata(chatId);
18 const participants = groupMetadata.participants || [];
19
20 const nonAdmins = participants.filter(p => !p.admin).map(p => p.id);
21 if (nonAdmins.length === 0) {
22 await sock.sendMessage(chatId, { text: 'No non-admin members to tag.' }, { quoted: message });
23 return;
24 }
25
26 let text = '🔊 *Hello Everyone:*\n\n';
27 nonAdmins.forEach(jid => {
28 text += `@${jid.split('@')[0]}\n`;
29 });
30
31 await sock.sendMessage(chatId, { text, mentions: nonAdmins }, { quoted: message });
32 } catch (error) {
33 console.error('Error in tagnotadmin command:', error);
34 await sock.sendMessage(chatId, { text: 'Failed to tag non-admin members.' }, { quoted: message });
35 }
36}
37
38module.exports = tagNotAdminCommand;
39

Callers 1

handleMessagesFunction · 0.85

Calls 1

isAdminFunction · 0.85

Tested by

no test coverage detected