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