-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
163ccae
commit c18b2ae
Showing
6 changed files
with
91 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
from datetime import datetime | ||
from typing import Literal | ||
|
||
from pydantic import BaseModel | ||
from pydantic import BaseModel, field_validator | ||
|
||
|
||
class Game(BaseModel): | ||
playroom_id: int | ||
end_time: datetime | ||
result: Literal["Hitler Canceler", "Fascist Law", "Hitler Death", "Liberal Law"] | ||
poll_id: int | ||
chat_id: int | ||
results: dict # Literal["Hitler Canceler", "Fascist Law", "Hitler Death", "Liberal Law"] | ||
creator_id: int | ||
|
||
@field_validator("results", mode="after") | ||
@classmethod | ||
def validate_results(cls, v: dict) -> Literal["CH", "DH", "FW", "LW"]: | ||
outcomes = set(v.values()) | ||
if "I'm Canceler Hitler" in outcomes: | ||
return "CH" | ||
if "I'm Dead Hitler" in outcomes: | ||
return "DH" | ||
if "I'm Liberal Winner" in outcomes: | ||
return "LW" | ||
if "I'm Fascistic Winner" in outcomes: | ||
return "FW" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
from pydantic import BaseModel, field_validator | ||
|
||
|
||
class Player(BaseModel): | ||
telegram_user_id: int | ||
username: str | ||
first_name: Optional[str] = None | ||
last_name: Optional[str] = None | ||
is_bot: bool = False | ||
first_name: Optional[str | None] | ||
full_name: Optional[str | None] | ||
last_name: Optional[str | None] | ||
is_bot: Optional[bool] = False | ||
language_code: Optional[str | None] | ||
|
||
@field_validator("is_bot", mode="after") | ||
@classmethod | ||
def validate_bot(cls, v: bool) -> str: | ||
return "TRUE" if v else "FALSE" # sqlite3 does not support boolean type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters