From 02512e43f3d68ffd89654c5f2e9e3e9a27c0c018 Mon Sep 17 00:00:00 2001 From: Janine vN Date: Sun, 5 Sep 2021 00:31:20 -0400 Subject: 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. --- bot/exts/fun/rps.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 bot/exts/fun/rps.py (limited to 'bot/exts/fun/rps.py') diff --git a/bot/exts/fun/rps.py b/bot/exts/fun/rps.py new file mode 100644 index 00000000..c6bbff46 --- /dev/null +++ b/bot/exts/fun/rps.py @@ -0,0 +1,57 @@ +from random import choice + +from discord.ext import commands + +from bot.bot import Bot + +CHOICES = ["rock", "paper", "scissors"] +SHORT_CHOICES = ["r", "p", "s"] + +# Using a dictionary instead of conditions to check for the winner. +WINNER_DICT = { + "r": { + "r": 0, + "p": -1, + "s": 1, + }, + "p": { + "r": 1, + "p": 0, + "s": -1, + }, + "s": { + "r": -1, + "p": 1, + "s": 0, + } +} + + +class RPS(commands.Cog): + """Rock Paper Scissors. The Classic Game!""" + + @commands.command(case_insensitive=True) + async def rps(self, ctx: commands.Context, move: str) -> None: + """Play the classic game of Rock Paper Scissors with your own sir-lancebot!""" + move = move.lower() + player_mention = ctx.author.mention + + if move not in CHOICES and move not in SHORT_CHOICES: + raise commands.BadArgument(f"Invalid move. Please make move from options: {', '.join(CHOICES).upper()}.") + + bot_move = choice(CHOICES) + # value of player_result will be from (-1, 0, 1) as (lost, tied, won). + player_result = WINNER_DICT[move[0]][bot_move[0]] + + if player_result == 0: + message_string = f"{player_mention} You and Sir Lancebot played {bot_move}, it's a tie." + await ctx.send(message_string) + elif player_result == 1: + await ctx.send(f"Sir Lancebot played {bot_move}! {player_mention} won!") + else: + await ctx.send(f"Sir Lancebot played {bot_move}! {player_mention} lost!") + + +def setup(bot: Bot) -> None: + """Load the RPS Cog.""" + bot.add_cog(RPS(bot)) -- cgit v1.2.3