From fcc23d87df6e6d0922d1ed5070b67016fe71c170 Mon Sep 17 00:00:00 2001 From: Romain J Date: Sun, 25 Apr 2021 18:48:21 +0200 Subject: [PATCH] update(commands:down?|Network): change api to improve results --- tuxbot/cogs/Network/network.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tuxbot/cogs/Network/network.py b/tuxbot/cogs/Network/network.py index 1d7bd17..c1a87eb 100644 --- a/tuxbot/cogs/Network/network.py +++ b/tuxbot/cogs/Network/network.py @@ -93,7 +93,9 @@ class Network(commands.Cog): @tasks.loop(hours=1.0) async def _update_peering_db(self): try: - async with aiohttp.ClientSession(connector=TCPConnector(verify_ssl=False)) as cs: + async with aiohttp.ClientSession( + connector=TCPConnector(verify_ssl=False) + ) as cs: async with cs.get( "https://3.233.208.117/api/net", timeout=aiohttp.ClientTimeout(total=60), @@ -306,26 +308,25 @@ class Network(commands.Cog): @command_extra(name="isdown", aliases=["is_down", "down?"], deletable=True) async def _isdown(self, ctx: ContextPlus, domain: IPConverter): try: + url = f"https://www.isthissitedown.org/site/{domain}" + async with aiohttp.ClientSession() as cs: async with cs.get( - f"https://isitdown.site/api/v3/{domain}", + url, timeout=aiohttp.ClientTimeout(total=8), ) as s: - json = await s.json() + text = await s.text() - if json["isitdown"]: - title = _("Down...", ctx, self.bot.config) - color = 0xDC3545 - else: + if "is up!" in text: title = _("Up!", ctx, self.bot.config) color = 0x28A745 + else: + title = _("Down...", ctx, self.bot.config) + color = 0xDC3545 e = discord.Embed(title=title, color=color) - e.set_thumbnail( - url=f"https://http.cat/{json['response_code']}" - ) - await ctx.send(embed=e) + await ctx.send(url, embed=e) except ( ClientConnectorError,