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

Function handler

plugins/base64.js:7–31  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

5 description: 'Encode text to Base64',
6 usage: '.base64 <text> OR reply to a message',
7 async handler(sock, message, args, context) {
8 const chatId = context.chatId || message.key.remoteJid;
9 try {
10 let txt = args?.join(' ') || "";
11 const quoted = message.message?.extendedTextMessage?.contextInfo?.quotedMessage;
12 if (quoted) {
13 txt = quoted.conversation ||
14 quoted.extendedTextMessage?.text ||
15 quoted.imageMessage?.caption ||
16 quoted.videoMessage?.caption ||
17 txt;
18 }
19 txt = txt.replace(/^\.\w+\s*/, '').trim();
20 if (!txt) {
21 return await sock.sendMessage(chatId, { text: '*Please provide text to encode or reply to a message.*\nExample: .base64 Hello World' }, { quoted: message });
22 }
23 const encoded = Buffer.from(txt, 'utf-8').toString('base64');
24 const response = `*🔗 Base64 Encoded:*\n\n${encoded}`;
25 await sock.sendMessage(chatId, { text: response }, { quoted: message });
26 }
27 catch (err) {
28 console.error('Base64 plugin error:', err);
29 await sock.sendMessage(chatId, { text: '❌ Failed to encode text.' }, { quoted: message });
30 }
31 }
32};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected