| Total Complexity | 3 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from dataclasses import dataclass |
||
| 2 | from typing import Any |
||
| 3 | from datetime import datetime |
||
| 4 | from models import ( |
||
| 5 | from_str, from_bool, from_datetime |
||
| 6 | ) |
||
| 7 | from models.user import User, user_from_dict |
||
| 8 | |||
| 9 | |||
| 10 | @dataclass |
||
| 11 | class ChatMessage: |
||
| 12 | id: str |
||
| 13 | user: User |
||
| 14 | bot: str |
||
| 15 | posted_at: datetime |
||
| 16 | message: str |
||
| 17 | message_plain: str |
||
| 18 | highlight: bool |
||
| 19 | is_bot: bool |
||
| 20 | is_system: bool |
||
| 21 | |||
| 22 | @staticmethod |
||
| 23 | def from_dict(obj: Any) -> 'ChatMessage': |
||
| 24 | if not isinstance(obj, dict): |
||
| 25 | return None |
||
| 26 | id = from_str(obj.get("id")) |
||
| 27 | user = user_from_dict(obj.get("user")) |
||
| 28 | bot = from_str(obj.get("bot")) |
||
| 29 | posted_at = from_datetime(obj.get("posted_at")) |
||
| 30 | message = from_str(obj.get("message")) |
||
| 31 | message_plain = from_str(obj.get("message_plain")) |
||
| 32 | highlight = from_bool(obj.get("highlight")) |
||
| 33 | is_bot = from_bool(obj.get("is_bot")) |
||
| 34 | is_system = from_bool(obj.get("is_system")) |
||
| 35 | |||
| 36 | return ChatMessage( |
||
| 37 | id=id, user=user, bot=bot, posted_at=posted_at, message=message, |
||
| 38 | message_plain=message_plain, highlight=highlight, is_bot=is_bot, |
||
| 39 | is_system=is_system) |
||
| 40 | |||
| 41 | |||
| 42 | def chat_message_from_dict(s: Any) -> ChatMessage: |
||
| 43 | return ChatMessage.from_dict(s) |
||
| 44 |