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

Function handler

plugins/urldecode.js:38–175  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

36 description: 'Encode/decode URLs or extract all links from text/files',
37 usage: '.urldecode <url>\n.urlencode <text>\n.extractlinks <text or reply to file>',
38 async handler(sock, message, args, context) {
39 const { chatId, channelInfo, userMessage } = context;
40 const scriptPath = path.join(process.cwd(), 'lib', 'urltool.py');
41 if (!fs.existsSync(scriptPath)) {
42 return await sock.sendMessage(chatId, {
43 text: `❌ urltool.py not found in lib/.`,
44 ...channelInfo
45 }, { quoted: message });
46 }
47 const quoted = getQuoted(message);
48 const quotedText = quoted?.conversation || quoted?.extendedTextMessage?.text || '';
49 const hasDoc = !!quoted?.documentMessage;
50 // Detect mode from command used
51 let mode = 'decode';
52 if (userMessage.startsWith('urlencode') || userMessage.startsWith('/urlencode') ||
53 userMessage.startsWith('.urlencode') || userMessage.startsWith('!urlencode')) {
54 mode = 'encode';
55 }
56 else if (userMessage.startsWith('extractlinks') || userMessage.startsWith('/extractlinks') ||
57 userMessage.startsWith('.extractlinks') || userMessage.startsWith('!extractlinks') ||
58 userMessage.startsWith('links')) {
59 mode = 'extract';
60 }
61 else if (args[0]?.toLowerCase() === 'encode') {
62 mode = 'encode';
63 args = args.slice(1);
64 }
65 else if (args[0]?.toLowerCase() === 'extract' || args[0]?.toLowerCase() === 'links') {
66 mode = 'extract';
67 args = args.slice(1);
68 }
69 else if (args[0]?.toLowerCase() === 'decode') {
70 mode = 'decode';
71 args = args.slice(1);
72 }
73 const textInput = args.join(' ').trim() || quotedText;
74 if (!textInput && !hasDoc) {
75 return await sock.sendMessage(chatId, {
76 text: `🌐 *URL Tools*\n\n` +
77 `*Decode a URL:*\n` +
78 `\`.urldecode https://example.com/path%20with%20spaces\`\n\n` +
79 `*Encode text to URL:*\n` +
80 `\`.urlencode hello world & more\`\n\n` +
81 `*Extract all links from text:*\n` +
82 `\`.extractlinks <paste text>\`\n` +
83 `Or reply to any text message or file with \`.extractlinks\`\n\n` +
84 `*Shortcut modes:*\n` +
85 `\`.urldecode encode <text>\`\n` +
86 `\`.urldecode extract <text>\``,
87 ...channelInfo
88 }, { quoted: message });
89 }
90 const tempDir = path.join(process.cwd(), 'temp');
91 fs.mkdirSync(tempDir, { recursive: true });
92 const id = Date.now();
93 try {
94 let stdout;
95 if (hasDoc && quoted && mode === 'extract') {

Callers

nothing calls this directly

Calls 3

getQuotedFunction · 0.70
downloadMediaMessageFunction · 0.70
sendResultFunction · 0.70

Tested by

no test coverage detected