Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/whois/__init__.py

31 lines
791 B
Python
Raw Normal View History

2023-01-19 03:29:50 +00:00
import ipaddress
2023-01-28 05:53:11 +00:00
2023-02-05 14:33:33 +00:00
from core.builtins import Bot
2023-03-04 08:51:56 +00:00
from core.component import module
2023-01-19 03:29:50 +00:00
from .ip import check_ip, format_ip
2023-01-28 05:53:11 +00:00
2023-01-19 06:39:06 +00:00
# from .domain import check_domain, format_domain
2023-01-19 03:29:50 +00:00
2023-03-15 13:47:28 +00:00
w = module('whois', desc='{whois.help}',
2023-01-19 06:39:06 +00:00
developers=['Dianliang233'])
2023-01-19 03:29:50 +00:00
@w.handle('<ip_or_domain>')
2023-02-05 14:33:33 +00:00
async def _(msg: Bot.MessageSession):
2023-01-19 03:29:50 +00:00
query = msg.parsed_msg['<ip_or_domain>']
query_type = ip_or_domain(query)
if query_type == 'ip':
res = await check_ip(query)
await msg.finish(await format_ip(res))
2023-01-19 06:39:06 +00:00
# elif query_type == 'domain':
# res = await check_domain(query)
# await msg.finish(await format_domain(res))
2023-01-19 03:29:50 +00:00
def ip_or_domain(string: str):
try:
ipaddress.ip_address(string)
return 'ip'
except ValueError:
return 'domain'