選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

message.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from datetime import datetime
  2. from typing import Any, List
  3. from uuid import uuid4
  4. from pydantic import BaseModel, PrivateAttr, computed_field
  5. class Reaction(BaseModel):
  6. reaction: str
  7. actor: str
  8. class AudioFile(BaseModel):
  9. uri: str
  10. creation_timestamp: int
  11. class Video(BaseModel):
  12. uri: str
  13. creation_timestamp: int
  14. class Photo(BaseModel):
  15. uri: str
  16. creation_timestamp: int
  17. class Gif(BaseModel):
  18. uri: str
  19. class Share(BaseModel):
  20. link: str
  21. share_text: str
  22. class Sticker(BaseModel):
  23. uri: str
  24. ai_stickers: List[Any]
  25. class Message(BaseModel):
  26. sender_name: str
  27. timestamp_ms: int
  28. content: str | None = None
  29. sticker: Sticker | None = None
  30. share: Share | None = None
  31. photos: List[Photo] | None = None
  32. videos: List[Video] | None = None
  33. gifs: List[Gif] | None = None
  34. audio_files: List[AudioFile] | None = None
  35. call_duration: int | None = None
  36. reactions: List[Reaction] | None = None
  37. is_unsent: bool | None = None
  38. is_geoblocked_for_viewer: bool
  39. _id: str = PrivateAttr(default_factory=lambda: str(uuid4()))
  40. def __str__(self) -> str:
  41. dt = datetime.fromtimestamp(self.timestamp_ms / 1000)
  42. dt_str = dt.strftime("%d/%m/%Y, %H:%M:%S")
  43. return f"{self.sender_name}({dt_str}) : {self.content}"
  44. def __hash__(self) -> int:
  45. return hash(self.item_id)
  46. @computed_field
  47. @property
  48. def item_id(self) -> str:
  49. return self._id