import datetime
from time import monotonic

from dog import Cog

from discord.ext import commands


class Health(Cog):
    @commands.command()
    async def ping(self, ctx):
        """ Pong! """

        # measure gateway delay
        before = monotonic()
        msg = await ctx.send('\u200b')
        after = monotonic()

        pong_ws = round(ctx.bot.latency * 1000, 2)
        pong_rest = round((after - before) * 1000, 2)
        pong_gateway_lag = round((msg.created_at - datetime.datetime.utcnow()).total_seconds() * 1000, 2)

        pong = f'Pong! WS: {pong_ws}ms, REST: {pong_rest}ms, GW lag: {pong_gateway_lag}ms'
        await msg.edit(content=pong)


def setup(bot):
    bot.add_cog(Health(bot))

import datetime
from time import monotonic

from dog import Cog

from discord.ext import commands


class Health(Cog):
    @commands.command()
    async def ping(self, ctx):
        """ Pong! """

        # measure gateway delay
        before = monotonic()
        msg = await ctx.send('\u200b')
        after = monotonic()

        pong_ws = round(ctx.bot.latency * 1000, 2)
        pong_rest = round((after - before) * 1000, 2)
        pong_gateway_lag = round((datetime.datetime.utcnow() - msg.created_at).total_seconds() * 1000, 2)

        pong = f'Pong! WS: {pong_ws}ms, REST: {pong_rest}ms, GW lag: {pong_gateway_lag}ms'
        await msg.edit(content=pong)


def setup(bot):
    bot.add_cog(Health(bot))

Fix gateway lag being negative in d?ping
Fix gateway lag being negative in d?ping

  import datetime
  from time import monotonic
  
  from dog import Cog
  
  from discord.ext import commands
  
  
  class Health(Cog):
      @commands.command()
      async def ping(self, ctx):
          """ Pong! """
  
          # measure gateway delay
          before = monotonic()
          msg = await ctx.send('\u200b')
          after = monotonic()
  
          pong_ws = round(ctx.bot.latency * 1000, 2)
          pong_rest = round((after - before) * 1000, 2)
-         pong_gateway_lag = round((msg.created_at - datetime.datetime.utcnow()).total_seconds() * 1000, 2)
+         pong_gateway_lag = round((datetime.datetime.utcnow() - msg.created_at).total_seconds() * 1000, 2)
  
          pong = f'Pong! WS: {pong_ws}ms, REST: {pong_rest}ms, GW lag: {pong_gateway_lag}ms'
          await msg.edit(content=pong)
  
  
  def setup(bot):
      bot.add_cog(Health(bot))
  
Fix gateway lag being negative in d?ping
## Code Before:
import datetime
from time import monotonic

from dog import Cog

from discord.ext import commands


class Health(Cog):
    @commands.command()
    async def ping(self, ctx):
        """ Pong! """

        # measure gateway delay
        before = monotonic()
        msg = await ctx.send('\u200b')
        after = monotonic()

        pong_ws = round(ctx.bot.latency * 1000, 2)
        pong_rest = round((after - before) * 1000, 2)
        pong_gateway_lag = round((msg.created_at - datetime.datetime.utcnow()).total_seconds() * 1000, 2)

        pong = f'Pong! WS: {pong_ws}ms, REST: {pong_rest}ms, GW lag: {pong_gateway_lag}ms'
        await msg.edit(content=pong)


def setup(bot):
    bot.add_cog(Health(bot))

## Instruction:
Fix gateway lag being negative in d?ping
## Code After:
import datetime
from time import monotonic

from dog import Cog

from discord.ext import commands


class Health(Cog):
    @commands.command()
    async def ping(self, ctx):
        """ Pong! """

        # measure gateway delay
        before = monotonic()
        msg = await ctx.send('\u200b')
        after = monotonic()

        pong_ws = round(ctx.bot.latency * 1000, 2)
        pong_rest = round((after - before) * 1000, 2)
        pong_gateway_lag = round((datetime.datetime.utcnow() - msg.created_at).total_seconds() * 1000, 2)

        pong = f'Pong! WS: {pong_ws}ms, REST: {pong_rest}ms, GW lag: {pong_gateway_lag}ms'
        await msg.edit(content=pong)


def setup(bot):
    bot.add_cog(Health(bot))
