diff options
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/constants.py | 3 | ||||
| -rw-r--r-- | bot/exts/evergreen/coinflip.py | 54 | 
2 files changed, 57 insertions, 0 deletions
| diff --git a/bot/constants.py b/bot/constants.py index 6323af80..2730106b 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -239,6 +239,9 @@ class Emojis:      reddit_comments = "<:reddit_comments:755845255001014384>"      reddit_users = "<:reddit_users:755845303822974997>" +    lemon_hyperpleased = "<:lemon_hyperpleased:754441879822663811>" +    lemon_pensive = "<:lemon_pensive:754441880246419486>" +  class Icons:      questionmark = "https://cdn.discordapp.com/emojis/512367613339369475.png" diff --git a/bot/exts/evergreen/coinflip.py b/bot/exts/evergreen/coinflip.py new file mode 100644 index 00000000..d1762463 --- /dev/null +++ b/bot/exts/evergreen/coinflip.py @@ -0,0 +1,54 @@ +import random +from typing import Tuple + +from discord.ext import commands + +from bot.bot import Bot +from bot.constants import Emojis + + +class CoinSide(commands.Converter): +    """Class used to convert the `side` parameter of coinflip command.""" + +    HEADS: Tuple[str] = ("h", "head", "heads") +    TAILS: Tuple[str] = ("t", "tail", "tails") + +    async def convert(self, ctx: commands.Context, side: str) -> str: +        """Converts the provided `side` into the corresponding string.""" +        side = side.lower() +        if side in self.HEADS: +            return "heads" + +        if side in self.TAILS: +            return "tails" + +        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: CoinSide = None) -> None: +        """ +        Flips a coin. + +        If `side` is provided will state whether you guessed the side correctly. +        """ +        flipped_side = random.choice(["heads", "tails"]) + +        message = f"{ctx.author.mention} flipped **{flipped_side}**. " +        if not side: +            await ctx.send(message) +            return + +        if side == flipped_side: +            message += f"You guessed correctly! {Emojis.lemon_hyperpleased}" +        else: +            message += f"You guessed incorrectly. {Emojis.lemon_pensive}" +        await ctx.send(message) + + +def setup(bot: Bot) -> None: +    """Loads the coinflip cog.""" +    bot.add_cog(CoinFlip()) | 
