diff options
| author | 2021-08-23 21:31:46 +0100 | |
|---|---|---|
| committer | 2021-08-23 21:31:46 +0100 | |
| commit | 5f20826574a801e8a31c777ed916944c615e0f4c (patch) | |
| tree | 09005bbfaf04613cb4bced04df2fe0ceb07dcc98 | |
| parent | Merge pull request #795 from D0rs4n/pr/wikipediaissue (diff) | |
Initial commit (add coinflip command in coinflip.py)
| -rw-r--r-- | bot/exts/evergreen/coinflip.py | 54 | 
1 files changed, 54 insertions, 0 deletions
| diff --git a/bot/exts/evergreen/coinflip.py b/bot/exts/evergreen/coinflip.py new file mode 100644 index 00000000..dc9a960b --- /dev/null +++ b/bot/exts/evergreen/coinflip.py @@ -0,0 +1,54 @@ +import random +from typing import Optional, Tuple + +from discord.ext import commands + +from bot.bot import Bot + + +LEMON_HYPERPLEASED = "<:lemon_hyperpleased:754441879822663811>" +LEMON_PENSIVE = "<:lemon_pensive:754441880246419486>" + + +class CoinSide(commands.Converter): +    HEADS: Tuple[str] = ("h", "head", "heads") +    TAILS: Tuple[str] = ("t", "tail", "tails") + +    async def convert(self, ctx: commands.Context, side: str) -> str: +        if side in CoinSide.HEADS: +            return "heads" + +        elif side in CoinSide.TAILS: +            return "tails" + +        else: +            raise commands.BadArgument(f"{side!r} is not a valid coin side.") + + +class CoinFlip(commands.Cog): +    """Cog for the CoinFlip command.""" + +    @commands.command(name="coinflip", aliases=("flip", "coin", "cf")) +    async def coinflip_command(self, ctx: commands.Context, side: Optional[CoinSide]) -> None: +        """ +        Flips a coin. + +        If `coin_side` is provided will state whether you guessed the side correctly. +        """ +        flipped_side = random.choice(["heads", "tails"]) + +        if not side: +            await ctx.send(f"{ctx.author.mention} Flipped **{flipped_side}**!") +            return + +        message = f"{ctx.author.mention} Flipped **{flipped_side}**. " +        if side == flipped_side: +            message += f"You guessed correctly! {LEMON_HYPERPLEASED}" +        else: +            message += f"You guessed incorrectly. {LEMON_PENSIVE}" +        await ctx.send(message) + + +def setup(bot: Bot) -> None: +    """Loads the coinflip cog.""" +    bot.add_cog(CoinFlip()) | 
