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

Function tagCommand

commands/tag.js:17–86  ·  view source on GitHub ↗
(sock, chatId, senderId, messageText, replyMessage, message)

Source from the content-addressed store, hash-verified

15}
16
17async function tagCommand(sock, chatId, senderId, messageText, replyMessage, message) {
18 const { isSenderAdmin, isBotAdmin } = await isAdmin(sock, chatId, senderId);
19
20 if (!isBotAdmin) {
21 await sock.sendMessage(chatId, { text: 'Please make the bot an admin first.' }, { quoted: message });
22 return;
23 }
24
25 if (!isSenderAdmin) {
26 const stickerPath = './assets/sticktag.webp'; // Path to your sticker
27 if (fs.existsSync(stickerPath)) {
28 const stickerBuffer = fs.readFileSync(stickerPath);
29 await sock.sendMessage(chatId, { sticker: stickerBuffer }, { quoted: message });
30 }
31 return;
32 }
33
34 const groupMetadata = await sock.groupMetadata(chatId);
35 const participants = groupMetadata.participants;
36 const mentionedJidList = participants.map(p => p.id);
37
38 if (replyMessage) {
39 let messageContent = {};
40
41 // Handle image messages
42 if (replyMessage.imageMessage) {
43 const filePath = await downloadMediaMessage(replyMessage.imageMessage, 'image');
44 messageContent = {
45 image: { url: filePath },
46 caption: messageText || replyMessage.imageMessage.caption || '',
47 mentions: mentionedJidList
48 };
49 }
50 // Handle video messages
51 else if (replyMessage.videoMessage) {
52 const filePath = await downloadMediaMessage(replyMessage.videoMessage, 'video');
53 messageContent = {
54 video: { url: filePath },
55 caption: messageText || replyMessage.videoMessage.caption || '',
56 mentions: mentionedJidList
57 };
58 }
59 // Handle text messages
60 else if (replyMessage.conversation || replyMessage.extendedTextMessage) {
61 messageContent = {
62 text: replyMessage.conversation || replyMessage.extendedTextMessage.text,
63 mentions: mentionedJidList
64 };
65 }
66 // Handle document messages
67 else if (replyMessage.documentMessage) {
68 const filePath = await downloadMediaMessage(replyMessage.documentMessage, 'document');
69 messageContent = {
70 document: { url: filePath },
71 fileName: replyMessage.documentMessage.fileName,
72 caption: messageText || '',
73 mentions: mentionedJidList
74 };

Callers 1

handleMessagesFunction · 0.85

Calls 2

isAdminFunction · 0.85
downloadMediaMessageFunction · 0.70

Tested by

no test coverage detected