Root cause: Field naming mismatch between bot model and database schema. The database stores channel IDs in columns named 'result_channel' and 'ping_channel', but the bot's DraftData model incorrectly used 'result_channel_id' and 'ping_channel_id'. Additionally, the draft data PATCH endpoint requires query parameters instead of JSON body (like player, game, transaction, and injury endpoints). Changes: - models/draft_data.py: Renamed fields to match database schema - result_channel_id → result_channel - ping_channel_id → ping_channel - services/draft_service.py: Added use_query_params=True to PATCH calls - views/draft_views.py: Updated embed to use correct field names - tasks/draft_monitor.py: Updated channel lookups to use correct field names - tests/test_models.py: Updated test assertions to match new field names This fixes: - Channel configuration now saves correctly via /draft-admin channels - Ping channel settings persist across bot restarts - Result channel settings persist across bot restarts - All draft data updates work properly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
"""
|
|
Draft configuration and state model
|
|
|
|
Represents the current draft settings and timer state.
|
|
"""
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from pydantic import Field, field_validator
|
|
|
|
from models.base import SBABaseModel
|
|
|
|
|
|
class DraftData(SBABaseModel):
|
|
"""Draft configuration and state model."""
|
|
|
|
currentpick: int = Field(0, description="Current pick number in progress")
|
|
timer: bool = Field(False, description="Whether draft timer is active")
|
|
pick_deadline: Optional[datetime] = Field(None, description="Deadline for current pick")
|
|
result_channel: Optional[int] = Field(None, description="Discord channel ID for draft results")
|
|
ping_channel: Optional[int] = Field(None, description="Discord channel ID for draft pings")
|
|
pick_minutes: int = Field(1, description="Minutes allowed per pick")
|
|
|
|
@field_validator("result_channel", "ping_channel", mode="before")
|
|
@classmethod
|
|
def cast_channel_ids_to_int(cls, v):
|
|
"""Ensure channel IDs are integers (database stores as string)."""
|
|
if v is None:
|
|
return None
|
|
if isinstance(v, str):
|
|
return int(v)
|
|
return v
|
|
|
|
@property
|
|
def is_draft_active(self) -> bool:
|
|
"""Check if the draft is currently active."""
|
|
return self.timer
|
|
|
|
@property
|
|
def is_pick_expired(self) -> bool:
|
|
"""Check if the current pick deadline has passed."""
|
|
if not self.pick_deadline:
|
|
return False
|
|
return datetime.now() > self.pick_deadline
|
|
|
|
def __str__(self):
|
|
status = "Active" if self.is_draft_active else "Inactive"
|
|
return f"Draft {status}: Pick {self.currentpick} ({self.pick_minutes}min timer)" |