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

Function handler

plugins/urldecode.ts:40–178  ·  view source on GitHub ↗
(sock: any, message: any, args: any[], context: BotContext)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

getQuotedFunction · 0.70
downloadMediaMessageFunction · 0.70
sendResultFunction · 0.70

Tested by

no test coverage detected