MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / handler

Function handler

plugins/tag.js:22–77  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

20 groupOnly: true,
21 adminOnly: true,
22 async handler(sock, message, args, context) {
23 const { chatId, channelInfo } = context;
24 const groupMetadata = await sock.groupMetadata(chatId);
25 const participants = groupMetadata.participants;
26 const mentionedJidList = participants.map((p) => p.id);
27 const replyMessage = message.message?.extendedTextMessage?.contextInfo?.quotedMessage;
28 const tagText = args.join(' ');
29 if (replyMessage) {
30 let messageContent = {};
31 if (replyMessage.imageMessage) {
32 const filePath = await downloadMediaMessage(replyMessage.imageMessage, 'image');
33 messageContent = {
34 image: { url: filePath },
35 caption: tagText || replyMessage.imageMessage.caption || '',
36 mentions: mentionedJidList,
37 ...channelInfo
38 };
39 }
40 else if (replyMessage.videoMessage) {
41 const filePath = await downloadMediaMessage(replyMessage.videoMessage, 'video');
42 messageContent = {
43 video: { url: filePath },
44 caption: tagText || replyMessage.videoMessage.caption || '',
45 mentions: mentionedJidList,
46 ...channelInfo
47 };
48 }
49 else if (replyMessage.conversation || replyMessage.extendedTextMessage) {
50 messageContent = {
51 text: replyMessage.conversation || replyMessage.extendedTextMessage.text,
52 mentions: mentionedJidList,
53 ...channelInfo
54 };
55 }
56 else if (replyMessage.documentMessage) {
57 const filePath = await downloadMediaMessage(replyMessage.documentMessage, 'document');
58 messageContent = {
59 document: { url: filePath },
60 fileName: replyMessage.documentMessage.fileName,
61 caption: tagText || '',
62 mentions: mentionedJidList,
63 ...channelInfo
64 };
65 }
66 if (Object.keys(messageContent).length > 0) {
67 await sock.sendMessage(chatId, messageContent);
68 }
69 }
70 else {
71 await sock.sendMessage(chatId, {
72 text: tagText || "Tagged message",
73 mentions: mentionedJidList,
74 ...channelInfo
75 });
76 }
77 }
78};

Callers

nothing calls this directly

Calls 1

downloadMediaMessageFunction · 0.70

Tested by

no test coverage detected