Skip to content

Conversation

@cxyfer
Copy link
Owner

@cxyfer cxyfer commented Jul 4, 2025

Summary

  • Add /problem command for querying LeetCode problems by ID
  • Extend /daily and /daily_cn commands with optional date parameter for historical lookup
  • Refactor common display logic into reusable functions
  • Add automatic command synchronization on bot startup

New Features

/problem Command

  • Query LeetCode problems by problem ID (1-4000+)
  • Support both leetcode.com and leetcode.cn domains
  • Input validation and error handling
  • Auto-complete for domain selection
  • Same display format as daily challenges

Enhanced Daily Commands

  • Optional date parameter for /daily and /daily_cn
  • Support YYYY-MM-DD format for historical lookup
  • Date validation with user-friendly error messages
  • Backward compatible - no date means current day

Code Improvements

  • Extract create_problem_embed() for unified embed creation
  • Extract create_problem_view() for consistent button layouts
  • Reduce code duplication by ~200 lines
  • Maintain consistent UI/UX across all commands

Auto Command Sync

  • Automatic slash command synchronization on bot startup
  • Ensures new commands appear without manual intervention

Test Plan

  • Syntax validation passes
  • Code compiles without errors
  • Test /problem command with valid problem IDs
  • Test /problem command with invalid inputs
  • Test /daily with date parameter
  • Test /daily_cn with date parameter
  • Verify commands appear in Discord after bot restart
  • Test backward compatibility of existing commands

🤖 Generated with Claude Code

…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>
@cxyfer cxyfer requested a review from Copilot July 4, 2025 15:37
Copilot

This comment was marked as outdated.

## 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>
@cxyfer cxyfer requested a review from Copilot July 4, 2025 15:43
Copy link

Copilot AI left a 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 /daily and /daily_cn with an optional date parameter for historical lookup.
  • Add /problem command to fetch LeetCode problem details by ID with input validation and autocomplete.
  • Refactor embed/view logic into create_problem_embed and create_problem_view; auto-sync slash commands in on_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 /problem command. 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_embed doesn't describe the is_daily and date_str parameters; 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):
Copy link

Copilot AI Jul 4, 2025

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.

Suggested change
if not re.match(r'^\d{4}-\d{2}-\d{2}$', date):
if not re.match(DATE_REGEX, date):

Copilot uses AI. Check for mistakes.
Comment on lines +77 to +81
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
Copy link

Copilot AI Jul 4, 2025

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
@cxyfer cxyfer merged commit 466a6b7 into main Jul 4, 2025
@cxyfer cxyfer deleted the feat branch July 4, 2025 15:47
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.

1 participant