35 lines
974 B
Python
35 lines
974 B
Python
import datetime
|
|
import logging
|
|
from typing import Optional
|
|
import pydantic
|
|
|
|
from pydantic import field_validator
|
|
from db_calls import db_get
|
|
from exceptions import log_exception, ApiException
|
|
|
|
logger = logging.getLogger('discord_app')
|
|
|
|
class DraftData(pydantic.BaseModel):
|
|
id: int = 0
|
|
currentpick: int = 0
|
|
timer: bool = False
|
|
pick_deadline: Optional[datetime.datetime] = None
|
|
result_channel: str = 'unknown'
|
|
ping_channel: str = 'unknown'
|
|
pick_minutes: int = 1
|
|
|
|
@field_validator("result_channel", "ping_channel", mode="before")
|
|
@classmethod
|
|
def cast_to_string(cls, v):
|
|
if isinstance(v, str):
|
|
return v
|
|
return str(v)
|
|
|
|
|
|
async def get_draft_data() -> DraftData:
|
|
data = await db_get('draftdata')
|
|
if data is None:
|
|
log_exception(ApiException('Did not receive current metadata from the API'))
|
|
return_val = DraftData(**data)
|
|
logger.info(f'this draft_data: {return_val}')
|
|
return return_val |