prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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.
  
  </issue>
  <code>
  [start of bot/exts/utils/ping.py]
  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 of bot/exts/utils/ping.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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."
  
verification_info: {"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"}]}