diff options
author | 2021-05-14 07:16:41 -0500 | |
---|---|---|
committer | 2021-05-14 07:16:41 -0500 | |
commit | f8c98972e2341fe621bc9b569a4b2fe0d1c5f391 (patch) | |
tree | 201cc00b477d6500d4661c27e72c9eb50402c648 /bot/exts/evergreen/status_codes.py | |
parent | Merge pull request #727 from python-discord/reddit-revoke (diff) |
Added randomness to cat or dog when not specified
Diffstat (limited to 'bot/exts/evergreen/status_codes.py')
-rw-r--r-- | bot/exts/evergreen/status_codes.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py index 7c00fe20..63b75a55 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -1,25 +1,35 @@ from http import HTTPStatus +from random import randint import discord from discord.ext import commands -from bot.utils.extensions import invoke_help_command - HTTP_DOG_URL = "https://httpstatusdogs.com/img/{code}.jpg" HTTP_CAT_URL = "https://http.cat/{code}.jpg" class HTTPStatusCodes(commands.Cog): - """Commands that give HTTP statuses described and visualized by cats and dogs.""" + """ + Commands that give HTTP statuses described and visualized by cats and dogs. + + Give a cat or dog visualization randomly if the option is not filled. + """ def __init__(self, bot: commands.Bot): self.bot = bot - @commands.group(name="http_status", aliases=("status", "httpstatus")) - async def http_status_group(self, ctx: commands.Context) -> None: + @commands.group(name="http_status", aliases=("status", "httpstatus"), invoke_without_command=True) + async def http_status_group(self, ctx: commands.Context, code: int) -> None: """Group containing dog and cat http status code commands.""" if not ctx.invoked_subcommand: - await invoke_help_command(ctx) + random = randint(0, 1) + if random == 0: + subcmd = self.bot.get_command("http_status cat") + else: + subcmd = self.bot.get_command("http_status dog") + + if await commands.Group.can_run(subcmd, ctx): + await subcmd(ctx, code) @http_status_group.command(name='cat') async def http_cat(self, ctx: commands.Context, code: int) -> None: |