refactor(command|utility): rewrite getheaders

This commit is contained in:
Romain J 2019-09-28 00:57:39 +02:00
parent 2d175b4453
commit 60f68f245d
7 changed files with 51 additions and 3 deletions

View file

@ -76,6 +76,6 @@
- [ ] clock *
- [ ] ytdiscover
- [x] iplocalise
- [ ] getheaders
- [x] getheaders
- [ ] git
- [ ] quote

View file

@ -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))

View file

@ -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'),

View file

@ -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))

View file

@ -29,3 +29,9 @@ msgstr ""
msgid "info not available"
msgstr ""
msgid "Headers of"
msgstr ""
msgid "Cannot connect to host"
msgstr ""

View file

@ -29,3 +29,9 @@ msgstr "Se situe à :"
msgid "info not available"
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"