52 lines
1.9 KiB
Python
Executable File
52 lines
1.9 KiB
Python
Executable File
"""
|
|
Message data model for forum thread structure (2ch.life).
|
|
|
|
This module defines the Message entity for forum data.
|
|
"""
|
|
|
|
from dataclasses import dataclass, field
|
|
from datetime import datetime
|
|
from typing import List, Optional
|
|
|
|
from .Image import Image
|
|
|
|
|
|
@dataclass
|
|
class Message:
|
|
"""
|
|
Represents a forum message/post.
|
|
|
|
Attributes:
|
|
id: Unique identifier for the message (data-num)
|
|
author: Username of the message author (always "Аноним")
|
|
content: Body content of the message (HTML format)
|
|
text_content: Plain text content of the message
|
|
timestamp: When the message was posted
|
|
images: List of attached images (optional)
|
|
reply_links: List of message IDs this message replies to (optional)
|
|
ref_links: List of message IDs referenced in this message (optional)
|
|
"""
|
|
ref_id: int
|
|
id: str
|
|
author: str
|
|
content: str
|
|
text_content: str
|
|
timestamp: datetime
|
|
images: List[Image] = field(default_factory=list)
|
|
reply_links: List[str] = field(default_factory=list)
|
|
ref_links: List[str] = field(default_factory=list)
|
|
|
|
def __post_init__(self):
|
|
"""Validate message data after initialization."""
|
|
if not self.id or not isinstance(self.id, str):
|
|
raise ValueError("Message ID must be a non-empty string")
|
|
if not self.author or not isinstance(self.author, str):
|
|
raise ValueError("Message author must be a non-empty string")
|
|
if not isinstance(self.timestamp, datetime):
|
|
raise ValueError("Message timestamp must be a datetime object")
|
|
if not isinstance(self.images, list):
|
|
raise ValueError("Images must be a list")
|
|
if not isinstance(self.reply_links, list):
|
|
raise ValueError("Reply_links must be a list")
|
|
if not isinstance(self.ref_links, list):
|
|
raise ValueError("Ref_links must be a list") |