From 4ecba07d9ba4c9d98b3199065713d6a8d48c2ff3 Mon Sep 17 00:00:00 2001 From: sam-heller Date: Wed, 3 Mar 2021 06:40:44 -0500 Subject: Removed HTTPStatus Dependency, enable broader Status Code Support --- bot/exts/evergreen/status_codes.py | 80 +++++++++++++------------------------- 1 file changed, 28 insertions(+), 52 deletions(-) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index 874c87eb..231d0254 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -1,71 +1,47 @@ -from http import HTTPStatus - import discord -from discord.ext import commands +from discord.ext.commands import Bot, Cog, Context, group HTTP_DOG_URL = "https://httpstatusdogs.com/img/{code}.jpg" HTTP_CAT_URL = "https://http.cat/{code}.jpg" +STATUS_TEMPLATE = '**Status: {code}**' +ERR_404 = 'Unable to find status Floof for {code}.' +ERR_UNKNOWN = 'Error attempting to retrieve status Floof for {code}.' -class HTTPStatusCodes(commands.Cog): +class HTTPStatusCodes(Cog): """Commands that give HTTP statuses described and visualized by cats and dogs.""" - def __init__(self, bot: commands.Bot): + def __init__(self, bot: Bot): self.bot = bot - @commands.group(name="http_status", aliases=("status", "httpstatus")) - async def http_status_group(self, ctx: commands.Context) -> None: + @group(name="http_status", aliases=("status", "httpstatus")) + async def http_status_group(self, ctx: Context) -> None: """Group containing dog and cat http status code commands.""" if not ctx.invoked_subcommand: await ctx.send_help(ctx.command) @http_status_group.command(name='cat') - async def http_cat(self, ctx: commands.Context, code: int) -> None: - """Sends an embed with an image of a cat, portraying the status code.""" - embed = discord.Embed(title=f'**Status: {code}**') - url = HTTP_CAT_URL.format(code=code) - - try: - HTTPStatus(code) - async with self.bot.http_session.get(url, allow_redirects=False) as response: - if response.status != 404: - embed.set_image(url=url) - else: - raise NotImplementedError - - except ValueError: - embed.set_footer(text='Inputted status code does not exist.') - - except NotImplementedError: - embed.set_footer(text='Inputted status code is not implemented by http.cat yet.') - - finally: - await ctx.send(embed=embed) + async def http_cat(self, ctx: Context, code: int) -> None: + """Assemble Cat URL and build Embed.""" + await self.build_embed(url=HTTP_CAT_URL.format(code), ctx=ctx, code=code) @http_status_group.command(name='dog') - async def http_dog(self, ctx: commands.Context, code: int) -> None: - """Sends an embed with an image of a dog, portraying the status code.""" - embed = discord.Embed(title=f'**Status: {code}**') - url = HTTP_DOG_URL.format(code=code) - - try: - HTTPStatus(code) - async with self.bot.http_session.get(url, allow_redirects=False) as response: - if response.status != 302: - embed.set_image(url=url) - else: - raise NotImplementedError - - except ValueError: - embed.set_footer(text='Inputted status code does not exist.') - - except NotImplementedError: - embed.set_footer(text='Inputted status code is not implemented by httpstatusdogs.com yet.') - - finally: - await ctx.send(embed=embed) - - -def setup(bot: commands.Bot) -> None: + async def http_dog(self, ctx: Context, code: int) -> None: + """Assemble Dog URL and build Embed.""" + await self.build_embed(url=HTTP_DOG_URL.format(code), ctx=ctx, code=code) + + async def build_embed(self, url: str, code: int, ctx: Context, ) -> None: + """Attempt to build and dispatch embed. Append error message instead of something goes wrong.""" + async with self.bot.http_session.get(url, allow_redirects=False) as response: + if 200 <= response.status <= 299: + await ctx.send(embed=discord.Embed(title=STATUS_TEMPLATE.format(code), url=url)) + else: + await ctx.send(embed=discord.Embed( + title=STATUS_TEMPLATE.format(code), + footer=ERR_404.format(code) if response.status == 404 else ERR_UNKNOWN.format(code)) + ) + + +def setup(bot: Bot) -> None: """Load the HTTPStatusCodes cog.""" bot.add_cog(HTTPStatusCodes(bot)) -- cgit v1.2.3 From c91ae2d6aaffbde168ab85e35ff3ad7ce6dedda2 Mon Sep 17 00:00:00 2001 From: sam-heller Date: Wed, 3 Mar 2021 07:14:53 -0500 Subject: Return 404 Floof embed on invalid status code --- bot/exts/evergreen/status_codes.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index 231d0254..91eaa988 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -31,15 +31,23 @@ class HTTPStatusCodes(Cog): await self.build_embed(url=HTTP_DOG_URL.format(code), ctx=ctx, code=code) async def build_embed(self, url: str, code: int, ctx: Context, ) -> None: - """Attempt to build and dispatch embed. Append error message instead of something goes wrong.""" + """Attempt to build and dispatch embed. Append error message instead if something goes wrong.""" async with self.bot.http_session.get(url, allow_redirects=False) as response: if 200 <= response.status <= 299: - await ctx.send(embed=discord.Embed(title=STATUS_TEMPLATE.format(code), url=url)) + await ctx.send(embed=discord.Embed( + title=STATUS_TEMPLATE.format(code), + url=url + )) + elif 404 == response.status: + await ctx.send(embed=discord.Embed( + title=ERR_404.format(code), + url=url + )) else: await ctx.send(embed=discord.Embed( title=STATUS_TEMPLATE.format(code), - footer=ERR_404.format(code) if response.status == 404 else ERR_UNKNOWN.format(code)) - ) + footer=ERR_UNKNOWN.format(code) + )) def setup(bot: Bot) -> None: -- cgit v1.2.3 From 87dc10b37996a8a9ab59058c6fe9baeb7ce665fd Mon Sep 17 00:00:00 2001 From: sam-heller Date: Wed, 3 Mar 2021 08:09:03 -0500 Subject: Numerous syntax and bug fixes --- bot/exts/evergreen/status_codes.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index 91eaa988..3725afa8 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -1,5 +1,5 @@ import discord -from discord.ext.commands import Bot, Cog, Context, group +from discord.ext import commands HTTP_DOG_URL = "https://httpstatusdogs.com/img/{code}.jpg" HTTP_CAT_URL = "https://http.cat/{code}.jpg" @@ -8,48 +8,44 @@ ERR_404 = 'Unable to find status Floof for {code}.' ERR_UNKNOWN = 'Error attempting to retrieve status Floof for {code}.' -class HTTPStatusCodes(Cog): +class HTTPStatusCodes(commands.Cog): """Commands that give HTTP statuses described and visualized by cats and dogs.""" - def __init__(self, bot: Bot): + def __init__(self, bot: commands.Bot): self.bot = bot - @group(name="http_status", aliases=("status", "httpstatus")) - async def http_status_group(self, ctx: Context) -> None: + @commands.group(name="http_status", aliases=("status", "httpstatus")) + async def http_status_group(self, ctx: commands.Context) -> None: """Group containing dog and cat http status code commands.""" if not ctx.invoked_subcommand: await ctx.send_help(ctx.command) @http_status_group.command(name='cat') - async def http_cat(self, ctx: Context, code: int) -> None: + async def http_cat(self, ctx: commands.Context, code: int) -> None: """Assemble Cat URL and build Embed.""" - await self.build_embed(url=HTTP_CAT_URL.format(code), ctx=ctx, code=code) + await self.build_embed(url=HTTP_CAT_URL.format(code=code), ctx=ctx, code=code) @http_status_group.command(name='dog') - async def http_dog(self, ctx: Context, code: int) -> None: + async def http_dog(self, ctx: commands.Context, code: int) -> None: """Assemble Dog URL and build Embed.""" - await self.build_embed(url=HTTP_DOG_URL.format(code), ctx=ctx, code=code) + await self.build_embed(url=HTTP_DOG_URL.format(code=code), ctx=ctx, code=code) - async def build_embed(self, url: str, code: int, ctx: Context, ) -> None: + async def build_embed(self, url: str, ctx: commands.Context, code: int) -> None: """Attempt to build and dispatch embed. Append error message instead if something goes wrong.""" async with self.bot.http_session.get(url, allow_redirects=False) as response: if 200 <= response.status <= 299: await ctx.send(embed=discord.Embed( - title=STATUS_TEMPLATE.format(code), - url=url - )) + title=STATUS_TEMPLATE.format(code=code)).set_image(url=url)) elif 404 == response.status: await ctx.send(embed=discord.Embed( - title=ERR_404.format(code), - url=url - )) + title=ERR_404.format(code=code)).set_image(url=url) + ) else: await ctx.send(embed=discord.Embed( - title=STATUS_TEMPLATE.format(code), - footer=ERR_UNKNOWN.format(code) - )) + title=STATUS_TEMPLATE.format(code=code), footer=ERR_UNKNOWN.format(code=code)) + ) -def setup(bot: Bot) -> None: +def setup(bot: commands.Bot) -> None: """Load the HTTPStatusCodes cog.""" bot.add_cog(HTTPStatusCodes(bot)) -- cgit v1.2.3 From 491ae8c2e8f2afde1b3f9c928684ef2170f17551 Mon Sep 17 00:00:00 2001 From: bradtimmis Date: Mon, 30 Aug 2021 22:14:33 -0400 Subject: Add requested changes Now that the branch is correctly tracking only the changes to the file `status_codes.py` the other requests can be addressed. Currently the only change not addressed is to handle the range of responses allowed. My focus will be on lines 45 to 64 for these changes. Issues #428 #500 #608 PR #610 --- bot/exts/evergreen/status_codes.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index 7f6d160d..2395f581 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -7,9 +7,9 @@ from bot.bot import Bot HTTP_DOG_URL = "https://httpstatusdogs.com/img/{code}.jpg" HTTP_CAT_URL = "https://http.cat/{code}.jpg" -STATUS_TEMPLATE = '**Status: {code}**' -ERR_404 = 'Unable to find status Floof for {code}.' -ERR_UNKNOWN = 'Error attempting to retrieve status Floof for {code}.' +STATUS_TEMPLATE = "**Status: {code}**" +ERR_404 = "Unable to find status Floof for {code}." +ERR_UNKNOWN = "Error attempting to retrieve status Floof for {code}." class HTTPStatusCodes(commands.Cog): @@ -22,7 +22,11 @@ class HTTPStatusCodes(commands.Cog): def __init__(self, bot: Bot): self.bot = bot - @commands.group(name="http_status", aliases=("status", "httpstatus"), invoke_without_command=True) + @commands.group( + name="http_status", + aliases=("status", "httpstatus"), + invoke_without_command=True, + ) async def http_status_group(self, ctx: commands.Context, code: int) -> None: """Choose a cat or dog randomly for the given status code.""" subcmd = choice((self.http_cat, self.http_dog)) @@ -42,15 +46,23 @@ class HTTPStatusCodes(commands.Cog): """Attempt to build and dispatch embed. Append error message instead if something goes wrong.""" async with self.bot.http_session.get(url, allow_redirects=False) as response: if 200 <= response.status <= 299: - await ctx.send(embed=discord.Embed( - title=STATUS_TEMPLATE.format(code=code)).set_image(url=url)) + await ctx.send( + embed=discord.Embed( + title=STATUS_TEMPLATE.format(code=code) + ).set_image(url=url) + ) elif 404 == response.status: - await ctx.send(embed=discord.Embed( - title=ERR_404.format(code=code)).set_image(url=url) + await ctx.send( + embed=discord.Embed(title=ERR_404.format(code=code)).set_image( + url=url + ) ) else: - await ctx.send(embed=discord.Embed( - title=STATUS_TEMPLATE.format(code=code), footer=ERR_UNKNOWN.format(code=code)) + await ctx.send( + embed=discord.Embed( + title=STATUS_TEMPLATE.format(code=code), + footer=ERR_UNKNOWN.format(code=code), + ) ) -- cgit v1.2.3 From 2ffadc4941990e856b12887e3f456df72ac76aa5 Mon Sep 17 00:00:00 2001 From: brad90four <42116429+brad90four@users.noreply.github.com> Date: Tue, 31 Aug 2021 08:12:12 -0400 Subject: Update docstrings, ' -> ", code style --- bot/exts/evergreen/status_codes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index 2395f581..c3eedfb1 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -8,8 +8,8 @@ from bot.bot import Bot HTTP_DOG_URL = "https://httpstatusdogs.com/img/{code}.jpg" HTTP_CAT_URL = "https://http.cat/{code}.jpg" STATUS_TEMPLATE = "**Status: {code}**" -ERR_404 = "Unable to find status Floof for {code}." -ERR_UNKNOWN = "Error attempting to retrieve status Floof for {code}." +ERR_404 = "Unable to find status floof for {code}." +ERR_UNKNOWN = "Error attempting to retrieve status floof for {code}." class HTTPStatusCodes(commands.Cog): @@ -34,12 +34,12 @@ class HTTPStatusCodes(commands.Cog): @http_status_group.command(name="cat") async def http_cat(self, ctx: commands.Context, code: int) -> None: - """Assemble Cat URL and build Embed.""" + """Send a cat version of the requested HTTP status code.""" await self.build_embed(url=HTTP_CAT_URL.format(code=code), ctx=ctx, code=code) @http_status_group.command(name="dog") async def http_dog(self, ctx: commands.Context, code: int) -> None: - """Assemble Dog URL and build Embed.""" + """Send a dog version of the requested HTTP status code.""" await self.build_embed(url=HTTP_DOG_URL.format(code=code), ctx=ctx, code=code) async def build_embed(self, url: str, ctx: commands.Context, code: int) -> None: -- cgit v1.2.3 From 815574c21365ab919c9f47990fbccc2c13c3e02d Mon Sep 17 00:00:00 2001 From: brad90four <42116429+brad90four@users.noreply.github.com> Date: Tue, 31 Aug 2021 09:57:50 -0400 Subject: Add logic to handle acceptable range of codes Also updated the line breaks, black was formatting on save locally. --- bot/exts/evergreen/status_codes.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index c3eedfb1..8a9a4f72 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -35,34 +35,47 @@ class HTTPStatusCodes(commands.Cog): @http_status_group.command(name="cat") async def http_cat(self, ctx: commands.Context, code: int) -> None: """Send a cat version of the requested HTTP status code.""" - await self.build_embed(url=HTTP_CAT_URL.format(code=code), ctx=ctx, code=code) + if code in range(100, 599): + await self.build_embed(url=HTTP_CAT_URL.format(code=code), ctx=ctx, code=code) + await ctx.send( + embed=discord.Embed( + title="Input status code does not exist", + description="The range of accepted status codes that are ok is from 100 to 599", + ) + ) @http_status_group.command(name="dog") async def http_dog(self, ctx: commands.Context, code: int) -> None: """Send a dog version of the requested HTTP status code.""" - await self.build_embed(url=HTTP_DOG_URL.format(code=code), ctx=ctx, code=code) + if code in range(100, 599): + await self.build_embed(url=HTTP_CAT_URL.format(code=code), ctx=ctx, code=code) + await ctx.send( + embed=discord.Embed( + title="Input status code does not exist", + description="The range of accepted status codes that are ok is from 100 to 599", + ) + ) async def build_embed(self, url: str, ctx: commands.Context, code: int) -> None: """Attempt to build and dispatch embed. Append error message instead if something goes wrong.""" async with self.bot.http_session.get(url, allow_redirects=False) as response: - if 200 <= response.status <= 299: + if response.status in range(200, 299): await ctx.send( embed=discord.Embed( title=STATUS_TEMPLATE.format(code=code) ).set_image(url=url) ) - elif 404 == response.status: + elif response.status == 404: await ctx.send( - embed=discord.Embed(title=ERR_404.format(code=code)).set_image( - url=url - ) + embed=discord.Embed( + title=ERR_404.format(code=code) + ).set_image(url=url) ) else: await ctx.send( embed=discord.Embed( title=STATUS_TEMPLATE.format(code=code), - footer=ERR_UNKNOWN.format(code=code), - ) + ).Embed.set_footer(ERR_UNKNOWN.format(code=code)) ) -- cgit v1.2.3 From 1c0ae5925495228a35e782e28a567f4769ee7a2b Mon Sep 17 00:00:00 2001 From: brad90four <42116429+brad90four@users.noreply.github.com> Date: Tue, 31 Aug 2021 10:15:19 -0400 Subject: Remove unnecessary comma --- bot/exts/evergreen/status_codes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index 8a9a4f72..f4c6763e 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -74,7 +74,7 @@ class HTTPStatusCodes(commands.Cog): else: await ctx.send( embed=discord.Embed( - title=STATUS_TEMPLATE.format(code=code), + title=STATUS_TEMPLATE.format(code=code) ).Embed.set_footer(ERR_UNKNOWN.format(code=code)) ) -- cgit v1.2.3 From ef0bdca4f2e3cab4879ca6f094ee505b09b00094 Mon Sep 17 00:00:00 2001 From: brad90four <42116429+brad90four@users.noreply.github.com> Date: Tue, 31 Aug 2021 12:04:30 -0400 Subject: Add returns after sending embed This will avoid sending the error embed even when the status codes are ok. --- bot/exts/evergreen/status_codes.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index f4c6763e..53d7b964 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -37,6 +37,7 @@ class HTTPStatusCodes(commands.Cog): """Send a cat version of the requested HTTP status code.""" if code in range(100, 599): await self.build_embed(url=HTTP_CAT_URL.format(code=code), ctx=ctx, code=code) + return await ctx.send( embed=discord.Embed( title="Input status code does not exist", @@ -49,6 +50,7 @@ class HTTPStatusCodes(commands.Cog): """Send a dog version of the requested HTTP status code.""" if code in range(100, 599): await self.build_embed(url=HTTP_CAT_URL.format(code=code), ctx=ctx, code=code) + return await ctx.send( embed=discord.Embed( title="Input status code does not exist", -- cgit v1.2.3 From 628bd9dfcc50e3cedb8a38c9915f89fcce2c2564 Mon Sep 17 00:00:00 2001 From: brad90four <42116429+brad90four@users.noreply.github.com> Date: Tue, 31 Aug 2021 14:20:52 -0400 Subject: Fix Dog instead of Cat, code error embed update Corrected the URL for the Dog embed (was mistakenly using CAT URL. Created a standalone ERROR_LENGTH_EMBED to send if the code used by the user is not in the range 100, 599. Changed the response status check to include 299 (to be proper). --- bot/exts/evergreen/status_codes.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index 53d7b964..56cc5786 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -10,6 +10,10 @@ HTTP_CAT_URL = "https://http.cat/{code}.jpg" STATUS_TEMPLATE = "**Status: {code}**" ERR_404 = "Unable to find status floof for {code}." ERR_UNKNOWN = "Error attempting to retrieve status floof for {code}." +ERROR_LENGTH_EMBED = discord.Embed( + title="Input status code does not exist", + description="The range of valid status codes is 100 to 599", +) class HTTPStatusCodes(commands.Cog): @@ -38,30 +42,20 @@ class HTTPStatusCodes(commands.Cog): if code in range(100, 599): await self.build_embed(url=HTTP_CAT_URL.format(code=code), ctx=ctx, code=code) return - await ctx.send( - embed=discord.Embed( - title="Input status code does not exist", - description="The range of accepted status codes that are ok is from 100 to 599", - ) - ) + await ctx.send(embed=ERROR_LENGTH_EMBED) @http_status_group.command(name="dog") async def http_dog(self, ctx: commands.Context, code: int) -> None: """Send a dog version of the requested HTTP status code.""" if code in range(100, 599): - await self.build_embed(url=HTTP_CAT_URL.format(code=code), ctx=ctx, code=code) + await self.build_embed(url=HTTP_DOG_URL.format(code=code), ctx=ctx, code=code) return - await ctx.send( - embed=discord.Embed( - title="Input status code does not exist", - description="The range of accepted status codes that are ok is from 100 to 599", - ) - ) + await ctx.send(embed=ERROR_LENGTH_EMBED) async def build_embed(self, url: str, ctx: commands.Context, code: int) -> None: """Attempt to build and dispatch embed. Append error message instead if something goes wrong.""" async with self.bot.http_session.get(url, allow_redirects=False) as response: - if response.status in range(200, 299): + if response.status in range(200, 300): await ctx.send( embed=discord.Embed( title=STATUS_TEMPLATE.format(code=code) -- cgit v1.2.3 From 7151ba8ff8265de4ccfcb7afbe2db0c3e0efc064 Mon Sep 17 00:00:00 2001 From: brad90four <42116429+brad90four@users.noreply.github.com> Date: Tue, 31 Aug 2021 14:26:49 -0400 Subject: All ranges are inclusive Changed the range check for the status code. Previously was 599, now 600. --- bot/exts/evergreen/status_codes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index 56cc5786..54b43304 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -39,7 +39,7 @@ class HTTPStatusCodes(commands.Cog): @http_status_group.command(name="cat") async def http_cat(self, ctx: commands.Context, code: int) -> None: """Send a cat version of the requested HTTP status code.""" - if code in range(100, 599): + if code in range(100, 600): await self.build_embed(url=HTTP_CAT_URL.format(code=code), ctx=ctx, code=code) return await ctx.send(embed=ERROR_LENGTH_EMBED) @@ -47,7 +47,7 @@ class HTTPStatusCodes(commands.Cog): @http_status_group.command(name="dog") async def http_dog(self, ctx: commands.Context, code: int) -> None: """Send a dog version of the requested HTTP status code.""" - if code in range(100, 599): + if code in range(100, 600): await self.build_embed(url=HTTP_DOG_URL.format(code=code), ctx=ctx, code=code) return await ctx.send(embed=ERROR_LENGTH_EMBED) -- cgit v1.2.3 From 88e0d819d9e40eb5f163fb68828328756652657c Mon Sep 17 00:00:00 2001 From: brad90four <42116429+brad90four@users.noreply.github.com> Date: Tue, 31 Aug 2021 15:19:11 -0400 Subject: Fix Embed footer text, catch 302 response The unknown error embed was not using the text correctly, using the suggestion from wookie to fix. The "404" response from the dog URL returns 302 instead, changed the elif to check if 302 response is returned. --- bot/exts/evergreen/status_codes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index 54b43304..d6bd4fcc 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -61,7 +61,7 @@ class HTTPStatusCodes(commands.Cog): title=STATUS_TEMPLATE.format(code=code) ).set_image(url=url) ) - elif response.status == 404: + elif response.status in (302, 404): # dog URL returns 302 instead of 404 await ctx.send( embed=discord.Embed( title=ERR_404.format(code=code) @@ -71,7 +71,7 @@ class HTTPStatusCodes(commands.Cog): await ctx.send( embed=discord.Embed( title=STATUS_TEMPLATE.format(code=code) - ).Embed.set_footer(ERR_UNKNOWN.format(code=code)) + ).Embed.set_footer(text=ERR_UNKNOWN.format(code=code)) ) -- cgit v1.2.3 From c8a31fd4971a7b356fbe36aa7e063f8d576902f3 Mon Sep 17 00:00:00 2001 From: bradtimmis Date: Wed, 1 Sep 2021 07:16:34 -0400 Subject: Remove unnecessary Embed from set_footer --- bot/exts/evergreen/status_codes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index d6bd4fcc..6151620d 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -71,7 +71,7 @@ class HTTPStatusCodes(commands.Cog): await ctx.send( embed=discord.Embed( title=STATUS_TEMPLATE.format(code=code) - ).Embed.set_footer(text=ERR_UNKNOWN.format(code=code)) + ).set_footer(text=ERR_UNKNOWN.format(code=code)) ) -- cgit v1.2.3 From e395d1570541c37f4dea8fad1d896cb89d0d1601 Mon Sep 17 00:00:00 2001 From: bradtimmis Date: Wed, 1 Sep 2021 07:35:31 -0400 Subject: Handle status not found with 404 picture Hard-coded in the appropriate 404 jpgs for wehn a status code does not exist from the dog or cat urls. --- bot/exts/evergreen/status_codes.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'bot/exts/evergreen/status_codes.py') diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index 6151620d..501cbe0a 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -62,10 +62,17 @@ class HTTPStatusCodes(commands.Cog): ).set_image(url=url) ) elif response.status in (302, 404): # dog URL returns 302 instead of 404 + if "dog" in url: + await ctx.send( + embed=discord.Embed( + title=ERR_404.format(code=code) + ).set_image(url="https://httpstatusdogs.com/img/404.jpg") + ) + return await ctx.send( embed=discord.Embed( title=ERR_404.format(code=code) - ).set_image(url=url) + ).set_image(url="https://http.cat/404.jpg") ) else: await ctx.send( -- cgit v1.2.3