feat: bsky show parent post status

This commit is contained in:
xtaodada 2024-10-21 15:08:05 +08:00
parent b1db99beff
commit e8e6b08372
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 17 additions and 8 deletions

View File

@ -75,18 +75,15 @@ class Timeline:
@staticmethod
def get_post_text(post: HumanPost) -> str:
text = "<b>Bsky Post Info</b>\n\n<code>"
key = "发表"
if post.is_reply:
key = "回复"
elif post.is_quote:
key = "引用"
if post.parent_post:
text += f"> {post.parent_post.content}\n\n=====================\n\n"
text += post.content
text += "\n\n"
text += f"{post.author.format} {key}{post.time_str}\n"
if (post.is_reply or post.is_quote) and post.parent_post:
text += f"{post.parent_post.author.format} {post.parent_post.status}{post.parent_post.time_str}\n"
text += f"{post.author.format} {post.status}{post.time_str}\n"
if post.is_repost:
text += f"{post.repost_info.by.format} 转发于 {post.repost_info.time_str}\n"
text += f"{post.repost_info.by.format} {post.status}{post.repost_info.time_str}\n"
text += f"点赞: {post.like_count} | 引用: {post.quote_count} | 回复: {post.reply_count} | 转发: {post.repost_count}"
return text

View File

@ -125,6 +125,16 @@ class HumanPost(BaseModel, frozen=False):
# utc+8
return self.created_at.astimezone(TZ).strftime("%Y-%m-%d %H:%M:%S")
@property
def status(self) -> str:
if self.is_quote:
return "引用"
elif self.is_reply:
return "回复"
elif self.is_repost:
return "转发"
return "发表"
@staticmethod
def parse_view(post: Union["PostView", "BskyViewRecordRecord"]) -> "HumanPost":
record = post.value if isinstance(post, BskyViewRecordRecord) else post.record
@ -181,7 +191,9 @@ class HumanPost(BaseModel, frozen=False):
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)
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):