(sock: any, message: any, args: any, context: BotContext)
| 25 | usage: '.getpage <url>', |
| 26 | |
| 27 | async handler(sock: any, message: any, args: any, context: BotContext) { |
| 28 | const chatId = context.chatId || message.key.remoteJid; |
| 29 | const url = args[0]; |
| 30 | |
| 31 | if (!url || !url.startsWith('http')) { |
| 32 | return await sock.sendMessage(chatId, { text: 'Provide a valid URL (include http/https).' }, { quoted: message }); |
| 33 | } |
| 34 | |
| 35 | try { |
| 36 | await sock.sendMessage(chatId, { text: '🌐 *Fetching source code...*' }); |
| 37 | |
| 38 | const res = await axios.get(url); |
| 39 | const html = res.data; |
| 40 | const buffer = Buffer.from(html, 'utf-8'); |
| 41 | |
| 42 | await sock.sendMessage(chatId, { |
| 43 | document: buffer, |
| 44 | mimetype: 'text/html', |
| 45 | fileName: 'source.html', |
| 46 | caption: `*Source code for:* ${url}` |
| 47 | }, { quoted: message }); |
| 48 | |
| 49 | } catch(err: any) { |
| 50 | await sock.sendMessage(chatId, { text: '❌ Failed to fetch source. The site might be protected.' }); |
| 51 | } |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | /***************************************************************************** |
nothing calls this directly
no outgoing calls
no test coverage detected