major-domo-v2/utils/helpers.py
Cal Corum 483f1f492f Fix draft pick API parsing and enhance admin command feedback
Root Cause Fixes:
- Add _extract_items_and_count_from_response() override to DraftPickService
  to handle API returning 'picks' key instead of 'draftpicks'
- Add custom from_api_data() to DraftPick model to handle API field mapping
  (origowner/owner/player -> origowner_id/owner_id/player_id)

Enhancements:
- Add timer status to /draft-admin set-pick success message
  - Shows relative deadline timestamp when timer active
  - Shows "Timer Inactive" when timer not running

Also includes related draft module improvements from prior work.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-10 15:33:52 -06:00

60 lines
1.8 KiB
Python

"""
Helper functions for Discord Bot v2.0
Contains utility functions for salary cap calculations and other common operations.
"""
from typing import Union
from config import get_config
# Get default values from config
_config = get_config()
# Salary cap constants - default from config, tolerance for float comparisons
DEFAULT_SALARY_CAP = _config.swar_cap_limit # 32.0
SALARY_CAP_TOLERANCE = 0.001 # Small tolerance for floating point comparisons
def get_team_salary_cap(team) -> float:
"""
Get the salary cap for a team, falling back to the default if not set.
Args:
team: Team data - can be a dict or Pydantic model with 'salary_cap' attribute.
Returns:
float: The team's salary cap, or DEFAULT_SALARY_CAP (32.0) if not set.
Why: Teams may have custom salary caps (e.g., for expansion teams or penalties).
This centralizes the fallback logic so all cap checks use the same source of truth.
"""
if team is None:
return DEFAULT_SALARY_CAP
# Handle both dict and Pydantic model (or any object with salary_cap attribute)
if isinstance(team, dict):
salary_cap = team.get('salary_cap')
else:
salary_cap = getattr(team, 'salary_cap', None)
if salary_cap is not None:
return salary_cap
return DEFAULT_SALARY_CAP
def exceeds_salary_cap(wara: float, team) -> bool:
"""
Check if a WAR total exceeds the team's salary cap.
Args:
wara: The total WAR value to check
team: Team data - can be a dict or Pydantic model
Returns:
bool: True if wara exceeds the team's salary cap (with tolerance)
Why: Centralizes the salary cap comparison logic with proper floating point
tolerance handling. All cap validation should use this function.
"""
cap = get_team_salary_cap(team)
return wara > (cap + SALARY_CAP_TOLERANCE)