aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/exts/evergreen/coinflip.py54
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())