PagerMaid_Plugins/whois.py

35 lines
1.5 KiB
Python
Raw Normal View History

2020-08-12 06:57:28 +00:00
import json
2021-08-16 14:32:42 +00:00
from json import JSONDecodeError
2020-08-12 06:57:28 +00:00
from requests import get
2022-01-18 08:47:20 +00:00
from pagermaid import version
2020-08-12 06:57:28 +00:00
from pagermaid.listener import listener
2021-06-16 07:09:40 +00:00
from pagermaid.utils import obtain_message, alias_command
2020-08-12 06:57:28 +00:00
2021-06-16 07:09:40 +00:00
@listener(outgoing=True, command=alias_command("whois"),
2020-08-12 06:57:28 +00:00
description="查看域名是否已被注册、注册日期、过期日期、域名状态、DNS解析服务器等。")
async def whois(context):
await context.edit("获取中 . . .")
try:
message = await obtain_message(context)
except ValueError:
await context.edit("出错了呜呜呜 ~ 无效的参数。")
return
req = get("https://tenapi.cn/whois/?url=" + message)
if req.status_code == 200:
2021-07-02 12:04:08 +00:00
try:
data = json.loads(req.text)['data']
except KeyError:
await context.edit("出错了呜呜呜 ~ 可能是域名不正确。")
return
2021-08-16 14:32:42 +00:00
except JSONDecodeError:
await context.edit("出错了呜呜呜 ~ 可能是域名不正确。")
return
2021-06-16 07:09:40 +00:00
res = '域名: `' + data['url'] + '`\n注册商: `' + str(data['registrar']) + '`\n联系人: `' + str(
data['registrant']) + '`\n联系邮箱: `' + str(data['mail']) + '`\n注册时间: `' + str(
data['registration']) + '`\n过期时间: `' + str(data['expiration']) + '`\nDNS ' + str(data['dns']).replace(
'<br/>', '\n')
2020-08-12 06:57:28 +00:00
await context.edit(res)
else:
await context.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")