aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/evergreen/status_codes.py
diff options
context:
space:
mode:
authorGravatar sam-heller <[email protected]>2021-03-03 08:09:03 -0500
committerGravatar sam-heller <[email protected]>2021-03-03 08:09:03 -0500
commit87dc10b37996a8a9ab59058c6fe9baeb7ce665fd (patch)
tree7e85c389d35de606749799cda90c4a6818a8d9d9 /bot/exts/evergreen/status_codes.py
parentReturn 404 Floof embed on invalid status code (diff)
Numerous syntax and bug fixes
Diffstat (limited to 'bot/exts/evergreen/status_codes.py')
-rw-r--r--bot/exts/evergreen/status_codes.py36
1 files changed, 16 insertions, 20 deletions
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))