Eliminates redundant constants.py file by moving all constants to config.py.
All constants (except baseball positions) are now accessible via get_config().
Changes:
- config.py: Added baseball position sets as module-level constants
* PITCHER_POSITIONS, POSITION_FIELDERS, ALL_POSITIONS remain static
* All other constants now accessed via BotConfig instance
- constants.py: Deleted (redundant with config.py)
- Updated 27 files to use get_config() instead of constants module:
* Commands: admin, help, league (3), players, profile, teams (3),
transactions (3), utilities, voice
* Services: league, player, team, trade_builder, transaction_builder
* Utils: autocomplete, team_utils
* Views: embeds
* Tests: test_constants, test_services (3 files)
* Examples: enhanced_player, migration_example
- tests/test_constants.py: Rewritten to test config values
* All 14 tests pass
* Now validates BotConfig defaults instead of constants module
Import Changes:
- Old: `from constants import SBA_CURRENT_SEASON`
- New: `from config import get_config` → `get_config().sba_current_season`
- Positions: `from config import PITCHER_POSITIONS, ALL_POSITIONS`
Benefits:
- Single source of truth (config.py only)
- Cleaner architecture - no redundant wrapper
- All constants configurable via environment variables
- Reduced maintenance overhead
- Type safety with Pydantic validation
All configuration tests pass. Core refactoring complete.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
||
|---|---|---|
| .. | ||
| __init__.py | ||
| info.py | ||
| README.md | ||
| schedule.py | ||
| standings.py | ||
| submit_scorecard.py | ||
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