(sock: any, message: any, args: any, _context: BotContext)
| 27 | ownerOnly: true, |
| 28 | |
| 29 | async handler(sock: any, message: any, args: any, _context: BotContext) { |
| 30 | const chatId = message.key.remoteJid; |
| 31 | |
| 32 | const pluginName = args[0]; |
| 33 | if (!pluginName) { |
| 34 | 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 }); |
| 35 | } |
| 36 | |
| 37 | try { |
| 38 | const base = pluginName.replace(/\.(ts|js)$/, ''); |
| 39 | let filePath: string; |
| 40 | let fileName: string; |
| 41 | |
| 42 | if (pluginName.endsWith('.js')) { |
| 43 | filePath = path.join(process.cwd(), 'dist', 'plugins', base + '.js'); |
| 44 | fileName = base + '.js'; |
| 45 | } else { |
| 46 | filePath = path.join(process.cwd(), 'plugins', base + '.ts'); |
| 47 | fileName = base + '.ts'; |
| 48 | if (!fs.existsSync(filePath)) { |
| 49 | filePath = path.join(process.cwd(), 'dist', 'plugins', base + '.js'); |
| 50 | fileName = base + '.js'; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if (!fs.existsSync(filePath)) { |
| 55 | return await sock.sendMessage(chatId, { text: `❌ Plugin "${base}" not found.` }, { quoted: message }); |
| 56 | } |
| 57 | |
| 58 | const code = fs.readFileSync(filePath, 'utf8'); |
| 59 | |
| 60 | const formattedCode = `💻 *SOURCE CODE: ${fileName}*\n\n\`\`\`javascript\n${code}\n\`\`\``; |
| 61 | |
| 62 | if (formattedCode.length > 4000) { |
| 63 | await sock.sendMessage(chatId, { |
| 64 | document: Buffer.from(code), |
| 65 | fileName: fileName, |
| 66 | mimetype: 'text/javascript', |
| 67 | caption: `📄 Code for *${fileName}* (File too large for text message)` |
| 68 | }, { quoted: message }); |
| 69 | } else { |
| 70 | await sock.sendMessage(chatId, { text: formattedCode }, { quoted: message }); |
| 71 | } |
| 72 | |
| 73 | } catch(error: any) { |
| 74 | console.error('Inspect Error:', error); |
| 75 | await sock.sendMessage(chatId, { text: '❌ Failed to read the plugin file.' }); |
| 76 | } |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | /***************************************************************************** |
nothing calls this directly
no outgoing calls
no test coverage detected