Skip to content

Conversation

@EliasCueto45
Copy link

@EliasCueto45 EliasCueto45 commented Jun 3, 2025

first draft ups

Summary by Sourcery

New Features:

  • Introduce EliasCog with an /RPS application command that prompts users to react with rock, paper, or scissors and logs interactions

pip install --upgrade certifi
''
'
@EliasCueto45 EliasCueto45 requested a review from YaoxuanZhang June 3, 2025 19:37
@EliasCueto45 EliasCueto45 self-assigned this Jun 3, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Jun 3, 2025

Reviewer's Guide

Adds a new Discord Cog that registers a guild-scoped RPS slash command; the command handler builds an embed, logs its invocation, and attempts to react with a predefined set of emojis.

Sequence Diagram for /RPS Command Interaction

sequenceDiagram
    actor User
    participant DiscordAPI as Discord API
    participant EliasCog

    User->>DiscordAPI: Executes /RPS command
    DiscordAPI->>EliasCog: Interaction (invokes ping method)
    EliasCog->>EliasCog: Log "Choose your reaction"
    EliasCog->>EliasCog: Create Embed (title: "Ping", description: "Choose your reaction")
    EliasCog->>DiscordAPI: interaction.response.send_message(embed)
    DiscordAPI-->>User: Displays message with embed
    loop For each emoji in status_emojis.keys
        EliasCog->>DiscordAPI: Attempt to add reaction (emoji) to the sent message
    end
Loading

Class Diagram for the new EliasCog

classDiagram
    class Cog {
        <<Abstract>>
        # In discord.ext.commands
    }
    class EliasCog {
        +bot: commands.Bot
        +logger: logging.Logger
        +status_emojis: dict
        +__init__(bot: commands.Bot)
        +ping(interaction: discord.Interaction, arg1) async void
    }
    EliasCog --|> Cog
    EliasCog ..> discord.Interaction : uses
    EliasCog ..> discord.Embed : creates
    EliasCog ..> logging.Logger : uses
    EliasCog ..> commands.Bot : uses
Loading

File-Level Changes

Change Details Files
Introduced a new onboarding Cog
  • Created EliasCog class inheriting from commands.Cog
  • Initialized bot reference and a dedicated logger
  • Defined a status_emojis mapping for game reactions
  • Added async setup to register the Cog
src/capy_app/frontend/cogs/onboarding/elias_onboarding_cog.py
Implemented the "RPS" slash command handler
  • Annotated ping() with guild and command decorators
  • Iterated over status_emojis keys and invoked add_reaction
  • Constructed an embed with title, description, and color from config
  • Used interaction.response.send_message to deliver the embed and logged the action
src/capy_app/frontend/cogs/onboarding/elias_onboarding_cog.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @EliasCueto45 - I've reviewed your changes - here's some feedback:

  • You’re calling await message.add_reaction(...) before you even send or define message—send the embed first, capture the returned Message object, then add reactions to it.
  • The status_emojis dict has an empty string for Paper, the slash handler is named ping with an unused arg1, and the embed title reads “Ping” instead of “RPS”—replace the placeholder emoji, rename the method/embed to match RPS, and remove or use arg1.
Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

)
self.status_emojis = {
"🪨": "Rock",
"": "Paper",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Empty string emoji key for Paper

Replace the empty string key with an appropriate emoji (e.g., 📄) or add logic to handle missing keys.

Comment on lines 24 to 25
@app_commands.command(name="RPS", description="Plays Rock Paper Scissors with the bot!", )
async def ping(self, interaction: discord.Interaction, arg1):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Command name and handler name mismatched

Please rename the handler and embed title to consistently reference Rock Paper Scissors.

}
@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):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Unused argument arg1

Remove arg1 if it's unnecessary, or rename it if it will be used later.

Comment on lines 26 to 27
for emoji in self.status_emojis.keys():
await message.add_reaction(emoji)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Reacting before message is defined

message must be defined (sent or fetched) before you can add reactions to it. Move the reaction loop after the message is created.

embed = discord.Embed(
title="Ping",
description=message,
color=colors.PING,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Using PING color for RPS embed

Consider adding a specific RPS color to config_colors for clarity instead of reusing colors.PING.

Suggested implementation:

        embed = discord.Embed(
            title="Ping",
            description=message,
            color=colors.RPS,
        )

You must also add a new color constant for RPS in your colors or config_colors module, for example:

RPS = 0x3498db  # Choose an appropriate hex color code

and ensure it is imported where this file uses colors.

from config import settings


class EliasCog(commands.Cog):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider refactoring the command into a standalone function without a Cog, custom logger, or unused mappings to simplify the implementation.

You can simplify this to a single `@app_commands.command` (no Cog, no custom logger, no unused mapping) while preserving all behavior:

```python
# commands/rps.py

import discord
from discord import app_commands
from discord.ext import commands
from config import settings
from frontend.config_colors import PING as PING_COLOR

@app_commands.guilds(discord.Object(settings.DEBUG_GUILD_ID))
@app_commands.command(name="rps", description="Plays Rock Paper Scissors with the bot")
async def rps(interaction: discord.Interaction):
    embed = discord.Embed(
        title="Rock Paper Scissors",
        description="Choose your reaction",
        color=PING_COLOR,
    )
    await interaction.response.send_message(embed=embed)
    # Grab the sent message and add reactions
    message = await interaction.original_response()
    for emoji in ("🪨", "📄", "✂️", "", ""):
        await message.add_reaction(emoji)

Steps to apply:

  1. Drop the EliasCog class and setup function entirely.
  2. Create a new module (commands/rps.py) with the above code.
  3. Ensure your bot’s startup loads commands/rps.py (e.g. via bot.tree.copy_global_to(guild=...) or your existing command loader).
  4. Remove the unused status_emojis dict and custom logger import.

This keeps the slash-command, the embed, and the reactions, with far less indirection.

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"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Replace f-string with no interpolated values with string (remove-redundant-fstring)

Suggested change
message = f"Choose your reaction"
message = "Choose your reaction"

@EliasCueto45 EliasCueto45 changed the title initial commit for Elias' Rock paper Scissors with bot command Jun 6, 2025
@EliasCueto45 EliasCueto45 changed the title Rock paper Scissors with bot command Rock paper Scissors with bot command Elias Cueto Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants