major-domo-v2/commands/players
Cal Corum 2926664d2d CLAUDE: Remove constants.py and migrate to config-based constants
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>
2025-10-16 10:52:05 -05:00
..
__init__.py CLAUDE: Initial commit for discord-app-v2 rebuild 2025-08-15 00:04:50 -05:00
info.py CLAUDE: Remove constants.py and migrate to config-based constants 2025-10-16 10:52:05 -05:00
README.md Transactions cog in place 2025-09-24 09:32:04 -05:00

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 for
    • season (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

  • 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

  1. Search by exact name in specified season
  2. If no results, try fuzzy search across all players
  3. If single result, display player card
  4. If multiple results, attempt exact name match
  5. 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

  1. Player not found:

    • Check player name spelling
    • Verify player exists in the specified season
    • Use fuzzy search suggestions
  2. 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
  3. Images not displaying:

    • Check player image URLs in database
    • Verify team thumbnail URLs
    • Ensure image hosting is accessible
  4. Performance issues:

    • Monitor concurrent API call efficiency
    • Check database query performance
    • Verify embed size limits

Dependencies

  • services.player_service
  • services.stats_service
  • utils.decorators.logged_command
  • views.embeds.EmbedTemplate
  • constants.SBA_CURRENT_SEASON
  • exceptions.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