We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Ping Command Bugs
There are a couple bugs in the ping command, that only manifest in local development.

## Bug 1: `gaierror: [Errno 11001] getaddrinfo failed`
This bug is pretty easy to explain. On many development bots, the site URL will have some sort of port (for example `pythondiscord.local:8000` or `web:8000`).  aioping.ping does not seem to handle that, and will throw a getadderinfo error. ([Full TB if needed](https://paste.pythondiscord.com/pahuherice.sql)). This issue does not affect the Python bot, as the URL does not contain a port.

The fix for this should be simple enough, you just need to extract netloc from the URL, and pass it to the ping function. One possible way to do that could be through using the builtin [urllib.parse.urlparse](https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlparse).

## Bug 2: Negative Processing Time
Last I checked, my bot had not yet developed time-traveling abilities, which makes this output a bit strange:

![Time Magic](https://user-images.githubusercontent.com/47495861/107149169-36182780-6968-11eb-94a1-5465728c4dfa.png)

The line that calculates that time is:
https://github.com/python-discord/bot/blob/888c427466b370b9ae51e47496e979c2b6faed0c/bot/exts/utils/ping.py#L36

I'm not too sure why this happens, but it happens consistently. My guess would be a difference between the internal timing for discord, and the internal timing of my system. This is also not a problem on the production server.

I propose that all negative times be replaced with a warning, or a 0, or something to signify a nonsensical result. If someone has a better explanation or a better fix, feel free to comment.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `bot/exts/utils/ping.py`
Content:
```
1 import socket
2 from datetime import datetime
3 
4 import aioping
5 from discord import Embed
6 from discord.ext import commands
7 
8 from bot.bot import Bot
9 from bot.constants import Channels, Emojis, STAFF_ROLES, URLs
10 from bot.decorators import in_whitelist
11 
12 DESCRIPTIONS = (
13     "Command processing time",
14     "Python Discord website latency",
15     "Discord API latency"
16 )
17 ROUND_LATENCY = 3
18 
19 
20 class Latency(commands.Cog):
21     """Getting the latency between the bot and websites."""
22 
23     def __init__(self, bot: Bot) -> None:
24         self.bot = bot
25 
26     @commands.command()
27     @in_whitelist(channels=(Channels.bot_commands,), roles=STAFF_ROLES)
28     async def ping(self, ctx: commands.Context) -> None:
29         """
30         Gets different measures of latency within the bot.
31 
32         Returns bot, Python Discord Site, Discord Protocol latency.
33         """
34         # datetime.datetime objects do not have the "milliseconds" attribute.
35         # It must be converted to seconds before converting to milliseconds.
36         bot_ping = (datetime.utcnow() - ctx.message.created_at).total_seconds() * 1000
37         bot_ping = f"{bot_ping:.{ROUND_LATENCY}f} ms"
38 
39         try:
40             delay = await aioping.ping(URLs.site, family=socket.AddressFamily.AF_INET) * 1000
41             site_ping = f"{delay:.{ROUND_LATENCY}f} ms"
42 
43         except TimeoutError:
44             site_ping = f"{Emojis.cross_mark} Connection timed out."
45 
46         # Discord Protocol latency return value is in seconds, must be multiplied by 1000 to get milliseconds.
47         discord_ping = f"{self.bot.latency * 1000:.{ROUND_LATENCY}f} ms"
48 
49         embed = Embed(title="Pong!")
50 
51         for desc, latency in zip(DESCRIPTIONS, [bot_ping, site_ping, discord_ping]):
52             embed.add_field(name=desc, value=latency, inline=False)
53 
54         await ctx.send(embed=embed)
55 
56 
57 def setup(bot: Bot) -> None:
58     """Load the Latency cog."""
59     bot.add_cog(Latency(bot))
60
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/bot/exts/utils/ping.py b/bot/exts/utils/ping.py
--- 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
@@ -34,11 +35,19 @@
         # 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:
-            delay = await aioping.ping(URLs.site, family=socket.AddressFamily.AF_INET) * 1000
-            site_ping = f"{delay:.{ROUND_LATENCY}f} ms"
+            url = urllib.parse.urlparse(URLs.site_schema + URLs.site).hostname
+            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."

{"golden_diff": "diff --git a/bot/exts/utils/ping.py b/bot/exts/utils/ping.py\n--- a/bot/exts/utils/ping.py\n+++ b/bot/exts/utils/ping.py\n@@ -1,4 +1,5 @@\n import socket\n+import urllib.parse\n from datetime import datetime\n \n import aioping\n@@ -34,11 +35,19 @@\n         # datetime.datetime objects do not have the \"milliseconds\" attribute.\n         # It must be converted to seconds before converting to milliseconds.\n         bot_ping = (datetime.utcnow() - ctx.message.created_at).total_seconds() * 1000\n-        bot_ping = f\"{bot_ping:.{ROUND_LATENCY}f} ms\"\n+        if bot_ping <= 0:\n+            bot_ping = \"Your clock is out of sync, could not calculate ping.\"\n+        else:\n+            bot_ping = f\"{bot_ping:.{ROUND_LATENCY}f} ms\"\n \n         try:\n-            delay = await aioping.ping(URLs.site, family=socket.AddressFamily.AF_INET) * 1000\n-            site_ping = f\"{delay:.{ROUND_LATENCY}f} ms\"\n+            url = urllib.parse.urlparse(URLs.site_schema + URLs.site).hostname\n+            try:\n+                delay = await aioping.ping(url, family=socket.AddressFamily.AF_INET) * 1000\n+                site_ping = f\"{delay:.{ROUND_LATENCY}f} ms\"\n+            except OSError:\n+                # Some machines do not have permission to run ping\n+                site_ping = \"Permission denied, could not ping.\"\n \n         except TimeoutError:\n             site_ping = f\"{Emojis.cross_mark} Connection timed out.\"\n", "issue": "Ping Command Bugs\nThere are a couple bugs in the ping command, that only manifest in local development.\r\n\r\n## Bug 1: `gaierror: [Errno 11001] getaddrinfo failed`\r\nThis bug is pretty easy to explain. On many development bots, the site URL will have some sort of port (for example `pythondiscord.local:8000` or `web:8000`).  aioping.ping does not seem to handle that, and will throw a getadderinfo error. ([Full TB if needed](https://paste.pythondiscord.com/pahuherice.sql)). This issue does not affect the Python bot, as the URL does not contain a port.\r\n\r\nThe fix for this should be simple enough, you just need to extract netloc from the URL, and pass it to the ping function. One possible way to do that could be through using the builtin [urllib.parse.urlparse](https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlparse).\r\n\r\n## Bug 2: Negative Processing Time\r\nLast I checked, my bot had not yet developed time-traveling abilities, which makes this output a bit strange:\r\n\r\n![Time Magic](https://user-images.githubusercontent.com/47495861/107149169-36182780-6968-11eb-94a1-5465728c4dfa.png)\r\n\r\nThe line that calculates that time is:\r\nhttps://github.com/python-discord/bot/blob/888c427466b370b9ae51e47496e979c2b6faed0c/bot/exts/utils/ping.py#L36\r\n\r\nI'm not too sure why this happens, but it happens consistently. My guess would be a difference between the internal timing for discord, and the internal timing of my system. This is also not a problem on the production server.\r\n\r\nI propose that all negative times be replaced with a warning, or a 0, or something to signify a nonsensical result. If someone has a better explanation or a better fix, feel free to comment.\n", "before_files": [{"content": "import socket\nfrom datetime import datetime\n\nimport aioping\nfrom discord import Embed\nfrom discord.ext import commands\n\nfrom bot.bot import Bot\nfrom bot.constants import Channels, Emojis, STAFF_ROLES, URLs\nfrom bot.decorators import in_whitelist\n\nDESCRIPTIONS = (\n    \"Command processing time\",\n    \"Python Discord website latency\",\n    \"Discord API latency\"\n)\nROUND_LATENCY = 3\n\n\nclass Latency(commands.Cog):\n    \"\"\"Getting the latency between the bot and websites.\"\"\"\n\n    def __init__(self, bot: Bot) -> None:\n        self.bot = bot\n\n    @commands.command()\n    @in_whitelist(channels=(Channels.bot_commands,), roles=STAFF_ROLES)\n    async def ping(self, ctx: commands.Context) -> None:\n        \"\"\"\n        Gets different measures of latency within the bot.\n\n        Returns bot, Python Discord Site, Discord Protocol latency.\n        \"\"\"\n        # datetime.datetime objects do not have the \"milliseconds\" attribute.\n        # It must be converted to seconds before converting to milliseconds.\n        bot_ping = (datetime.utcnow() - ctx.message.created_at).total_seconds() * 1000\n        bot_ping = f\"{bot_ping:.{ROUND_LATENCY}f} ms\"\n\n        try:\n            delay = await aioping.ping(URLs.site, family=socket.AddressFamily.AF_INET) * 1000\n            site_ping = f\"{delay:.{ROUND_LATENCY}f} ms\"\n\n        except TimeoutError:\n            site_ping = f\"{Emojis.cross_mark} Connection timed out.\"\n\n        # Discord Protocol latency return value is in seconds, must be multiplied by 1000 to get milliseconds.\n        discord_ping = f\"{self.bot.latency * 1000:.{ROUND_LATENCY}f} ms\"\n\n        embed = Embed(title=\"Pong!\")\n\n        for desc, latency in zip(DESCRIPTIONS, [bot_ping, site_ping, discord_ping]):\n            embed.add_field(name=desc, value=latency, inline=False)\n\n        await ctx.send(embed=embed)\n\n\ndef setup(bot: Bot) -> None:\n    \"\"\"Load the Latency cog.\"\"\"\n    bot.add_cog(Latency(bot))\n", "path": "bot/exts/utils/ping.py"}], "after_files": [{"content": "import socket\nimport urllib.parse\nfrom datetime import datetime\n\nimport aioping\nfrom discord import Embed\nfrom discord.ext import commands\n\nfrom bot.bot import Bot\nfrom bot.constants import Channels, Emojis, STAFF_ROLES, URLs\nfrom bot.decorators import in_whitelist\n\nDESCRIPTIONS = (\n    \"Command processing time\",\n    \"Python Discord website latency\",\n    \"Discord API latency\"\n)\nROUND_LATENCY = 3\n\n\nclass Latency(commands.Cog):\n    \"\"\"Getting the latency between the bot and websites.\"\"\"\n\n    def __init__(self, bot: Bot) -> None:\n        self.bot = bot\n\n    @commands.command()\n    @in_whitelist(channels=(Channels.bot_commands,), roles=STAFF_ROLES)\n    async def ping(self, ctx: commands.Context) -> None:\n        \"\"\"\n        Gets different measures of latency within the bot.\n\n        Returns bot, Python Discord Site, Discord Protocol latency.\n        \"\"\"\n        # datetime.datetime objects do not have the \"milliseconds\" attribute.\n        # It must be converted to seconds before converting to milliseconds.\n        bot_ping = (datetime.utcnow() - ctx.message.created_at).total_seconds() * 1000\n        if bot_ping <= 0:\n            bot_ping = \"Your clock is out of sync, could not calculate ping.\"\n        else:\n            bot_ping = f\"{bot_ping:.{ROUND_LATENCY}f} ms\"\n\n        try:\n            url = urllib.parse.urlparse(URLs.site_schema + URLs.site).hostname\n            try:\n                delay = await aioping.ping(url, family=socket.AddressFamily.AF_INET) * 1000\n                site_ping = f\"{delay:.{ROUND_LATENCY}f} ms\"\n            except OSError:\n                # Some machines do not have permission to run ping\n                site_ping = \"Permission denied, could not ping.\"\n\n        except TimeoutError:\n            site_ping = f\"{Emojis.cross_mark} Connection timed out.\"\n\n        # Discord Protocol latency return value is in seconds, must be multiplied by 1000 to get milliseconds.\n        discord_ping = f\"{self.bot.latency * 1000:.{ROUND_LATENCY}f} ms\"\n\n        embed = Embed(title=\"Pong!\")\n\n        for desc, latency in zip(DESCRIPTIONS, [bot_ping, site_ping, discord_ping]):\n            embed.add_field(name=desc, value=latency, inline=False)\n\n        await ctx.send(embed=embed)\n\n\ndef setup(bot: Bot) -> None:\n    \"\"\"Load the Latency cog.\"\"\"\n    bot.add_cog(Latency(bot))\n", "path": "bot/exts/utils/ping.py"}]}