(sock: any, message: any, args: any, context: BotContext)
| 9 | usage: '.pingweb [website URL]', |
| 10 | |
| 11 | async handler(sock: any, message: any, args: any, context: BotContext) { |
| 12 | const { chatId, channelInfo, rawText } = context; |
| 13 | |
| 14 | const prefix = rawText.match(/^[.!#]/)?.[0] || '.'; |
| 15 | const commandPart = rawText.slice(prefix.length).trim(); |
| 16 | const parts = commandPart.split(/\s+/); |
| 17 | const url = parts.slice(1).join(' ').trim(); |
| 18 | |
| 19 | const startBot = Date.now(); |
| 20 | const sent = await sock.sendMessage(chatId, { |
| 21 | text: '🏓 Pinging...', |
| 22 | ...channelInfo |
| 23 | }, { quoted: message }); |
| 24 | const endBot = Date.now(); |
| 25 | const botLatency = endBot - startBot; |
| 26 | |
| 27 | let responseText = `🏓 *Pong!*\n\n📶 *Bot Latency:* ${botLatency}ms`; |
| 28 | |
| 29 | if (url) { |
| 30 | try { |
| 31 | let testUrl = url; |
| 32 | if (!testUrl.startsWith('http://') && !testUrl.startsWith('https://')) { |
| 33 | testUrl = 'https://' + testUrl; |
| 34 | } |
| 35 | |
| 36 | const urlObj = new URL(testUrl); |
| 37 | |
| 38 | const startWeb = Date.now(); |
| 39 | const response = await axios.get(testUrl, { |
| 40 | timeout: 10000, |
| 41 | validateStatus: () => true, |
| 42 | headers: { |
| 43 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' |
| 44 | } |
| 45 | }); |
| 46 | const endWeb = Date.now(); |
| 47 | const webLatency = endWeb - startWeb; |
| 48 | |
| 49 | responseText += `\n\n🌐 *Website:* ${urlObj.hostname}`; |
| 50 | responseText += `\n⚡ *Response Time:* ${webLatency}ms`; |
| 51 | responseText += `\n📡 *Status:* ${response.status} ${response.statusText}`; |
| 52 | responseText += `\n✅ *Reachable:* Yes`; |
| 53 | |
| 54 | } catch(error: any) { |
| 55 | if (error.code === 'ENOTFOUND') { |
| 56 | responseText += `\n\n🌐 *Website:* ${url}`; |
| 57 | responseText += `\n❌ *Error:* Domain not found`; |
| 58 | } else if (error.code === 'ETIMEDOUT' || error.code === 'ECONNABORTED') { |
| 59 | responseText += `\n\n🌐 *Website:* ${url}`; |
| 60 | responseText += `\n❌ *Error:* Connection timeout`; |
| 61 | } else if (error.message.includes('Invalid URL')) { |
| 62 | responseText += `\n\n❌ *Invalid URL format*`; |
| 63 | responseText += `\n💡 Example: .ping google.com`; |
| 64 | } else { |
| 65 | responseText += `\n\n🌐 *Website:* ${url}`; |
| 66 | responseText += `\n❌ *Error:* ${error.message}`; |
| 67 | } |
| 68 | } |
nothing calls this directly
no outgoing calls
no test coverage detected