-
Notifications
You must be signed in to change notification settings - Fork 0
Initial commi for Sayed I. #3
base: main
Are you sure you want to change the base?
Conversation
Reviewer's GuideThis PR introduces a new Discord Cog (SayedCog) that registers a Sequence Diagram for /countdown Command InteractionsequenceDiagram
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
Class Diagram for the New SayedCogclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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
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( |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
| 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!") |
There was a problem hiding this comment.
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.
| 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}") |
Added personal cog
Summary by Sourcery
Add personal "SayedCog" onboarding extension with a
/countdownslash command for ephemeral timers.New Features:
SayedCogas a new onboarding cog./countdownslash command that accepts a 1–30 second input and updates the response each second until completion.