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

Function handler

plugins/starmsg.js:8–53  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

6 usage: '.star — reply to a message | .unstar — reply to a message',
7 ownerOnly: true,
8 async handler(sock, message, args, context) {
9 const chatId = context.chatId || message.key.remoteJid;
10 const channelInfo = context.channelInfo || {};
11 const rawText = (context.rawText || '').toLowerCase();
12 const shouldStar = !rawText.startsWith('.unstar');
13 // contextInfo can be nested in any message type
14 const msg = message.message;
15 const contextInfo = msg?.extendedTextMessage?.contextInfo ||
16 msg?.imageMessage?.contextInfo ||
17 msg?.videoMessage?.contextInfo ||
18 msg?.audioMessage?.contextInfo ||
19 msg?.documentMessage?.contextInfo ||
20 msg?.stickerMessage?.contextInfo ||
21 msg?.buttonsResponseMessage?.contextInfo ||
22 null;
23 if (!contextInfo?.stanzaId) {
24 return await sock.sendMessage(chatId, {
25 text: `*⭐ STAR MESSAGE*\n\n_Reply to any message with:_\n• \`.star\` — to star it\n• \`.unstar\` — to unstar it`,
26 ...channelInfo
27 }, { quoted: message });
28 }
29 const targetId = contextInfo.stanzaId;
30 // Determine fromMe: compare phone numbers only (strip :xx@suffix)
31 const botNum = (sock.user?.id || '').split(':')[0].split('@')[0];
32 const participantNum = (contextInfo.participant || '').split(':')[0].split('@')[0];
33 const fromMe = participantNum ? participantNum === botNum : message.key.fromMe;
34 try {
35 await sock.chatModify({
36 star: {
37 messages: [{ id: targetId, fromMe }],
38 star: shouldStar
39 }
40 }, chatId);
41 await sock.sendMessage(chatId, {
42 text: shouldStar ? `⭐ *Message starred!*` : `✴️ *Message unstarred!*`,
43 ...channelInfo
44 }, { quoted: message });
45 }
46 catch (e) {
47 console.error('[STARMSG] Error:', e.message);
48 await sock.sendMessage(chatId, {
49 text: `❌ Failed to ${shouldStar ? 'star' : 'unstar'} message: ${e.message}`,
50 ...channelInfo
51 }, { quoted: message });
52 }
53 }
54};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected