From 62ce85f5d395135dfc1235775b4498813ab8cbc7 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Sun, 9 May 2021 21:08:49 +0300 Subject: Fixes Site Ping On Localhost Improves parsing of site URL, so the ping command works locally and in prod. Signed-off-by: Hassan Abouelela --- bot/exts/utils/ping.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bot/exts/utils/ping.py b/bot/exts/utils/ping.py index 572fc934b..6e6603ff4 100644 --- a/bot/exts/utils/ping.py +++ b/bot/exts/utils/ping.py @@ -1,4 +1,5 @@ import socket +import urllib.parse from datetime import datetime import aioping @@ -37,7 +38,8 @@ class Latency(commands.Cog): bot_ping = f"{bot_ping:.{ROUND_LATENCY}f} ms" try: - delay = await aioping.ping(URLs.site, family=socket.AddressFamily.AF_INET) * 1000 + url = urllib.parse.urlparse(URLs.site_schema + URLs.site).hostname + delay = await aioping.ping(url, family=socket.AddressFamily.AF_INET) * 1000 site_ping = f"{delay:.{ROUND_LATENCY}f} ms" except TimeoutError: -- cgit v1.2.3 From a39b8a860b263046e07884b56e3937916abeb1d1 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Sun, 9 May 2021 21:09:37 +0300 Subject: Adds Warning For Desynced Clock In Ping Command Signed-off-by: Hassan Abouelela --- bot/exts/utils/ping.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bot/exts/utils/ping.py b/bot/exts/utils/ping.py index 6e6603ff4..95490d5a9 100644 --- a/bot/exts/utils/ping.py +++ b/bot/exts/utils/ping.py @@ -35,7 +35,10 @@ class Latency(commands.Cog): # datetime.datetime objects do not have the "milliseconds" attribute. # It must be converted to seconds before converting to milliseconds. bot_ping = (datetime.utcnow() - ctx.message.created_at).total_seconds() * 1000 - bot_ping = f"{bot_ping:.{ROUND_LATENCY}f} ms" + if bot_ping <= 0: + bot_ping = "Your clock is out of sync, could not calculate ping." + else: + bot_ping = f"{bot_ping:.{ROUND_LATENCY}f} ms" try: url = urllib.parse.urlparse(URLs.site_schema + URLs.site).hostname -- cgit v1.2.3 From 8e5a38fc9be2bac83ed327cfbfdfcfe099f3b6b4 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Sun, 9 May 2021 22:54:11 +0300 Subject: Adds Warning For Permission Error In Ping Mostly affects linux machines not running as root. Signed-off-by: Hassan Abouelela --- bot/exts/utils/ping.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bot/exts/utils/ping.py b/bot/exts/utils/ping.py index 95490d5a9..750ff46d2 100644 --- a/bot/exts/utils/ping.py +++ b/bot/exts/utils/ping.py @@ -42,8 +42,12 @@ class Latency(commands.Cog): try: url = urllib.parse.urlparse(URLs.site_schema + URLs.site).hostname - delay = await aioping.ping(url, family=socket.AddressFamily.AF_INET) * 1000 - site_ping = f"{delay:.{ROUND_LATENCY}f} ms" + try: + delay = await aioping.ping(url, family=socket.AddressFamily.AF_INET) * 1000 + site_ping = f"{delay:.{ROUND_LATENCY}f} ms" + except OSError: + # Some machines do not have permission to run ping + site_ping = "Permission denied, could not ping." except TimeoutError: site_ping = f"{Emojis.cross_mark} Connection timed out." -- cgit v1.2.3