From 7a4bc85d3fb156cecb93ed0215ae299471187601 Mon Sep 17 00:00:00 2001 From: Elias Cueto Date: Tue, 3 Jun 2025 15:33:00 -0400 Subject: [PATCH 1/2] initial commit for Elias' pip install --upgrade certifi '' ' --- a.py | 0 .../cogs/onboarding/elias_onboarding_cog.py | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 a.py create mode 100644 src/capy_app/frontend/cogs/onboarding/elias_onboarding_cog.py diff --git a/a.py b/a.py new file mode 100644 index 0000000..e69de29 diff --git a/src/capy_app/frontend/cogs/onboarding/elias_onboarding_cog.py b/src/capy_app/frontend/cogs/onboarding/elias_onboarding_cog.py new file mode 100644 index 0000000..4f507a9 --- /dev/null +++ b/src/capy_app/frontend/cogs/onboarding/elias_onboarding_cog.py @@ -0,0 +1,39 @@ +import discord +import logging +from discord.ext import commands +from discord import app_commands + +from frontend import config_colors as colors +from config import settings + + +class EliasCog(commands.Cog): + def __init__(self, bot: commands.Bot): + self.bot = bot + self.logger = logging.getLogger( + f"discord.cog.{self.__class__.__name__.lower()}" + ) + self.status_emojis = { + "🪨": "Rock", + "": "Paper", + "✂️": "Scissors", + "⭐": "Won", + "❌": "Lost", + } + @app_commands.guilds(discord.Object(id=settings.DEBUG_GUILD_ID)) + @app_commands.command(name="RPS", description="Plays Rock Paper Scissors with the bot!", ) + async def ping(self, interaction: discord.Interaction, arg1): + for emoji in self.status_emojis.keys(): + await message.add_reaction(emoji) + message = f"Choose your reaction" + embed = discord.Embed( + title="Ping", + description=message, + color=colors.PING, + ) + self.logger.info(message) + await interaction.response.send_message(embed=embed) + + +async def setup(bot: commands.Bot): + await bot.add_cog(EliasCog(bot)) From cd72067cd71c8e6456b9ed3a288c933cb47ae664 Mon Sep 17 00:00:00 2001 From: Elias Cueto Date: Fri, 6 Jun 2025 13:17:54 -0400 Subject: [PATCH 2/2] RPS working --- .../cogs/onboarding/elias_onboarding_cog.py | 69 +++++++++++++++---- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/src/capy_app/frontend/cogs/onboarding/elias_onboarding_cog.py b/src/capy_app/frontend/cogs/onboarding/elias_onboarding_cog.py index 4f507a9..0e475b0 100644 --- a/src/capy_app/frontend/cogs/onboarding/elias_onboarding_cog.py +++ b/src/capy_app/frontend/cogs/onboarding/elias_onboarding_cog.py @@ -5,7 +5,7 @@ from frontend import config_colors as colors from config import settings - +import random class EliasCog(commands.Cog): def __init__(self, bot: commands.Bot): @@ -15,24 +15,69 @@ def __init__(self, bot: commands.Bot): ) self.status_emojis = { "🪨": "Rock", - "": "Paper", + "🧻": "Paper", "✂️": "Scissors", - "⭐": "Won", - "❌": "Lost", } + @app_commands.guilds(discord.Object(id=settings.DEBUG_GUILD_ID)) - @app_commands.command(name="RPS", description="Plays Rock Paper Scissors with the bot!", ) - async def ping(self, interaction: discord.Interaction, arg1): - for emoji in self.status_emojis.keys(): - await message.add_reaction(emoji) - message = f"Choose your reaction" + @app_commands.command(name="rps", description="Plays Rock Paper Scissors with the bot!", ) + async def rps(self, interaction: discord.Interaction): + + message = f"React to play!" + self.logger.info(message) embed = discord.Embed( - title="Ping", + title="Rock Paper Scissors", description=message, - color=colors.PING, + color=colors.GUILD, ) - self.logger.info(message) await interaction.response.send_message(embed=embed) + msg = await interaction.original_response() + for emoji in self.status_emojis.keys(): + await msg.add_reaction(emoji) + self.bot.rps_message_id = msg.id + self.bot.rps_user_id = interaction.user.id + + def determine_winner(self, user_choice: str, bot_choice: str) -> str: + if user_choice == bot_choice: + return "tied" + wins_against = { + "Rock": "Scissors", + "Scissors": "Paper", + "Paper": "Rock", + } + if wins_against[user_choice] == bot_choice: + return "won ⭐" + else: + return "lost ❌" + + @commands.Cog.listener() + async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User): + if user.bot: + return + + if not hasattr(self.bot, "rps_message_id") or reaction.message.id != self.bot.rps_message_id: + return + + if user.id != self.bot.rps_user_id: + return + + choice = self.status_emojis.get(str(reaction.emoji)) + if not choice: + return + # Delete reaction version + await reaction.message.clear_reactions() + + #Delete message version + #wait reaction.message.delete() + + # Choose bot's random move + import random + bot_choice = random.choice(["Rock", "Paper", "Scissors"]) + result = self.determine_winner(choice, bot_choice) + + await reaction.message.channel.send( + f"{user.mention} chose **{choice}**, I chose **{bot_choice}**. You **{result}**!" + ) async def setup(bot: commands.Bot):