feat: bsky show parent content

This commit is contained in:
xtaodada 2024-10-21 14:59:36 +08:00
parent 16e2a9bce5
commit b1db99beff
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -40,14 +40,13 @@ def flood_wait():
class Timeline:
@staticmethod
def get_button(post: HumanPost) -> InlineKeyboardMarkup:
return InlineKeyboardMarkup(
[
[
buttons = [
InlineKeyboardButton("Source", url=post.url),
InlineKeyboardButton("Author", url=post.author.url),
]
]
)
if post.parent_post:
buttons.insert(1, InlineKeyboardButton("RSource", url=post.parent_post.url))
return InlineKeyboardMarkup([buttons])
@staticmethod
def get_author_button(author: HumanAuthor) -> InlineKeyboardMarkup:
@ -76,16 +75,18 @@ class Timeline:
@staticmethod
def get_post_text(post: HumanPost) -> str:
text = "<b>Bsky Post Info</b>\n\n<code>"
text += post.content
text += "</code>\n\n"
key = "发表"
if post.is_reply:
key = "回复"
elif post.is_quote:
key = "引用"
elif post.is_repost:
text += f"{post.repost_info.by.format} 转发于 {post.repost_info.time_str}\n"
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_repost:
text += f"{post.repost_info.by.format} 转发于 {post.repost_info.time_str}\n"
text += f"点赞: {post.like_count} | 引用: {post.quote_count} | 回复: {post.reply_count} | 转发: {post.repost_count}"
return text
@ -102,6 +103,15 @@ class Timeline:
parse_mode=ParseMode.HTML,
reply_markup=Timeline.get_button(post),
)
elif post.external:
return await bot.send_document(
reply.cid,
post.external,
caption=text,
reply_to_message_id=reply.mid,
parse_mode=ParseMode.HTML,
reply_markup=Timeline.get_button(post),
)
elif not post.images:
return await bot.send_message(
reply.cid,