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 | ||
Player Commands
This directory contains Discord slash commands for player information and statistics.
Files
info.py
- Command:
/player - Description: Display comprehensive player information and statistics
- Parameters:
name(required): Player name to search forseason(optional): Season for statistics (defaults to current season)
- Service Dependencies:
player_service.get_players_by_name()player_service.search_players_fuzzy()player_service.get_player()stats_service.get_player_stats()
Key Features
Player Search
- Exact Name Matching: Primary search method using player name
- Fuzzy Search Fallback: If no exact match, suggests similar player names
- Multiple Player Handling: When multiple players match, attempts exact match or asks user to be more specific
- Suggestion System: Shows up to 10 suggested players with positions when no exact match found
Player Information Display
- Basic Info: Name, position(s), team, season
- Statistics Integration:
- Batting stats (AVG/OBP/SLG, OPS, wOBA, HR, RBI, runs, etc.)
- Pitching stats (W-L record, ERA, WHIP, strikeouts, saves, etc.)
- Two-way player detection and display
- Visual Elements:
- Team logo as author icon
- Player card image as main image
- Thumbnail priority: fancy card → headshot → team logo
- Team color theming for embed
Advanced Features
- Concurrent Data Fetching: Player data and statistics retrieved in parallel for performance
- sWAR Display: Shows Strat-o-Matic WAR value
- Multi-Position Support: Displays all eligible positions
- Rich Error Handling: Graceful fallbacks when data is unavailable
Architecture Notes
Search Logic Flow
- Search by exact name in specified season
- If no results, try fuzzy search across all players
- If single result, display player card
- If multiple results, attempt exact name match
- If still multiple, show disambiguation list
Performance Optimizations
asyncio.gather()for concurrent API calls- Efficient player data and statistics retrieval
- Lazy loading of optional player images
Error Handling
- No players found: Suggests fuzzy matches
- Multiple matches: Provides clarification options
- Missing data: Shows partial information with clear indicators
- API failures: Graceful degradation with fallback data
Troubleshooting
Common Issues
-
Player not found:
- Check player name spelling
- Verify player exists in the specified season
- Use fuzzy search suggestions
-
Statistics not loading:
- Verify
stats_service.get_player_stats()API endpoint - Check if player has statistics for the requested season
- Ensure season parameter is valid
- Verify
-
Images not displaying:
- Check player image URLs in database
- Verify team thumbnail URLs
- Ensure image hosting is accessible
-
Performance issues:
- Monitor concurrent API call efficiency
- Check database query performance
- Verify embed size limits
Dependencies
services.player_serviceservices.stats_serviceutils.decorators.logged_commandviews.embeds.EmbedTemplateconstants.SBA_CURRENT_SEASONexceptions.BotException
Testing
Run tests with: python -m pytest tests/test_commands_players.py -v
Database Requirements
- Player records with name, positions, team associations
- Statistics tables for batting and pitching
- Image URLs for player cards, headshots, and fancy cards
- Team logo and color information