From d9881afbccd0e800842d6d57a9b216d9c4e789b3 Mon Sep 17 00:00:00 2001 From: SXP-Simon Date: Fri, 6 Mar 2026 22:34:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(Onebot):=20=E5=A4=9A=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E6=8E=A2=E6=B5=8B=E5=BA=8F=E5=88=97=E5=8F=B7?= =?UTF-8?q?=EF=BC=9A=E4=BC=98=E5=8C=96=E4=BA=86=E6=8F=90=E5=8F=96=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=B8=8D=E4=BB=85=E6=A3=80=E6=9F=A5=20messag?= =?UTF-8?q?e=5Fseq=EF=BC=8C=E8=BF=98=E6=94=AF=E6=8C=81=20LLBot=20=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E4=B8=AD=E5=87=BA=E7=8E=B0=E7=9A=84=20real=5Fid=20?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=B8=B8=E8=A7=81=E7=9A=84=20seq=20=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/adapters/onebot_adapter.py | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/infrastructure/platform/adapters/onebot_adapter.py b/src/infrastructure/platform/adapters/onebot_adapter.py index bba578f..887667a 100644 --- a/src/infrastructure/platform/adapters/onebot_adapter.py +++ b/src/infrastructure/platform/adapters/onebot_adapter.py @@ -171,11 +171,23 @@ class OneBotAdapter(PlatformAdapter): if start_timestamp <= msg_time <= int(end_time.timestamp()): all_raw_messages.append(raw_msg) - # 更新锚点为该批次最旧的消息序列号/ID,用于下一次回溯请求 - # 优先使用 message_seq 以适配 go-cqhttp/NapCat 的标准历史接口 - new_anchor_id = chunk_earliest_msg.get( - "message_seq", chunk_earliest_msg.get("message_id") + # 提取锚点。LLBot/NapCat 等不同实现字段不统一,需多字段探测。 + # 优先级: message_seq > real_id > seq > message_id + seq_val = ( + chunk_earliest_msg.get("message_seq") + or chunk_earliest_msg.get("real_id") + or chunk_earliest_msg.get("seq") ) + mid_val = chunk_earliest_msg.get("message_id") + + try: + # 如果能提取到正整数序列号,执行 -1 偏移以确保分页窗口向前(历史)推进 + if seq_val is not None and int(seq_val) > 0: + new_anchor_id = int(seq_val) - 1 + else: + new_anchor_id = mid_val + except (ValueError, TypeError): + new_anchor_id = mid_val # 如果时间已经超过限制,或者锚点没有变化(说明已经到底),则停止 if chunk_earliest_time < start_timestamp: @@ -192,7 +204,7 @@ class OneBotAdapter(PlatformAdapter): current_anchor_id = new_anchor_id logger.debug( - f"OneBot 分页拉取进度: 已获取 {len(all_raw_messages)} 条符合条件的消息,下一次锚点: {current_anchor_id}" + f"OneBot 分页拉取进度: 已获取 {len(all_raw_messages)} 条基础/有效消息,下一次锚点: {current_anchor_id}" ) # 稍微延迟,减缓服务端压力