diff options
| author | 2019-11-02 12:15:22 +0000 | |
|---|---|---|
| committer | 2019-11-02 12:15:22 +0000 | |
| commit | abee8a8c51cbea40b2265cec245071ab9a5297a1 (patch) | |
| tree | 9f7397dfd8d6e3fc408a535e2907d3ce108a3dc9 | |
| parent | implement !zen command. (diff) | |
apply kosa's requested changes.
- return None from the command's coroutine as hinted, rather than a discord.Message object.
- only check for one negative sign on !zen index searches (rather than any amount) so that `int(...)` does not fail.
- provide a range of valid indices when a user requests a !zen index out of range.
| -rw-r--r-- | bot/cogs/utils.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/bot/cogs/utils.py b/bot/cogs/utils.py index db8e77062..7dd5e2e56 100644 --- a/bot/cogs/utils.py +++ b/bot/cogs/utils.py @@ -214,12 +214,14 @@ class Utils(Cog): description=ZEN_OF_PYTHON ) - return await ctx.send(embed=embed) + await ctx.send(embed=embed) + return zen_lines = ZEN_OF_PYTHON.splitlines() # check if it's an integer. could be negative. why not. - if search_value.lstrip("-").isdigit(): + is_negative_integer = search_value[0] == "-" and search_value[1:].isdigit() + if search_value.isdigit() or is_negative_integer: index = int(search_value) try: @@ -228,9 +230,8 @@ class Utils(Cog): embed = Embed( colour=Colour.red(), title=random.choice(NEGATIVE_REPLIES), - description="Please provide a valid index." + description=f"Please provide an index between {-len(zen_lines)} and {len(zen_lines) - 1}." ) - else: embed = Embed( colour=Colour.blurple(), @@ -238,7 +239,8 @@ class Utils(Cog): description=line ) - return await ctx.send(embed=embed) + await ctx.send(embed=embed) + return # at this point, we must be dealing with a string search. matcher = difflib.SequenceMatcher(None, search_value.lower()) @@ -266,7 +268,7 @@ class Utils(Cog): description=best_match ) - return await ctx.send(embed=embed) + await ctx.send(embed=embed) def setup(bot: Bot) -> None: |