From 8bdf68bc67115e09a4456a82e9c8e9bca06928ab Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 11 Jul 2020 10:16:55 -0700 Subject: Created the statuscat command. --- bot/exts/evergreen/status_cats.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 bot/exts/evergreen/status_cats.py (limited to 'bot') diff --git a/bot/exts/evergreen/status_cats.py b/bot/exts/evergreen/status_cats.py new file mode 100644 index 00000000..e28b0213 --- /dev/null +++ b/bot/exts/evergreen/status_cats.py @@ -0,0 +1,33 @@ +import logging + +from discord.ext import commands +from http import HTTPStatus +import discord + +log = logging.getLogger(__name__) + + +class StatusCats(commands.Cog): + """Commands that give statuses described and visualized by cats.""" + + def __init__(self, bot: commands.Bot): + self.bot = bot + + @commands.command(aliases=['statuscat']) + async def http_cat(self, ctx, code: int) -> None: + """Sends an embed with an image of a cat, potraying the status code.""" + embed = discord.Embed(title=f'**Status: {code}**') + embed.set_image(url=f'https://http.cat/{code}.jpg') + + try: + HTTPStatus(code) + + except ValueError: + embed.set_footer(text='Inputted status code does not exist.') + + await ctx.send(embed=embed) + + +def setup(bot: commands.Bot) -> None: + """Load the StatusCats cog.""" + bot.add_cog(StatusCats(bot)) -- cgit v1.2.3 From 4c219ac7f616ef008b8deafc49819ab733d1fe4a Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 11 Jul 2020 10:39:01 -0700 Subject: Fixed importing and context argument annotation. --- bot/exts/evergreen/status_cats.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/status_cats.py b/bot/exts/evergreen/status_cats.py index e28b0213..900f0ad6 100644 --- a/bot/exts/evergreen/status_cats.py +++ b/bot/exts/evergreen/status_cats.py @@ -1,8 +1,8 @@ import logging - -from discord.ext import commands from http import HTTPStatus + import discord +from discord.ext import commands log = logging.getLogger(__name__) @@ -14,7 +14,7 @@ class StatusCats(commands.Cog): self.bot = bot @commands.command(aliases=['statuscat']) - async def http_cat(self, ctx, code: int) -> None: + async def http_cat(self, ctx: commands.Context, code: int) -> None: """Sends an embed with an image of a cat, potraying the status code.""" embed = discord.Embed(title=f'**Status: {code}**') embed.set_image(url=f'https://http.cat/{code}.jpg') -- cgit v1.2.3 From 240d64e485eb90da0081597bea615676ae1f3bac Mon Sep 17 00:00:00 2001 From: Xithrius <15021300+Xithrius@users.noreply.github.com> Date: Sun, 12 Jul 2020 17:17:58 -0700 Subject: Update bot/exts/evergreen/status_cats.py Co-authored-by: manusaurio --- bot/exts/evergreen/status_cats.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/status_cats.py b/bot/exts/evergreen/status_cats.py index 900f0ad6..18777e0b 100644 --- a/bot/exts/evergreen/status_cats.py +++ b/bot/exts/evergreen/status_cats.py @@ -17,10 +17,11 @@ class StatusCats(commands.Cog): async def http_cat(self, ctx: commands.Context, code: int) -> None: """Sends an embed with an image of a cat, potraying the status code.""" embed = discord.Embed(title=f'**Status: {code}**') - embed.set_image(url=f'https://http.cat/{code}.jpg') + try: HTTPStatus(code) + embed.set_image(url=f'https://http.cat/{code}.jpg') except ValueError: embed.set_footer(text='Inputted status code does not exist.') -- cgit v1.2.3 From e459832da981e0ed6fb644cec9a244371935a540 Mon Sep 17 00:00:00 2001 From: manusaurio Date: Sun, 12 Jul 2020 21:32:18 -0300 Subject: Delete extra blank line to pass linter --- bot/exts/evergreen/status_cats.py | 1 - 1 file changed, 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/status_cats.py b/bot/exts/evergreen/status_cats.py index 18777e0b..b2077b17 100644 --- a/bot/exts/evergreen/status_cats.py +++ b/bot/exts/evergreen/status_cats.py @@ -18,7 +18,6 @@ class StatusCats(commands.Cog): """Sends an embed with an image of a cat, potraying the status code.""" embed = discord.Embed(title=f'**Status: {code}**') - try: HTTPStatus(code) embed.set_image(url=f'https://http.cat/{code}.jpg') -- cgit v1.2.3 From 51ef384b768933db3aa47ac437ac335de2f4239d Mon Sep 17 00:00:00 2001 From: Xithrius <15021300+Xithrius@users.noreply.github.com> Date: Sun, 12 Jul 2020 18:28:48 -0700 Subject: Update bot/exts/evergreen/status_cats.py Co-authored-by: Dennis Pham --- bot/exts/evergreen/status_cats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/status_cats.py b/bot/exts/evergreen/status_cats.py index b2077b17..e1758514 100644 --- a/bot/exts/evergreen/status_cats.py +++ b/bot/exts/evergreen/status_cats.py @@ -8,7 +8,7 @@ log = logging.getLogger(__name__) class StatusCats(commands.Cog): - """Commands that give statuses described and visualized by cats.""" + """Commands that give HTTP statuses described and visualized by cats.""" def __init__(self, bot: commands.Bot): self.bot = bot -- cgit v1.2.3 From 1631d67e3a4ac11526817a862b1d65222ae753c3 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sun, 12 Jul 2020 18:33:45 -0700 Subject: Removed logging, added more explicit error catching.. --- bot/exts/evergreen/status_cats.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/status_cats.py b/bot/exts/evergreen/status_cats.py index e1758514..586b8378 100644 --- a/bot/exts/evergreen/status_cats.py +++ b/bot/exts/evergreen/status_cats.py @@ -1,11 +1,8 @@ -import logging from http import HTTPStatus import discord from discord.ext import commands -log = logging.getLogger(__name__) - class StatusCats(commands.Cog): """Commands that give HTTP statuses described and visualized by cats.""" @@ -20,12 +17,15 @@ class StatusCats(commands.Cog): try: HTTPStatus(code) - embed.set_image(url=f'https://http.cat/{code}.jpg') except ValueError: embed.set_footer(text='Inputted status code does not exist.') - await ctx.send(embed=embed) + else: + embed.set_image(url=f'https://http.cat/{code}.jpg') + + finally: + await ctx.send(embed=embed) def setup(bot: commands.Bot) -> None: -- cgit v1.2.3