mirror of
https://github.com/Xtao-Labs/misskey2telegram.git
synced 2024-11-26 23:22:39 +00:00
31 lines
761 B
Python
31 lines
761 B
Python
from httpx import URL, InvalidURL
|
|
|
|
from init import request
|
|
|
|
|
|
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:
|
|
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
|