From 60f68f245dbcb1cc305d3d44bf7466e75db61124 Mon Sep 17 00:00:00 2001
From: Romain J <romain.ordi@gmail.com>
Date: Sat, 28 Sep 2019 00:57:39 +0200
Subject: [PATCH] refactor(command|utility): rewrite getheaders

---
 README.md                                |   2 +-
 cogs/admin.py                            |   7 ++++++
 cogs/basics.py                           |   2 +-
 cogs/utility.py                          |  29 +++++++++++++++++++++++
 extras/locales/en/LC_MESSAGES/utility.po |   6 +++++
 extras/locales/fr/LC_MESSAGES/utility.mo | Bin 693 -> 809 bytes
 extras/locales/fr/LC_MESSAGES/utility.po |   8 ++++++-
 7 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 07717db..2010f04 100644
--- a/README.md
+++ b/README.md
@@ -76,6 +76,6 @@
  - [ ] clock *
  - [ ] ytdiscover
  - [x] iplocalise
- - [ ] getheaders
+ - [x] getheaders
  - [ ] git
  - [ ] quote
\ No newline at end of file
diff --git a/cogs/admin.py b/cogs/admin.py
index 4bbb35b..cc7c42f 100644
--- a/cogs/admin.py
+++ b/cogs/admin.py
@@ -407,6 +407,13 @@ class Admin(commands.Cog):
         await ctx.send(f"{Texts('admin').get('Warn with id')} `{warn_id}`"
                        f" {Texts('admin').get('successfully edited')}")
 
+    """---------------------------------------------------------------------"""
+
+    @commands.command(name='set-language', aliases=['set-lang'])
+    async def _set_language(self, ctx: commands.Context, lang):
+        """
+        todo: set lang for guild
+        """
 
 def setup(bot: TuxBot):
     bot.add_cog(Admin(bot))
diff --git a/cogs/basics.py b/cogs/basics.py
index 3f43f06..ff41266 100644
--- a/cogs/basics.py
+++ b/cogs/basics.py
@@ -139,7 +139,7 @@ class Basics(commands.Cog):
 
     """---------------------------------------------------------------------"""
 
-    @commands.command(name='credits', aliases=['contributors'])
+    @commands.command(name='credits', aliases=['contributors', 'authors'])
     async def _credits(self, ctx: commands.Context):
         e = discord.Embed(
             title=Texts('basics').get('Contributors'),
diff --git a/cogs/utility.py b/cogs/utility.py
index ecf6cb0..381894d 100644
--- a/cogs/utility.py
+++ b/cogs/utility.py
@@ -1,5 +1,6 @@
 import re
 
+import aiohttp
 import discord
 from discord.ext import commands
 from bot import TuxBot
@@ -70,6 +71,34 @@ class Utility(commands.Cog):
                     content=f"{Texts('utility').get('info not available')}"
                             f"``{response.get('query')}``")
 
+    """---------------------------------------------------------------------"""
+
+    @commands.command(name='getheaders')
+    async def _getheaders(self, ctx: commands.Context, addr: str):
+        if (addr.startswith('http') or addr.startswith('ftp')) is not True:
+            addr = f"http://{addr}"
+
+        try:
+            async with self.bot.session.get(addr) as s:
+                await ctx.trigger_typing()
+                e = discord.Embed(
+                    title=f"{Texts('utility').get('Headers of')} {addr}",
+                    color=0xd75858
+                )
+                e.add_field(name="Status", value=s.status, inline=True)
+                e.set_thumbnail(url=f"https://http.cat/{s.status}")
+
+                headers = dict(s.headers.items())
+                headers.pop('Set-Cookie', headers)
+
+                for key, value in headers.items():
+                    e.add_field(name=key, value=value, inline=True)
+                await ctx.send(embed=e)
+
+        except aiohttp.client_exceptions.ClientConnectorError:
+            await ctx.send(f"{Texts('utility').get('Cannot connect to host')} "
+                           f"{addr}")
+
 
 def setup(bot: TuxBot):
     bot.add_cog(Utility(bot))
diff --git a/extras/locales/en/LC_MESSAGES/utility.po b/extras/locales/en/LC_MESSAGES/utility.po
index d72dedf..fb63db9 100644
--- a/extras/locales/en/LC_MESSAGES/utility.po
+++ b/extras/locales/en/LC_MESSAGES/utility.po
@@ -28,4 +28,10 @@ msgid "Is located at :"
 msgstr ""
 
 msgid "info not available"
+msgstr ""
+
+msgid "Headers of"
+msgstr ""
+
+msgid "Cannot connect to host"
 msgstr ""
\ No newline at end of file
diff --git a/extras/locales/fr/LC_MESSAGES/utility.mo b/extras/locales/fr/LC_MESSAGES/utility.mo
index f5d6167b7ccbf3c6ed1295dc17a0ceed6b997922..b39c8511cb0a5529b4b193e0e445bdc6fe81c82a 100644
GIT binary patch
delta 266
zcmYkyJqy866vy#HNFEY{iMord%BC!&3<fX2;OTg%zkB80-KMNW2FhSzBVK_1tCt|J
zz-s3AFUqZNpL0*=;@$hkkC<mccz%>XHRtp9)|f+RgW~9b0_ch&==SvvW9a$y4f8JS
zkaJgc6Qy7s2H^xoi7GV15XNE$3-AQ9@CB*BmXcj9j1oC2Hl$QWw3L+GGS052w4pLL
u+C0)ib&k`eD>E1>t@}-jMVp1@-#L$jy%kovXP*sINgDfLSmS1%bgw>|Ha6b?

delta 151
zcmZ3<ww1O1o)F7a1|VPqVi_Rz0dbH(4Uo+P#I-=o55!$idKQot0^(IrdM}W+Wn^Hu
z0Hi_c_?Q?N1c9_1kmd!_20+>gNZSEvV<6oKq#2x2xpMOJ(u);J@)fK$o}R`yc{0;9
E0Bw2_i2wiq

diff --git a/extras/locales/fr/LC_MESSAGES/utility.po b/extras/locales/fr/LC_MESSAGES/utility.po
index 3e740fb..84c8811 100644
--- a/extras/locales/fr/LC_MESSAGES/utility.po
+++ b/extras/locales/fr/LC_MESSAGES/utility.po
@@ -28,4 +28,10 @@ msgid "Is located at :"
 msgstr "Se situe à :"
 
 msgid "info not available"
-msgstr "Erreur, impossible d'obtenir des informations sur cette adresse IP"
\ No newline at end of file
+msgstr "Erreur, impossible d'obtenir des informations sur cette adresse IP"
+
+msgid "Headers of"
+msgstr "Entêtes de"
+
+msgid "Cannot connect to host"
+msgstr "Impossible de se connecter à l'hôte"