diff options
author | 2021-09-05 00:31:20 -0400 | |
---|---|---|
committer | 2021-09-05 00:31:20 -0400 | |
commit | 02512e43f3d68ffd89654c5f2e9e3e9a27c0c018 (patch) | |
tree | 4b62a6dbb39601f02aa435c7eb8a10433585c3bb /bot/exts/fun/coinflip.py | |
parent | Move snakes commands into fun folder (diff) |
Move game and fun commands to Fun folder, fix ddg
This moves all the fun commands and games into the fun folder.
This commit also makes changes to the duck_game.
It was setting a footer during an embed init, which is no longer
possible with the version of d.py we use. Additionally, an issue with
editing an embed that had a local image loaded.
The workaround for the time being is to update the message,
not the embed.
Diffstat (limited to 'bot/exts/fun/coinflip.py')
-rw-r--r-- | bot/exts/fun/coinflip.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/bot/exts/fun/coinflip.py b/bot/exts/fun/coinflip.py new file mode 100644 index 00000000..804306bd --- /dev/null +++ b/bot/exts/fun/coinflip.py @@ -0,0 +1,53 @@ +import random + +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 = ("h", "head", "heads") + TAILS = ("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()) |