From f8c98972e2341fe621bc9b569a4b2fe0d1c5f391 Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Fri, 14 May 2021 07:16:41 -0500 Subject: Added randomness to cat or dog when not specified --- bot/exts/evergreen/status_codes.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 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 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: -- cgit v1.2.3 From c4ee8a3bd9eeee61e3a2312f6c8a42f64858c8a6 Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Fri, 14 May 2021 07:29:35 -0500 Subject: Added randomness to cat or dog when not specified --- bot/exts/evergreen/status_codes.py | 1 - 1 file changed, 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 63b75a55..0893cf99 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -11,7 +11,6 @@ HTTP_CAT_URL = "https://http.cat/{code}.jpg" class HTTPStatusCodes(commands.Cog): """ 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. """ -- cgit v1.2.3 From d70e6ce0ed8e35b731f0e709b690879fe9c70506 Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Fri, 14 May 2021 13:01:20 -0500 Subject: Fixes linting issue and improves randomness selection. --- bot/exts/evergreen/status_codes.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 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 0893cf99..1fb2231c 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from random import randint +from random import choice import discord from discord.ext import commands @@ -11,6 +11,7 @@ HTTP_CAT_URL = "https://http.cat/{code}.jpg" class HTTPStatusCodes(commands.Cog): """ 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. """ @@ -19,16 +20,15 @@ class HTTPStatusCodes(commands.Cog): @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: - 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) + """Randomize cat/dog picture output when a sub-command is not specified.""" + subcmd = choice((self.http_cat, self.http_dog)) + # if random == 0: + # subcmd = self.bot.get_command("http_status cat") + # else: + # subcmd = self.bot.get_command("http_status dog") + + if await subcmd.can_run(ctx): + await subcmd(ctx, code) @http_status_group.command(name='cat') async def http_cat(self, ctx: commands.Context, code: int) -> None: -- cgit v1.2.3 From 5a6d25aea9a1cae58d1b147bc95c027972aad2a0 Mon Sep 17 00:00:00 2001 From: Icebluewolf <44532864+Icebluewolf@users.noreply.github.com> Date: Fri, 14 May 2021 13:50:30 -0500 Subject: Remove comments and update docstrings Co-authored-by: Joe Banks --- bot/exts/evergreen/status_codes.py | 10 +++------- 1 file changed, 3 insertions(+), 7 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 1fb2231c..0fe9ba47 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -10,9 +10,9 @@ HTTP_CAT_URL = "https://http.cat/{code}.jpg" 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. - Give a cat or dog visualization randomly if the option is not filled. + If neither animal is selected a cat or dog is chosen randomly for the given status code. """ def __init__(self, bot: commands.Bot): @@ -20,12 +20,8 @@ class HTTPStatusCodes(commands.Cog): @commands.group(name="http_status", aliases=("status", "httpstatus"), invoke_without_command=True) async def http_status_group(self, ctx: commands.Context, code: int) -> None: - """Randomize cat/dog picture output when a sub-command is not specified.""" + """Choose a cat or dog randomly for the given status code.""" subcmd = choice((self.http_cat, self.http_dog)) - # if random == 0: - # subcmd = self.bot.get_command("http_status cat") - # else: - # subcmd = self.bot.get_command("http_status dog") if await subcmd.can_run(ctx): await subcmd(ctx, code) -- cgit v1.2.3 From 7ad20d865e499942d13b4589101b65827e135de3 Mon Sep 17 00:00:00 2001 From: Icebluewolf <44532864+Icebluewolf@users.noreply.github.com> Date: Wed, 19 May 2021 17:21:12 -0500 Subject: remove unnecessary check --- bot/exts/evergreen/status_codes.py | 4 +--- 1 file changed, 1 insertion(+), 3 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 dabf004d..089bdb4a 100644 --- a/bot/exts/evergreen/status_codes.py +++ b/bot/exts/evergreen/status_codes.py @@ -24,9 +24,7 @@ class HTTPStatusCodes(commands.Cog): 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)) - - if await subcmd.can_run(ctx): - await subcmd(ctx, code) + await subcmd(ctx, code) @http_status_group.command(name="cat") async def http_cat(self, ctx: commands.Context, code: int) -> None: -- cgit v1.2.3