aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar brad90four <[email protected]>2021-08-31 09:57:50 -0400
committerGravatar brad90four <[email protected]>2021-08-31 09:57:50 -0400
commit815574c21365ab919c9f47990fbccc2c13c3e02d (patch)
tree1360cef78299b4b75a7606b02f4a7fa02e98e070
parentUpdate docstrings, ' -> ", code style (diff)
Add logic to handle acceptable range of codes
Also updated the line breaks, black was formatting on save locally.
-rw-r--r--bot/exts/evergreen/status_codes.py31
1 files changed, 22 insertions, 9 deletions
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))
)