(msg: Api.Message)
| 74 | try { |
| 75 | const reply = await safeGetReplyMessage(msg); |
| 76 | if (reply && reply.text) { |
| 77 | const text = reply.text.trim(); |
| 78 | const ipRegex = /\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/; |
| 79 | const domainRegex = |
| 80 | /\b(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}\b/; |
| 81 | |
| 82 | const ipMatch = text.match(ipRegex); |
| 83 | const domainMatch = text.match(domainRegex); |
| 84 | |
| 85 | if (ipMatch) { |
| 86 | query = ipMatch[0]; |
| 87 | } else if (domainMatch) { |
| 88 | query = domainMatch[0]; |
| 89 | } else { |
| 90 | query = text.split(" ")[0]; |
| 91 | } |
| 92 | } |
| 93 | } catch (replyError: any) { |
| 94 | console.error("Failed to get reply message:", replyError); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | if (!query || query.trim() === "") { |
| 99 | await msg.edit({ |
| 100 | text: `📍 <b>IP查询插件</b> |
| 101 | |
| 102 | <b>使用方法:</b> |
| 103 | • <code>ip <IP地址></code> |
| 104 | • <code>ip <域名></code> |
| 105 | • 回复包含IP/域名的消息后使用 <code>ip</code> |
| 106 | |
| 107 | <b>示例:</b> |
| 108 | • <code>ip 8.8.8.8</code> |
| 109 | • <code>ip google.com</code> |
| 110 | • <code>ip 2001:4860:4860::8888</code>`, |
| 111 | parseMode: "html", |
| 112 | }); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | await msg.edit({ |
| 117 | text: `🔍 <b>正在查询:</b> <code>${htmlEscape(query)}</code>`, |
| 118 | parseMode: "html", |
| 119 | }); |
| 120 | |
| 121 | const data = await getIpInfo(query); |
| 122 | |
| 123 | if (data.status === "fail") { |
| 124 | const errorMessage = data.message || "未知错误"; |
| 125 | await msg.edit({ |
| 126 | text: `❌ <b>查询失败</b> |
| 127 | |
| 128 | <b>查询目标:</b> <code>${htmlEscape(query)}</code> |
| 129 | <b>失败原因:</b> ${htmlEscape(errorMessage)} |
| 130 | |
| 131 | 💡 <b>建议:</b> |
| 132 | • 检查IP地址或域名格式 |
| 133 | • 稍后重试查询`, |
nothing calls this directly
no test coverage detected