Major fixes and improvements: Trade System Fixes: - Fix duplicate player moves in trade embed Player Exchanges section - Resolve "WVMiL not participating" error for Minor League destinations - Implement organizational authority model for ML/MiL/IL team relationships - Update Trade.cross_team_moves to deduplicate using moves_giving only Team Model Enhancements: - Rewrite roster_type() method using sname as definitive source per spec - Fix edge cases like "BHMIL" (Birmingham IL) vs "BHMMIL" - Update _get_base_abbrev() to use consistent sname-based logic - Add organizational lookup support in trade participation Autocomplete System: - Fix major_league_team_autocomplete invalid roster_type parameter - Implement client-side filtering using Team.roster_type() method - Add comprehensive test coverage for all autocomplete functions - Centralize autocomplete logic to shared utils functions Test Infrastructure: - Add 25 new tests for trade models and trade builder - Add 13 autocomplete function tests with error handling - Fix existing test failures with proper mocking patterns - Update dropadd tests to use shared autocomplete functions Documentation Updates: - Document trade model enhancements and deduplication fix - Add autocomplete function documentation with usage examples - Document organizational authority model and edge case handling - Update README files with recent fixes and implementation notes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
8.5 KiB
8.5 KiB
Transaction Commands
This directory contains Discord slash commands for transaction management and roster legality checking.
Files
management.py
- Commands:
/mymoves- View user's pending and scheduled transactions/legal- Check roster legality for current and next week
- Service Dependencies:
transaction_service(multiple methods for transaction retrieval)roster_service(roster validation and retrieval)team_service.get_teams_by_owner()andget_team_by_abbrev()
dropadd.py
- Commands:
/dropadd- Interactive transaction builder for single-team roster moves/cleartransaction- Clear current transaction builder
- Service Dependencies:
transaction_builder(transaction creation and validation)player_service.search_players()(player autocomplete)team_service.get_teams_by_owner()
trade.py (NEW)
- Commands:
/trade initiate- Start a new multi-team trade/trade add-team- Add additional teams to trade (3+ team trades)/trade add-player- Add player exchanges between teams/trade supplementary- Add internal organizational moves for roster legality/trade view- View current trade status/trade clear- Clear current trade
- Service Dependencies:
trade_builder(multi-team trade management)player_service.search_players()(player autocomplete)team_service.get_teams_by_owner()andget_team_by_abbrev()
Key Features
Transaction Status Display (/mymoves)
- User Team Detection: Automatically finds user's team by Discord ID
- Transaction Categories:
- Pending: Transactions awaiting processing
- Frozen: Scheduled transactions ready for processing
- Processed: Recently completed transactions
- Cancelled: Optional display of cancelled transactions
- Status Visualization:
- Status emojis for each transaction type
- Week numbering and move descriptions
- Transaction count summaries
- Smart Limiting: Shows recent transactions (last 5 pending, 3 frozen/processed, 2 cancelled)
Roster Legality Checking (/legal)
- Dual Roster Validation: Checks both current and next week rosters
- Flexible Team Selection:
- Auto-detects user's team
- Allows manual team specification via abbreviation
- Comprehensive Validation:
- Player count verification (active roster + IL)
- sWAR calculations and limits
- League rule compliance checking
- Error and warning categorization
- Parallel Processing: Roster retrieval and validation run concurrently
Multi-Team Trade System (/trade) (NEW)
- Trade Initiation: Start trades between multiple teams using proper Discord command groups
- Team Management: Add/remove teams to create complex multi-team trades (2+ teams supported)
- Player Exchanges: Add cross-team player movements with source and destination validation
- Supplementary Moves: Add internal organizational moves for roster legality compliance
- Interactive UI: Rich Discord embeds with validation feedback and trade status
- Real-time Validation: Live roster checking across all participating teams
- Authority Model: Major League team owners control all players in their organization (ML/MiL/IL)
Trade Command Workflow:
/trade initiate other_team:LAA- Start trade between your team and LAA/trade add-team other_team:BOS- Add BOS for 3-team trade/trade add-player player_name:"Mike Trout" destination_team:BOS- Exchange players/trade supplementary player_name:"Player X" destination:ml- Internal roster moves/trade view- Review complete trade with validation- Submit via interactive UI - Trade submission through Discord buttons
Autocomplete System:
- Team Initiation: Only Major League teams (ML team owners initiate trades)
- Player Destinations: All roster types (ML/MiL/IL) available for player placement
- Player Search: Prioritizes user's team players, supports fuzzy name matching
- Smart Filtering: Context-aware suggestions based on user permissions
Advanced Transaction Features
- Concurrent Data Fetching: Multiple transaction types retrieved in parallel
- Owner-Based Filtering: Transactions filtered by team ownership
- Status Tracking: Real-time transaction status with emoji indicators
- Team Integration: Team logos and colors in transaction displays
Architecture Notes
Permission Model
- Team Ownership: Commands use Discord user ID to determine team ownership
- Cross-Team Viewing:
/legalallows checking other teams' roster status - Access Control: Users can only view their own transactions via
/mymoves
Data Processing
- Async Operations: Heavy use of
asyncio.gather()for performance - Error Resilience: Graceful handling of missing roster data
- Validation Pipeline: Multi-step roster validation with detailed feedback
Embed Structure
- Status-Based Coloring: Success (green) vs Error (red) color coding
- Information Hierarchy: Important information prioritized in embed layout
- Team Branding: Consistent use of team thumbnails and colors
Troubleshooting
Common Issues
-
User team not found:
- Verify user has team ownership record in database
- Check Discord user ID mapping to team ownership
- Ensure current season team assignments are correct
-
Transaction data missing:
- Verify
transaction_serviceAPI endpoints are functional - Check transaction status filtering logic
- Ensure transaction records exist for the team/season
- Verify
-
Roster validation failing:
- Check
roster_service.get_current_roster()andget_next_roster()responses - Verify roster validation rules and logic
- Ensure player data integrity in roster records
- Check
-
Legal command errors:
- Verify team abbreviation exists in database
- Check roster data availability for both current and next weeks
- Ensure validation service handles edge cases properly
Service Dependencies
services.transaction_service:get_pending_transactions()get_frozen_transactions()get_processed_transactions()get_team_transactions()
services.roster_service:get_current_roster()get_next_roster()validate_roster()
services.team_service:get_teams_by_owner()get_team_by_abbrev()get_teams_by_season()(trade autocomplete)
services.trade_builder(NEW):TradeBuilderclass for multi-team transaction managementget_trade_builder()andclear_trade_builder()cache functionsTradeValidationResultfor comprehensive trade validation
services.player_service:search_players()for autocomplete functionality
Core Dependencies
utils.decorators.logged_commandviews.embeds.EmbedTemplateviews.trade_embed(NEW): Trade-specific UI componentsutils.autocomplete(ENHANCED): Player and team autocomplete functionsutils.team_utils(NEW): Shared team validation utilitiesconstants.SBA_CURRENT_SEASON
Testing
Run tests with:
python -m pytest tests/test_commands_transactions.py -v(management commands)python -m pytest tests/test_models_trade.py -v(NEW) (trade models)python -m pytest tests/test_services_trade_builder.py -v(NEW) (trade builder service)
Database Requirements
- Team ownership mapping (Discord user ID to team)
- Transaction records with status tracking
- Roster data for current and next weeks
- Player assignments and position information
- League rules and validation criteria
Recent Enhancements (NEW)
- ✅ Multi-Team Trade System: Complete
/tradecommand group for 2+ team trades - ✅ Enhanced Autocomplete: Major League team filtering and smart player suggestions
- ✅ Shared Utilities: Reusable team validation and autocomplete functions
- ✅ Comprehensive Testing: Factory-based tests for trade models and services
- ✅ Interactive Trade UI: Rich Discord embeds with real-time validation
Future Enhancements
- Trade Submission Integration: Connect trade system to transaction processing pipeline
- **Advanced transaction analytics and history
- Trade Approval Workflow: Multi-party trade approval system
- **Roster optimization suggestions
- **Automated roster validation alerts
- Trade History Tracking: Complete audit trail for multi-team trades
Security Considerations
- User authentication via Discord IDs
- Team ownership verification for sensitive operations
- Transaction privacy (users can only see their own transactions)
- Input validation for team abbreviations and parameters