diff options
| author | 2020-10-05 18:54:12 +0200 | |
|---|---|---|
| committer | 2020-10-05 18:54:12 +0200 | |
| commit | cfb9237d38b2e2961d1aa2f7dd41f81c7346fb57 (patch) | |
| tree | 0c2047c8478350dcc9ad586cb84d508b9b947512 /bot/exts | |
| parent | Revert and update roll command (diff) | |
Rewrite roll command
- Improves readability
- Sends dice separated by single spaces
Diffstat (limited to 'bot/exts')
| -rw-r--r-- | bot/exts/evergreen/fun.py | 22 | 
1 files changed, 12 insertions, 10 deletions
| diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 23715906..09400d23 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -7,7 +7,7 @@ from typing import Callable, Iterable, Tuple, Union  from discord import Embed, Message  from discord.ext import commands -from discord.ext.commands import Bot, Cog, Context, MessageConverter, clean_content +from discord.ext.commands import BadArgument, Bot, Cog, Context, MessageConverter, clean_content  from bot import utils  from bot.constants import Colours, Emojis @@ -60,15 +60,17 @@ class Fun(Cog):      @commands.command()      async def roll(self, ctx: Context, num_rolls: int = 1) -> None:          """Outputs a number of random dice emotes (up to 6).""" -        output = "" -        if num_rolls > 6: -            num_rolls = 6 -        elif num_rolls < 1: -            output = ":no_entry: You must roll at least once." -        for _ in range(num_rolls): -            dice = f"dice_{random.randint(1, 6)}" -            output += getattr(Emojis, dice, '') + " " -        await ctx.send(output.rstrip()) +        def _get_random_die() -> str: +            """Generate a random die emoji, ready to be sent on Discord.""" +            die_name = f"dice_{random.randint(1, 6)}" +            return getattr(Emojis, die_name) + +        # Only support between 1 and 6 rolls +        if 1 <= num_rolls <= 6: +            dice = " ".join(_get_random_die() for _ in range(num_rolls)) +            await ctx.send(dice) +        else: +            raise BadArgument("`!roll` only supports between 1 and 6 rolls.")      @commands.command(name="uwu", aliases=("uwuwize", "uwuify",))      async def uwu_command(self, ctx: Context, *, text: clean_content(fix_channel_mentions=True)) -> None: | 
