Skip to content

Commit

Permalink
🐛 为各主题添加 repost 的渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
AzideCupric committed Mar 20, 2024
1 parent c915b36 commit e320646
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions nonebot_bison/theme/themes/basic/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,22 @@ async def render(self, post: "Post") -> list[MessageSegmentFactory]:

text += post.content if len(post.content) < 500 else f"{post.content[:500]}..."

if rp := post.repost:
text += f"\n--------------\n转发自 {rp.nickname or ''}:\n"
text += f"{rp.title}\n"
text += rp.content if len(rp.content) < 500 else f"{rp.content[:500]}..."

text += f"\n来源: {post.platform.name} {post.nickname or ''}\n"

urls: list[str] = []
if rp and rp.url:
urls += f"转发详情:{rp.url}"
if post.url:
text += f"详情: {post.url}"

if urls:
text += "\n".join(urls)

msgs: list[MessageSegmentFactory] = [Text(text)]
if post.images:
pics = post.images
Expand Down
2 changes: 1 addition & 1 deletion nonebot_bison/theme/themes/brief/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def render(self, post: "Post") -> list[MessageSegmentFactory]:
if not post.title:
raise ThemeRenderUnsupportError("Post has no title")
text = f"{post.title}\n\n"
text += f"来源: {post.platform.name} {post.nickname or ''}\n"
text += f"来源: {post.platform.name} {post.nickname or ''}{' 的转发' if post.repost else ''}\n"
if post.url:
text += f"详情: {post.url}"

Expand Down
14 changes: 13 additions & 1 deletion nonebot_bison/theme/themes/ht2i/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,24 @@ async def render(self, post: "Post"):

_text += post.content if len(post.content) < 500 else f"{post.content[:500]}..."

if rp := post.repost:
_text += f"\n--------------\n转发自 {rp.nickname or ''}:\n"
_text += f"{rp.title}\n"
_text += rp.content if len(rp.content) < 500 else f"{rp.content[:500]}..."

_text += f"\n来源: {post.platform.name} {post.nickname or ''}\n"

msgs: list[MessageSegmentFactory] = [await self._text_render(_text)]

urls: list[str] = []
if rp and rp.url:
urls += f"转发详情:{rp.url}"
if post.url:
msgs.append(Text(f"详情: {post.url}"))
urls += f"详情: {post.url}"

if urls:
msgs.append(Text("\n".join(urls)))

if post.images:
pics = post.images
if is_pics_mergable(pics):
Expand Down

0 comments on commit e320646

Please sign in to comment.