diff options
| author | 2020-10-10 10:57:16 +0200 | |
|---|---|---|
| committer | 2020-10-10 10:57:16 +0200 | |
| commit | d643b103868e41a5a17f96f17f40d151f73c6d24 (patch) | |
| tree | 6be90800323da481f1cac46fd46d98c82bbaf221 /bot/exts | |
| parent | PR #492: Fix & improve snake video command (diff) | |
| parent | Merge branch 'master' into space-out-dice (diff) | |
Merge pull request #481 from python-discord/space-out-dice
Add space between dice in roll command
Diffstat (limited to '')
| -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 de6a92c6..231e6d54 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 @@ -57,18 +57,20 @@ class Fun(Cog):          with Path("bot/resources/evergreen/caesar_info.json").open("r", encoding="UTF-8") as f:              self._caesar_cipher_embed = json.load(f) +    @staticmethod +    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) +      @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) +        if 1 <= num_rolls <= 6: +            dice = " ".join(self._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: | 
