-
Notifications
You must be signed in to change notification settings - Fork 1
✨ feat: Add new slash commands for problem lookup and historical daily challenges #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…y challenges ## New Features ### 1. Problem Lookup Command - Add `/problem` slash command to query LeetCode problems by ID - Support both leetcode.com and leetcode.cn domains - Input validation for problem ID (positive integers) - Auto-complete support for domain selection - Consistent UI with existing daily challenge display ### 2. Enhanced Daily Commands - Extend `/daily` and `/daily_cn` with optional date parameter - Support historical daily challenge lookup (YYYY-MM-DD format) - Date format validation and error handling - Fallback to current day when no date specified ### 3. Code Refactoring - Extract common embed creation logic into `create_problem_embed()` - Extract button view creation into `create_problem_view()` - Reduce code duplication between daily and problem commands - Unified display format across all problem-related features ### 4. Auto Command Sync - Add automatic slash command synchronization on bot startup - Ensure new commands appear in Discord servers without manual intervention ## Technical Details - Reuse existing LeetCode client and database infrastructure - Maintain backward compatibility with existing commands - Comprehensive error handling and user feedback - Follows established code patterns and conventions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
## Improvements
### Documentation
- Add comprehensive docstrings for `/daily` and `/problem` commands
- Clarify optional date parameter behavior in `/daily` commands
- Document function parameters and their expected types
### Code Quality
- Remove redundant `import re` from method scope (already imported at module level)
- Add upper bound validation for problem IDs (1-4000 range)
- Improve input validation with clearer error messages
### Date Handling
- Pass explicit `date_str` parameter to `create_problem_embed()`
- Avoid relying on `problem_info.get('date', 'Today')` for historical lookups
- Prevent mislabeling of historical daily challenges
### Input Validation
- Add upper bound check for problem IDs
- Improve error messages for out-of-range values
- Enhance robustness of user input handling
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
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.
Pull Request Overview
Adds historical date support to daily challenge commands, introduces a new /problem lookup command, refactors embed/view creation, and enables automatic command synchronization on startup.
- Extend
/dailyand/daily_cnwith an optionaldateparameter for historical lookup. - Add
/problemcommand to fetch LeetCode problem details by ID with input validation and autocomplete. - Refactor embed/view logic into
create_problem_embedandcreate_problem_view; auto-sync slash commands inon_ready.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cogs/slash_commands_cog.py | Add date validation, historical daily lookup logic, and new /problem. |
| cogs/schedule_manager_cog.py | Extract embed/view functions and update send_daily_challenge. |
| bot.py | Implement on_ready to initialize schedules and auto-sync commands. |
Comments suppressed due to low confidence (4)
cogs/slash_commands_cog.py:124
- The upper bound of 4000 conflicts with the description mentioning "1-3500+"; clarify the supported ID range to avoid user confusion.
if problem_id > 4000: # Add upper bound validation
cogs/slash_commands_cog.py:105
- There are no tests covering the new
/problemcommand. Consider adding unit or integration tests for valid, invalid, and edge-case inputs.
@app_commands.command(name="problem", description="根據題號查詢 LeetCode 題目資訊")
cogs/schedule_manager_cog.py:163
- The docstring for
create_problem_embeddoesn't describe theis_dailyanddate_strparameters; update it to document all arguments.
async def create_problem_embed(self, problem_info: dict, domain: str = "com", is_daily: bool = False, date_str: str = None):
bot.py:252
- [nitpick] The comment suggests syncing commands is optional, but the code always calls
bot.tree.sync(). Update the comment or add a guard to reflect actual behavior.
# Auto-sync commands on startup (optional, comment out if not needed)
|
|
||
| if date: | ||
| # Validate date format | ||
| if not re.match(r'^\d{4}-\d{2}-\d{2}$', date): |
Copilot
AI
Jul 4, 2025
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.
[nitpick] Consider extracting the date validation regex into a shared constant or helper function to avoid duplication and improve maintainability.
| if not re.match(r'^\d{4}-\d{2}-\d{2}$', date): | |
| if not re.match(DATE_REGEX, date): |
| if date: | ||
| # Validate date format | ||
| if not re.match(r'^\d{4}-\d{2}-\d{2}$', date): | ||
| await interaction.followup.send("日期格式錯誤,請使用 YYYY-MM-DD 格式(例如:2024-01-15)", ephemeral=True) | ||
| return |
Copilot
AI
Jul 4, 2025
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.
[nitpick] The same regex appears in both /daily and /daily_cn; extract it into a common validator to DRY up the code.
| if date: | |
| # Validate date format | |
| if not re.match(r'^\d{4}-\d{2}-\d{2}$', date): | |
| await interaction.followup.send("日期格式錯誤,請使用 YYYY-MM-DD 格式(例如:2024-01-15)", ephemeral=True) | |
| return | |
| if date: | |
| # Validate date format | |
| if not self.validate_date_format(date): | |
| await interaction.followup.send("日期格式錯誤,請使用 YYYY-MM-DD 格式(例如:2024-01-15)", ephemeral=True) | |
| return |
Summary
/problemcommand for querying LeetCode problems by ID/dailyand/daily_cncommands with optional date parameter for historical lookupNew Features
/problemCommandEnhanced Daily Commands
dateparameter for/dailyand/daily_cnCode Improvements
create_problem_embed()for unified embed creationcreate_problem_view()for consistent button layoutsAuto Command Sync
Test Plan
/problemcommand with valid problem IDs/problemcommand with invalid inputs/dailywith date parameter/daily_cnwith date parameter🤖 Generated with Claude Code