Fix homeserver ping
This commit is contained in:
parent
775be84d26
commit
83e6f7108e
1 changed files with 6 additions and 4 deletions
|
@ -11,23 +11,25 @@ class LatencyModule(niobot.Module):
|
||||||
"""See the bot's latency."""
|
"""See the bot's latency."""
|
||||||
latency = ctx.latency
|
latency = ctx.latency
|
||||||
|
|
||||||
homeserver = homeserver or await niobot.resolve_homeserver(ctx.message.sender.split(":")[1])
|
homeserver = homeserver or ctx.message.sender.split(":")[1]
|
||||||
if not homeserver.startswith("http"):
|
if not homeserver.startswith("http"):
|
||||||
homeserver = f"https://{homeserver}"
|
homeserver = f"https://{homeserver}"
|
||||||
|
|
||||||
parsed = urllib.parse.urlparse(homeserver)
|
parsed = urllib.parse.urlparse(homeserver)
|
||||||
loc = "https://" + parsed.netloc
|
loc = "https://" + parsed.netloc
|
||||||
|
homeserver = await niobot.resolve_homeserver(parsed.netloc)
|
||||||
async with httpx.AsyncClient(headers={"User-Agent": niobot.__user_agent__}) as client:
|
async with httpx.AsyncClient(headers={"User-Agent": niobot.__user_agent__}) as client:
|
||||||
timings = []
|
timings = []
|
||||||
for rnd in range(5):
|
for rnd in range(5):
|
||||||
start = time.time()
|
start = time.time()
|
||||||
try:
|
try:
|
||||||
res = await client.get(f"{loc}/_matrix/client/v1/ping")
|
res = await client.get(f"{homeserver}/_matrix/client/v1/ping")
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
except httpx.HTTPError:
|
except httpx.HTTPError:
|
||||||
timings.append(-1)
|
timings.append(-1)
|
||||||
end = time.time()
|
else:
|
||||||
timings.append(end - start)
|
end = time.time()
|
||||||
|
timings.append(end - start)
|
||||||
fed_latency = sum(timings) / len(timings) * 1000
|
fed_latency = sum(timings) / len(timings) * 1000
|
||||||
|
|
||||||
hs_target = parsed.hostname
|
hs_target = parsed.hostname
|
||||||
|
|
Loading…
Reference in a new issue