Skip to content

Conversation

@simtiaz5
Copy link

@simtiaz5 simtiaz5 commented Jun 3, 2025

Added personal cog

Summary by Sourcery

Add personal "SayedCog" onboarding extension with a /countdown slash command for ephemeral timers.

New Features:

  • Introduce SayedCog as a new onboarding cog.
  • Implement /countdown slash command that accepts a 1–30 second input and updates the response each second until completion.

@simtiaz5 simtiaz5 self-assigned this Jun 3, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Jun 3, 2025

Reviewer's Guide

This PR introduces a new Discord Cog (SayedCog) that registers a /countdown slash command, validates its input, sends an initial ephemeral message, updates it every second to count down, and concludes with a final notification.

Sequence Diagram for /countdown Command Interaction

sequenceDiagram
    actor User
    participant I as discord.Interaction
    participant C as SayedCog

    User->>I: /countdown (seconds)
    I->>C: countdown(interaction, seconds)
    activate C
    alt Input: seconds < 1 OR seconds > 30
        C->>I: response.send_message("Please provide a number between 1 and 30 seconds.", ephemeral=True)
    else Input: seconds is valid
        C->>I: response.send_message("Counting down from {seconds} seconds...", ephemeral=True)
        loop For each second from input 'seconds' down to 1
            C-->>I: edit_original_response(content="{remaining_time}...")
        end
        C-->>I: edit_original_response(content="Time's up!")
    end
    deactivate C
Loading

Class Diagram for the New SayedCog

classDiagram
    class SayedCog {
        +bot: commands.Bot
        +logger: logging.Logger
        +__init__(bot: commands.Bot)
        +countdown(interaction: discord.Interaction, seconds: int) async
    }
    class commands.Cog {
        <<Base Class>>
    }
    SayedCog --|> commands.Cog
Loading

File-Level Changes

Change Details Files
Add SayedCog with a countdown slash command
  • Define /countdown command scoped to the debug guild
  • Validate seconds parameter between 1 and 30
  • Send an initial ephemeral response and iteratively edit it each second
  • Conclude the sequence with a "Time's up!" message
src/capy_app/frontend/cogs/onboarding/sayed_onboarding_cog.py
Implement cog infrastructure and logging
  • Initialize a logger in the cog constructor
  • Provide async setup function to register the cog with the bot
src/capy_app/frontend/cogs/onboarding/sayed_onboarding_cog.py
Include necessary imports and configuration
  • Import discord, commands, app_commands, and asyncio
  • Load color and settings modules for guild ID and styling
src/capy_app/frontend/cogs/onboarding/sayed_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

@simtiaz5 simtiaz5 requested a review from gianlucazhang2 June 3, 2025 19:36
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 @simtiaz5 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 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.

@app_commands.command(name="countdown", description="Counts down the input seconds to 0. Allowed range is 1-30 seconds.")
async def countdown(self, interaction: discord.Interaction, seconds: int):
if seconds < 1 or seconds > 30:
await interaction.response.send_message(
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider using a deferred response for long-running operations

Deferring the interaction prevents timeouts and lets you handle the countdown asynchronously.


@app_commands.guilds(discord.Object(id=settings.DEBUG_GUILD_ID))
@app_commands.command(name="countdown", description="Counts down the input seconds to 0. Allowed range is 1-30 seconds.")
async def countdown(self, interaction: discord.Interaction, seconds: int):
Copy link

Choose a reason for hiding this comment

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

suggestion: Use app_commands.Range to enforce input bounds

This approach removes the need for a manual range check and leverages built-in validation.

Comment on lines 32 to 36
for i in range(seconds, 0, -1):
await asyncio.sleep(1)
await interaction.edit_original_response(content=f"{i}...")
await asyncio.sleep(1)
await interaction.edit_original_response(content="Time's up!")
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Handle potential failures when editing the response

Wrap each edit_original_response call in a try/except block to handle possible discord.HTTPException errors and prevent the countdown from crashing.

Suggested change
for i in range(seconds, 0, -1):
await asyncio.sleep(1)
await interaction.edit_original_response(content=f"{i}...")
await asyncio.sleep(1)
await interaction.edit_original_response(content="Time's up!")
import discord # Ensure discord is imported for HTTPException
for i in range(seconds, 0, -1):
await asyncio.sleep(1)
try:
await interaction.edit_original_response(content=f"{i}...")
except discord.HTTPException as e:
# Optionally log the error or handle it as needed
print(f"Failed to edit response during countdown: {e}")
break
await asyncio.sleep(1)
try:
await interaction.edit_original_response(content="Time's up!")
except discord.HTTPException as e:
print(f"Failed to edit response at end of countdown: {e}")

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