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

Function handler

plugins/getplugin.js:24–67  ·  view source on GitHub ↗
(sock, message, args, _context)

Source from the content-addressed store, hash-verified

22 usage: '.inspect [plugin_name]',
23 ownerOnly: true,
24 async handler(sock, message, args, _context) {
25 const chatId = message.key.remoteJid;
26 const pluginName = args[0];
27 if (!pluginName) {
28 return await sock.sendMessage(chatId, { text: 'Which plugin do you want to inspect?\n\n*Examples:*\n- .inspect ping\n- .inspect ping.ts\n- .inspect ping.js' }, { quoted: message });
29 }
30 try {
31 const base = pluginName.replace(/\.(ts|js)$/, '');
32 let filePath;
33 let fileName;
34 if (pluginName.endsWith('.js')) {
35 filePath = path.join(process.cwd(), 'plugins', `${base }.js`);
36 fileName = `${base }.js`;
37 }
38 else {
39 filePath = path.join(process.cwd(), 'plugins', `${base }.ts`);
40 fileName = `${base }.ts`;
41 if (!fs.existsSync(filePath)) {
42 filePath = path.join(process.cwd(), 'plugins', `${base }.js`);
43 fileName = `${base }.js`;
44 }
45 }
46 if (!fs.existsSync(filePath)) {
47 return await sock.sendMessage(chatId, { text: `❌ Plugin "${base}" not found.` }, { quoted: message });
48 }
49 const code = fs.readFileSync(filePath, 'utf8');
50 const formattedCode = `💻 *SOURCE CODE: ${fileName}*\n\n\`\`\`javascript\n${code}\n\`\`\``;
51 if (formattedCode.length > 4000) {
52 await sock.sendMessage(chatId, {
53 document: Buffer.from(code),
54 fileName,
55 mimetype: 'text/javascript',
56 caption: `📄 Code for *${fileName}* (File too large for text message)`
57 }, { quoted: message });
58 }
59 else {
60 await sock.sendMessage(chatId, { text: formattedCode }, { quoted: message });
61 }
62 }
63 catch (error) {
64 console.error('Inspect Error:', error);
65 await sock.sendMessage(chatId, { text: '❌ Failed to read the plugin file.' });
66 }
67 }
68};
69/*****************************************************************************
70 * *

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected