mirror of
https://github.com/Xtao-Labs/misskey2telegram.git
synced 2024-11-22 22:05:58 +00:00
32 lines
862 B
Python
32 lines
862 B
Python
from httpx import URL, InvalidURL, AsyncClient
|
|
|
|
from init import headers
|
|
|
|
|
|
def get_host(url: str) -> str:
|
|
try:
|
|
url = URL(url)
|
|
except InvalidURL:
|
|
return ""
|
|
return url.host
|
|
|
|
|
|
async def check_host(host: str) -> bool:
|
|
if not host:
|
|
return False
|
|
try:
|
|
async with AsyncClient(timeout=60, headers=headers) as request:
|
|
req = await request.get(f"https://{host}/.well-known/nodeinfo")
|
|
req.raise_for_status()
|
|
node_url = req.json()["links"][0]["href"]
|
|
req = await request.get(node_url)
|
|
req.raise_for_status()
|
|
data = req.json()
|
|
if data["software"]["name"] != "misskey":
|
|
raise ValueError
|
|
if not data["software"]["version"].startswith("13."):
|
|
raise ValueError
|
|
return True
|
|
except Exception:
|
|
return False
|