Adding 17 CLAUDE.md files across the project to provide detailed context and implementation guidelines for AI development agents: Root Documentation: - CLAUDE.md - Main project guide with Git workflow requirements Component Documentation: - commands/CLAUDE.md - Command architecture and patterns - models/CLAUDE.md - Pydantic models and validation - services/CLAUDE.md - Service layer and API interactions - tasks/CLAUDE.md - Background tasks and automation - tests/CLAUDE.md - Testing strategies and patterns - utils/CLAUDE.md - Utility functions and decorators - views/CLAUDE.md - Discord UI components and embeds Command Package Documentation: - commands/help/CLAUDE.md - Help system implementation - commands/injuries/CLAUDE.md - Injury management commands - commands/league/CLAUDE.md - League-wide commands - commands/players/CLAUDE.md - Player information commands - commands/profile/CLAUDE.md - User profile commands - commands/teams/CLAUDE.md - Team information commands - commands/transactions/CLAUDE.md - Transaction management - commands/utilities/CLAUDE.md - Utility commands - commands/voice/CLAUDE.md - Voice channel management Key Updates: - Updated .gitignore to track CLAUDE.md files in version control - Added Git Workflow section requiring branch-based development - Documented all architectural patterns and best practices - Included comprehensive command/service implementation guides These files provide essential context for AI agents working on the codebase, ensuring consistent patterns, proper error handling, and maintainable code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
6.0 KiB
6.0 KiB
League Commands
This directory contains Discord slash commands related to league-wide information and statistics.
Files
info.py
- Command:
/league - Description: Display current league status and information
- Functionality: Shows current season/week, phase (regular season/playoffs/offseason), transaction status, trade deadlines, and league configuration
- Service Dependencies:
league_service.get_current_state() - Key Features:
- Dynamic phase detection (offseason, playoffs, regular season)
- Transaction freeze status
- Trade deadline and playoff schedule information
- Draft pick trading status
standings.py
- Commands:
/standings- Display league standings by division/playoff-picture- Show current playoff picture and wild card race
- Parameters:
season: Optional season number (defaults to current)division: Optional division filter for standings
- Service Dependencies:
standings_service - Key Features:
- Division-based standings display
- Games behind calculations
- Recent form statistics (home record, last 8 games, current streak)
- Playoff cutoff visualization
- Wild card race tracking
schedule.py
- Commands:
/schedule- Display game schedules/results- Show recent game results
- Parameters:
season: Optional season number (defaults to current)week: Optional specific week filterteam: Optional team abbreviation filter
- Service Dependencies:
schedule_service - Key Features:
- Weekly schedule views
- Team-specific schedule filtering
- Series grouping and summary
- Recent/upcoming game overview
- Game completion tracking
submit_scorecard.py
- Command:
/submit-scorecard - Description: Submit Google Sheets scorecards with game results and play-by-play data
- Parameters:
sheet_url: Full URL to the Google Sheets scorecard
- Required Role:
Season 12 Players - Service Dependencies:
SheetsService- Google Sheets data extractiongame_service- Game CRUD operationsplay_service- Play-by-play data managementdecision_service- Pitching decision managementstandings_service- Standings recalculationleague_service- Current state retrievalteam_service- Team lookupplayer_service- Player lookup for results display
- Key Features:
- Scorecard Validation: Checks sheet access and version compatibility
- Permission Control: Only GMs of playing teams can submit
- Duplicate Detection: Identifies already-played games with confirmation dialog
- Transaction Rollback: Full rollback support at 3 states:
PLAYS_POSTED: Deletes plays on errorGAME_PATCHED: Wipes game and deletes plays on errorCOMPLETE: All data committed successfully
- Data Extraction: Reads 68 fields from Playtable, 14 fields from Pitcherstats, box score, and game metadata
- Results Display: Rich embed with box score, pitching decisions, and top 3 key plays by WPA
- Automated Standings: Triggers standings recalculation after successful submission
- News Channel Posting: Automatically posts results to configured channel
Workflow (14 Phases):
- Validate scorecard access and version
- Extract game metadata from Setup tab
- Lookup teams and match managers
- Check user permissions (must be GM of one team or bot owner)
- Check for duplicate games (with confirmation if found)
- Find scheduled game in database
- Read play-by-play data (up to 297 plays)
- Submit plays to database
- Read box score
- Update game with scores and managers
- Read pitching decisions (up to 27 pitchers)
- Submit decisions to database
- Create and post results embed to news channel
- Recalculate league standings
Error Handling:
- User-friendly error messages for common issues
- Graceful rollback on validation errors
- API error parsing for actionable feedback
- Non-critical errors (key plays, standings) don't fail submission
Configuration:
sheets_credentials_path(in config.py): Path to Google service account credentials JSON (set viaSHEETS_CREDENTIALS_PATHenv var)SBA_NETWORK_NEWS_CHANNEL: Channel name for results postingSBA_PLAYERS_ROLE_NAME: Role required to submit scorecards
Architecture Notes
Decorator Usage
All commands use the @logged_command decorator pattern:
- Eliminates boilerplate logging code
- Provides consistent error handling
- Automatic request tracing and timing
Error Handling
- Graceful fallbacks for missing data
- User-friendly error messages
- Ephemeral responses for errors
Embed Structure
- Uses
EmbedTemplatefor consistent styling - Color coding based on context (success/error/info)
- Rich formatting with team logos and thumbnails
Troubleshooting
Common Issues
- No league data available: Check
league_service.get_current_state()API endpoint - Standings not loading: Verify
standings_service.get_standings_by_division()returns valid data - Schedule commands failing: Ensure
schedule_servicemethods are properly handling season/week parameters
Dependencies
services.league_serviceservices.standings_serviceservices.schedule_serviceservices.sheets_service(NEW) - Google Sheets integrationservices.game_service(NEW) - Game managementservices.play_service(NEW) - Play-by-play dataservices.decision_service(NEW) - Pitching decisionsservices.team_serviceservices.player_serviceutils.decorators.logged_commandutils.discord_helpers(NEW) - Channel and message utilitiesutils.team_utilsviews.embeds.EmbedTemplateviews.confirmations.ConfirmationView(NEW) - Reusable confirmation dialogconstants.SBA_CURRENT_SEASONconfig.BotConfig.sheets_credentials_path(NEW) - Google Sheets credentials pathconstants.SBA_NETWORK_NEWS_CHANNEL(NEW)constants.SBA_PLAYERS_ROLE_NAME(NEW)
Testing
Run tests with: python -m pytest tests/test_commands_league.py -v