From 1bec4f9933371a738da464fe08b9a3f27ebc6d69 Mon Sep 17 00:00:00 2001
From: felinae98 <731499577@qq.com>
Date: Wed, 25 May 2022 21:26:00 +0800
Subject: [PATCH] add custom_post

---
 .../nonebot_bison/post/abstract_post.py       | 11 +++++++---
 src/plugins/nonebot_bison/post/custom_post.py | 22 +++++++++++++++++++
 2 files changed, 30 insertions(+), 3 deletions(-)
 create mode 100644 src/plugins/nonebot_bison/post/custom_post.py

diff --git a/src/plugins/nonebot_bison/post/abstract_post.py b/src/plugins/nonebot_bison/post/abstract_post.py
index 153cc67..c0902f3 100644
--- a/src/plugins/nonebot_bison/post/abstract_post.py
+++ b/src/plugins/nonebot_bison/post/abstract_post.py
@@ -42,9 +42,14 @@ class AbstractPost(OptionalMixin, BasePost):
             msg_segments = await self.generate_pic_messages()
         else:
             msg_segments = await self.generate_text_messages()
-        if self.compress:
-            msgs = [reduce(lambda x, y: x.append(y), msg_segments, Message())]
+        if msg_segments:
+            if self.compress:
+                msgs = [reduce(lambda x, y: x.append(y), msg_segments, Message())]
+            else:
+                msgs = list(
+                    map(lambda msg_segment: Message([msg_segment]), msg_segments)
+                )
         else:
-            msgs = list(map(lambda msg_segment: Message([msg_segment]), msg_segments))
+            msgs = []
         msgs.extend(self.extra_msg)
         return msgs
diff --git a/src/plugins/nonebot_bison/post/custom_post.py b/src/plugins/nonebot_bison/post/custom_post.py
new file mode 100644
index 0000000..6883717
--- /dev/null
+++ b/src/plugins/nonebot_bison/post/custom_post.py
@@ -0,0 +1,22 @@
+from dataclasses import dataclass
+
+from nonebot.adapters.onebot.v11.message import Message, MessageSegment
+
+from .abstract_post import AbstractPost, BasePost
+
+
+@dataclass
+class _CustomPost(BasePost):
+
+    message_segments: list[MessageSegment]
+
+    async def generate_text_messages(self) -> list[MessageSegment]:
+        return self.message_segments
+
+    async def generate_pic_messages(self) -> list[MessageSegment]:
+        ...  # TODO
+
+
+@dataclass
+class CustomPost(_CustomPost, AbstractPost):
+    ...