diff --git a/defs/bsky.py b/defs/bsky.py index a2edfb7..d9df6b5 100644 --- a/defs/bsky.py +++ b/defs/bsky.py @@ -9,7 +9,6 @@ from pyrogram.types import ( InlineKeyboardMarkup, InlineKeyboardButton, InputMediaPhoto, - Message, ) from init import bot, logs @@ -78,12 +77,16 @@ class Timeline: def get_post_text(post: HumanPost) -> str: text = "Bsky Post Info\n\n" text += post.content + text += "\n\n" key = "发表" if post.is_reply: key = "回复" elif post.is_quote: key = "引用" - text += f"\n\n{post.author.format} {key}于 {post.time_str}" + elif post.is_repost: + text += f"{post.repost_info.by.format} 转发于 {post.repost_info.time_str}\n" + text += f"{post.author.format} {key}于 {post.time_str}\n" + text += f"点赞: {post.like_count} | 引用: {post.quote_count} | 回复: {post.reply_count} | 转发: {post.repost_count}" return text @staticmethod diff --git a/models/models/bsky.py b/models/models/bsky.py index e263739..2a5be37 100644 --- a/models/models/bsky.py +++ b/models/models/bsky.py @@ -31,7 +31,7 @@ class HumanAuthor(BaseModel): display_name: str handle: str did: str - avatar_img: str + avatar_img: Optional[str] = None created_at: datetime description: Optional[str] = None @@ -59,7 +59,7 @@ class HumanAuthor(BaseModel): @staticmethod def parse(author: "ProfileViewBasic") -> "HumanAuthor": return HumanAuthor( - display_name=author.display_name, + display_name=author.display_name or author.handle, handle=author.handle, did=author.did, avatar_img=author.avatar, @@ -69,7 +69,7 @@ class HumanAuthor(BaseModel): @staticmethod def parse_detail(author: "ProfileViewDetailed") -> "HumanAuthor": return HumanAuthor( - display_name=author.display_name, + display_name=author.display_name or author.handle, handle=author.handle, did=author.did, avatar_img=author.avatar, @@ -81,6 +81,16 @@ class HumanAuthor(BaseModel): ) +class HumanRepostInfo(BaseModel): + by: HumanAuthor + at: datetime + + @property + def time_str(self) -> str: + # utc+8 + return self.at.astimezone(TZ).strftime("%Y-%m-%d %H:%M:%S") + + class HumanPost(BaseModel, frozen=False): cid: str content: str @@ -103,7 +113,8 @@ class HumanPost(BaseModel, frozen=False): is_reply: bool = False is_repost: bool = False - parent_post: "HumanPost" = None + repost_info: Optional[HumanRepostInfo] = None + parent_post: Optional["HumanPost"] = None @property def url(self) -> str: @@ -163,13 +174,14 @@ class HumanPost(BaseModel, frozen=False): def parse(data: "FeedViewPost") -> "HumanPost": base = HumanPost.parse_view(data.post) is_quote, is_reply, is_repost = False, False, False - parent_post = None + parent_post, repost_info = None, None if data.reply: is_reply = True if hasattr(data.reply.parent, "post"): parent_post = HumanPost.parse_view(data.reply.parent) elif data.reason: is_repost = True + repost_info = HumanRepostInfo(by=HumanAuthor.parse(data.reason.by), at=data.reason.at) elif data.post.embed and isinstance(data.post.embed, BskyViewRecord): is_quote = True if isinstance(data.post.embed.record, BskyViewRecordRecord): @@ -178,6 +190,7 @@ class HumanPost(BaseModel, frozen=False): base.is_reply = is_reply base.is_repost = is_repost base.parent_post = parent_post + base.repost_info = repost_info return base @staticmethod @@ -188,7 +201,7 @@ class HumanPost(BaseModel, frozen=False): if data.parent: is_reply = True if hasattr(data.parent, "post"): - parent_post = HumanPost.parse_view(data.parent.post) + parent_post = HumanPost.parse_thread(data.parent) elif data.post.embed and isinstance(data.post.embed, BskyViewRecord): is_quote = True if isinstance(data.post.embed.record, BskyViewRecordRecord):