From 5cdec18863dce9b85b7319ffd21ca807120089f7 Mon Sep 17 00:00:00 2001 From: anka <1350989414@qq.com> Date: Sat, 19 Apr 2025 16:52:30 +0000 Subject: [PATCH] =?UTF-8?q?improvement:=20=E5=AF=B9=E6=A0=87=E7=82=B9?= =?UTF-8?q?=E7=AC=A6=E5=8F=B7=E5=88=86=E5=89=B2=E8=80=8C=E4=B8=8D=E6=98=AF?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E5=88=87=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/sources/wecom/wecom_event.py | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/astrbot/core/platform/sources/wecom/wecom_event.py b/astrbot/core/platform/sources/wecom/wecom_event.py index b42ddeac3..8758f785d 100644 --- a/astrbot/core/platform/sources/wecom/wecom_event.py +++ b/astrbot/core/platform/sources/wecom/wecom_event.py @@ -45,7 +45,30 @@ class WecomPlatformEvent(AstrMessageEvent): if len(plain) <= 2048: return [plain] else: - return [plain[i : i + 2048] for i in range(0, len(plain), 2048)] + result = [] + start = 0 + while start < len(plain): + # 剩下的字符串长度<2048时结束 + if start + 2048 >= len(plain): + result.append(plain[start:]) + break + + # 向前搜索分割标点符号 + end = min(start + 2048, len(plain)) + cut_position = end + for i in range(end, start, -1): + if i < len(plain) and plain[i-1] in ["。", "!", "?", ".", "!", "?", "\n", ";", ";"]: + cut_position = i + break + + # 没找到合适的位置分割, 直接切分 + if cut_position == end and end < len(plain): + cut_position = end + + result.append(plain[start:cut_position]) + start = cut_position + + return result async def send(self, message: MessageChain): message_obj = self.message_obj