From 434021ecb913beaa4c45dd818d3e2db1129073bb Mon Sep 17 00:00:00 2001
From: Romain J <romain.ordi@gmail.com>
Date: Sat, 30 Jan 2021 16:43:17 +0100
Subject: [PATCH] feat(commands|Network>ping): feat ping command

---
 README.rst                     |  8 ++++++++
 tuxbot/cogs/Network/network.py | 15 +++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/README.rst b/README.rst
index 92b3015..3e3d359 100644
--- a/README.rst
+++ b/README.rst
@@ -61,6 +61,8 @@ Windows
 
 *not for now and not for the future*
 
+--------------
+
 Configure PostgreSQL
 --------------------
 
@@ -76,6 +78,8 @@ https://wiki.archlinux.org/index.php/PostgreSQL
 
 Continue to `create the venv <#creating-the-virtual-environment>`__.
 
+--------------
+
 Debian
 ^^^^^^
 
@@ -83,6 +87,8 @@ https://wiki.debian.org/PostgreSql
 
 Continue to `create the venv <#creating-the-virtual-environment>`__.
 
+--------------
+
 RHEL and derivatives (CentOS, Fedora...)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
@@ -90,6 +96,8 @@ https://fedoraproject.org/wiki/PostgreSQL
 
 Continue to `create the venv <#creating-the-virtual-environment>`__.
 
+--------------
+
 Creating the Virtual Environment
 --------------------------------
 
diff --git a/tuxbot/cogs/Network/network.py b/tuxbot/cogs/Network/network.py
index fb11d39..388ebfe 100644
--- a/tuxbot/cogs/Network/network.py
+++ b/tuxbot/cogs/Network/network.py
@@ -1,6 +1,7 @@
 import asyncio
 import functools
 import logging
+import time
 from typing import Union
 
 import aiohttp
@@ -214,3 +215,17 @@ class Network(commands.Cog, name="Network"):
             )
 
         await ctx.send(embed=e)
+
+    @command_extra(name="ping", deletable=True)
+    async def _ping(self, ctx: ContextPlus):
+        start = time.perf_counter()
+        await ctx.trigger_typing()
+        end = time.perf_counter()
+
+        latency = round(self.bot.latency * 1000, 2)
+        typing = round((end - start) * 1000, 2)
+
+        e = discord.Embed(title="Ping", color=discord.Color.teal())
+        e.add_field(name="Websocket", value=f"{latency}ms")
+        e.add_field(name="Typing", value=f"{typing}ms")
+        await ctx.send(embed=e)