major-domo-v2/utils/team_utils.py
Cal Corum 3aa95ef98c CLAUDE: Refine injury roll display and cleanup imports
## Injury Command Enhancements

### Pitcher-Specific Injury Display
- Added rest requirement note for pitcher injuries with game duration
- Shows "X games plus their current rest requirement" for pitchers
- Removed redundant footer text from FATIGUED result
- Cleaner, more concise pitcher injury messaging

### Bot Configuration
- Registered injuries command package in bot.py
- Added proper import and setup for InjuryGroup

### Code Cleanup
- Fixed misplaced import in views/embeds.py (moved to top)
- Standardized import ordering across command files
- Minor formatting improvements

## Files Changed
- commands/injuries/management.py: Pitcher rest requirement display
- bot.py: Injuries package registration
- views/embeds.py: Import cleanup
- Various: Import standardization

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-16 22:20:13 -05:00

109 lines
3.0 KiB
Python

"""
Team Utilities
Common team-related helper functions used across commands.
"""
from typing import Optional
import discord
from models.team import Team
from services.team_service import team_service
from config import get_config
async def get_user_major_league_team(
user_id: int,
season: int = get_config().sba_current_season
) -> Optional[Team]:
"""
Get the major league team owned by a Discord user.
This is a very common pattern used across many commands, so it's
extracted into a utility function for consistency and reusability.
Args:
user_id: Discord user ID
season: Season to check (defaults to current season)
Returns:
Team object if user owns a major league team, None otherwise
"""
try:
major_league_teams = await team_service.get_teams_by_owner(
user_id,
season,
roster_type="ml"
)
if major_league_teams:
return major_league_teams[0] # Return first ML team
return None
except Exception:
# Silently fail and return None - let calling code handle the error
return None
async def validate_user_has_team(
interaction: discord.Interaction,
season: int = get_config().sba_current_season
) -> Optional[Team]:
"""
Validate that a user has a major league team and send error message if not.
This combines team lookup with standard error messaging for consistency.
Args:
interaction: Discord interaction object
season: Season to check (defaults to current season)
Returns:
Team object if user has a team, None if not (error message already sent)
"""
user_team = await get_user_major_league_team(interaction.user.id, season)
if not user_team:
await interaction.followup.send(
"❌ You don't appear to own a major league team in the current season.",
ephemeral=True
)
return None
return user_team
async def get_team_by_abbrev_with_validation(
team_abbrev: str,
interaction: discord.Interaction,
season: int = get_config().sba_current_season
) -> Optional[Team]:
"""
Get a team by abbreviation with standard error messaging.
Args:
team_abbrev: Team abbreviation to look up
interaction: Discord interaction object for error messaging
season: Season to check (defaults to current season)
Returns:
Team object if found, None if not (error message already sent)
"""
try:
team = await team_service.get_team_by_abbrev(team_abbrev, season)
if not team:
await interaction.followup.send(
f"❌ Team '{team_abbrev}' not found.",
ephemeral=True
)
return None
return team
except Exception:
await interaction.followup.send(
f"❌ Error looking up team '{team_abbrev}'. Please try again.",
ephemeral=True
)
return None