diff --git a/pkg/pipeline/longtext/strategies/forward.py b/pkg/pipeline/longtext/strategies/forward.py index c001b6d8..7abb9c6e 100644 --- a/pkg/pipeline/longtext/strategies/forward.py +++ b/pkg/pipeline/longtext/strategies/forward.py @@ -9,30 +9,8 @@ from ....core import entities as core_entities from ....platform.types import message as platform_message -class ForwardMessageDiaplay(pydantic.BaseModel): - title: str = "群聊的聊天记录" - brief: str = "[聊天记录]" - source: str = "聊天记录" - preview: typing.List[str] = [] - summary: str = "查看x条转发消息" - - -class Forward(platform_message.MessageComponent): - """合并转发。""" - type: str = "Forward" - """消息组件类型。""" - display: ForwardMessageDiaplay - """显示信息""" - node_list: typing.List[platform_message.ForwardMessageNode] - """转发消息节点列表。""" - def __init__(self, *args, **kwargs): - if len(args) == 1: - self.node_list = args[0] - super().__init__(**kwargs) - super().__init__(*args, **kwargs) - - def __str__(self): - return '[聊天记录]' +ForwardMessageDiaplay = platform_message.ForwardMessageDiaplay +Forward = platform_message.Forward @strategy_model.strategy_class("forward") diff --git a/pkg/platform/sources/discord.py b/pkg/platform/sources/discord.py index f8f0179d..577272a3 100644 --- a/pkg/platform/sources/discord.py +++ b/pkg/platform/sources/discord.py @@ -55,6 +55,11 @@ class DiscordMessageConverter(adapter.MessageConverter): image_files.append(discord.File(fp=image_bytes, filename=f"{uuid.uuid4()}.png")) elif isinstance(ele, platform_message.Plain): text_string += ele.text + elif isinstance(ele, platform_message.Forward): + for node in ele.node_list: + text_string, image_files = await DiscordMessageConverter.yiri2target(node.message_chain) + text_string += text_string + image_files.extend(image_files) return text_string, image_files diff --git a/pkg/platform/sources/lark.py b/pkg/platform/sources/lark.py index 4d630ae9..b4b346db 100644 --- a/pkg/platform/sources/lark.py +++ b/pkg/platform/sources/lark.py @@ -90,6 +90,9 @@ class LarkMessageConverter(adapter.MessageConverter): ] ) pending_paragraph = [] + elif isinstance(msg, platform_message.Forward): + for node in msg.node_list: + message_elements.extend(await LarkMessageConverter.yiri2target(node.message_chain, api_client)) if pending_paragraph: message_elements.append(pending_paragraph) diff --git a/pkg/platform/types/message.py b/pkg/platform/types/message.py index aad239d8..f53193d0 100644 --- a/pkg/platform/types/message.py +++ b/pkg/platform/types/message.py @@ -785,10 +785,20 @@ class ForwardMessageNode(pydantic.BaseModel): ) +class ForwardMessageDiaplay(pydantic.BaseModel): + title: str = "群聊的聊天记录" + brief: str = "[聊天记录]" + source: str = "聊天记录" + preview: typing.List[str] = [] + summary: str = "查看x条转发消息" + + class Forward(MessageComponent): """合并转发。""" type: str = "Forward" """消息组件类型。""" + display: ForwardMessageDiaplay + """显示信息""" node_list: typing.List[ForwardMessageNode] """转发消息节点列表。""" def __init__(self, *args, **kwargs): diff --git a/templates/platform.json b/templates/platform.json index 959c8b00..58489d4b 100644 --- a/templates/platform.json +++ b/templates/platform.json @@ -58,7 +58,7 @@ "max": 0 }, "long-text-process": { - "threshold": 256, + "threshold": 2560, "strategy": "forward", "font-path": "" },