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

Function handler

plugins/promote.js:44–85  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

42 groupOnly: true,
43 adminOnly: true,
44 async handler(sock, message, args, context) {
45 const { chatId, channelInfo } = context;
46 let userToPromote = [];
47 const mentionedJids = message.message?.extendedTextMessage?.contextInfo?.mentionedJid;
48 if (mentionedJids && mentionedJids.length > 0) {
49 userToPromote = mentionedJids;
50 }
51 else if (message.message?.extendedTextMessage?.contextInfo?.participant) {
52 userToPromote = [message.message.extendedTextMessage.contextInfo.participant];
53 }
54 if (userToPromote.length === 0) {
55 await sock.sendMessage(chatId, {
56 text: 'Please mention the user or reply to their message to promote!',
57 ...channelInfo
58 }, { quoted: message });
59 return;
60 }
61 try {
62 await sock.groupParticipantsUpdate(chatId, userToPromote, "promote");
63 const usernames = await Promise.all(userToPromote.map(async (jid) => {
64 return `@${jid.split('@')[0]}`;
65 }));
66 const promoterJid = sock.user.id;
67 const promotionMessage = `*『 GROUP PROMOTION 』*\n\n` +
68 `👥 *Promoted User${userToPromote.length > 1 ? 's' : ''}:*\n` +
69 `${usernames.map(name => `• ${name}`).join('\n')}\n\n` +
70 `👑 *Promoted By:* @${promoterJid.split('@')[0]}\n\n` +
71 `📅 *Date:* ${new Date().toLocaleString()}`;
72 await sock.sendMessage(chatId, {
73 text: promotionMessage,
74 mentions: [...userToPromote, promoterJid],
75 ...channelInfo
76 });
77 }
78 catch (error) {
79 console.error('Error in promote command:', error);
80 await sock.sendMessage(chatId, {
81 text: 'Failed to promote user(s)!',
82 ...channelInfo
83 }, { quoted: message });
84 }
85 },
86 handlePromotionEvent
87};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected