diff options
Diffstat (limited to 'bot/exts/evergreen/status_codes.py')
-rw-r--r-- | bot/exts/evergreen/status_codes.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index 3725afa8..7f6d160d 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -1,6 +1,10 @@ +from random import choice + import discord from discord.ext import commands +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}**' @@ -9,23 +13,27 @@ ERR_UNKNOWN = 'Error attempting to retrieve status Floof for {code}.' class HTTPStatusCodes(commands.Cog): - """Commands that give HTTP statuses described and visualized by cats and dogs.""" + """ + Fetch an image depicting HTTP status codes as a dog or a cat. + + If neither animal is selected a cat or dog is chosen randomly for the given status code. + """ - 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 containing dog and cat http status code commands.""" - if not ctx.invoked_subcommand: - await ctx.send_help(ctx.command) + @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)) + await subcmd(ctx, code) - @http_status_group.command(name='cat') + @http_status_group.command(name="cat") 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=code), ctx=ctx, code=code) - @http_status_group.command(name='dog') + @http_status_group.command(name="dog") 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=code), ctx=ctx, code=code) @@ -46,6 +54,6 @@ class HTTPStatusCodes(commands.Cog): ) -def setup(bot: commands.Bot) -> None: +def setup(bot: Bot) -> None: """Load the HTTPStatusCodes cog.""" bot.add_cog(HTTPStatusCodes(bot)) |