Implements full Google Sheets scorecard submission with: - Complete game data extraction (68 play fields, pitching decisions, box score) - Transaction rollback support at 3 states (plays/game/complete) - Duplicate game detection with confirmation dialog - Permission-based submission (GMs only) - Automated results posting to news channel - Automatic standings recalculation - Key plays display with WPA sorting New Components: - Play, Decision, Game models with full validation - SheetsService for Google Sheets integration - GameService, PlayService, DecisionService for data management - ConfirmationView for user confirmations - Discord helper utilities for channel operations Services Enhanced: - StandingsService: Added recalculate_standings() method - CustomCommandsService: Fixed creator endpoint path - Team/Player models: Added helper methods for display Configuration: - Added SHEETS_CREDENTIALS_PATH environment variable - Added SBA_NETWORK_NEWS_CHANNEL and role constants - Enabled pygsheets dependency Documentation: - Comprehensive README updates across all modules - Added command, service, model, and view documentation - Detailed workflow and error handling documentation 🤖 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