From b672a39356ccf3ee68ca17af026c681ec777ac90 Mon Sep 17 00:00:00 2001 From: Lennard <1649211052@qq.com> Date: Tue, 10 Nov 2026 12:24:03 -0800 Subject: [PATCH 01/17] =?UTF-8?q?fix:=20=E5=8D=8F=E8=AE=AE=E7=AB=AF?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=9B=9E=E6=89=A7=E7=9A=84=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=AE=B0=E4=B8=BA=E7=BB=93=E6=9E=9C=E6=9C=AA=E7=9F=A5=EF=BC=8C?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E4=B8=8D=E5=86=8D=E6=8D=A2=E5=86=99=E6=B3=95?= =?UTF-8?q?=E9=87=8D=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SnowLuma 在 QQ 收下消息却没返回群消息序号时,回 status=failed,wording 为 "group message delivery was not confirmed ... check the conversation before retrying"。这时消息可能已经在群里。宿主原来把它记成 failed,bilibili 插件 看到 failed 就去掉 @全体成员 再发一次,群里出现同一秒带 @ 和不带 @ 的两张 开播、动态卡片。 - parse_send_result 把这条 wording 解析为 unconfirmed;其他 failed 不变。 模型发言同样受益:聊天记录里写成发送结果未确认,不再当成没发出去。 - 插件文档说明 unconfirmed 时消息可能已在群里,换写法重发只在 failed 时做。 - 协议测试:假 OneBot 端分别回这条 wording 和真实拒绝,前者 unconfirmed, 后者仍为 failed。 核对:pytest tests/test_next_platform_protocol.py 通过。 未确认:lbot 上重复卡片中带 @ 的那条在库里是否为 failed、wording 是否 就是这一句,需要在实例库上核对;QQ 为什么对这类消息不给回执也未确认。 --- developer/plugins-v1.en.md | 2 +- developer/plugins-v1.md | 2 +- src/len_bot/next/platform/onebot_messages.py | 8 +++- tests/test_next_platform_protocol.py | 42 ++++++++++++++++++++ website/develop/plugin-sending.md | 2 +- 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/developer/plugins-v1.en.md b/developer/plugins-v1.en.md index 4927336c2..11a5acead 100644 --- a/developer/plugins-v1.en.md +++ b/developer/plugins-v1.en.md @@ -327,7 +327,7 @@ Override synchronous `unavailable_tools(self, scene: str) -> dict[str, str]` to | Wait for the next message | `await ctx.wait_message(timeout_seconds=60, sender="same")`; see [Multi-turn conversations](#multi-turn-conversations) | | Message words | `message_text(message, names=None)`; see [Messages](#messages) | -`self.ctx` (`PluginContext`) is used in `start()`, `stop()`, and `@background`, where scene-bound methods take an explicit `scene` argument. `self.ctx.scenes` lists the scenes that enable the plugin. Switching a scene to plugins mode (chat off) only stops waking the chat model; commands, rules, notices, schedules and sending keep working there. `Sent.status` is one of `sent`, `failed`, `unconfirmed`, `simulated`, or `partial`. +`self.ctx` (`PluginContext`) is used in `start()`, `stop()`, and `@background`, where scene-bound methods take an explicit `scene` argument. `self.ctx.scenes` lists the scenes that enable the plugin. Switching a scene to plugins mode (chat off) only stops waking the chat model; commands, rules, notices, schedules and sending keep working there. `Sent.status` is one of `sent`, `failed`, `unconfirmed`, `simulated`, or `partial`. `unconfirmed` means the outcome is unknown and the message may already be in the conversation; resend in another form (for example without mentioning everyone) only after `failed`. Card and image helpers are described in [Cards and images](#cards-and-images). diff --git a/developer/plugins-v1.md b/developer/plugins-v1.md index a99b971fa..87d07beda 100644 --- a/developer/plugins-v1.md +++ b/developer/plugins-v1.md @@ -487,7 +487,7 @@ def unavailable_tools(self, scene: str) -> dict[str, str]: `data_dir` 是这个插件独立的数据目录。KV 只按插件隔离,需要按群区分时,请把 `scene` 放进 key 中。 -发送后返回 `Sent`,状态分为 sent、failed、unconfirmed、simulated 和 partial。只有 sent 表示平台已确认,客户端上的实际效果仍需要观察。用原生 JSON 返回回执时,可以把 message_ids 转为 list。 +发送后返回 `Sent`,状态分为 sent、failed、unconfirmed、simulated 和 partial。只有 sent 表示平台已确认,客户端上的实际效果仍需要观察。unconfirmed 表示结果未知,消息可能已经在群里,换一种写法重发(例如去掉提及全体成员)只在 failed 时做。用原生 JSON 返回回执时,可以把 message_ids 转为 list。 `PluginContext.fetch_image` 和 `Invocation.fetch_image` 使用宿主的公网地址检查和重定向规则,以及实例的 fake-ip 配置和图片的字节数、像素上限。它们返回完整的、已经验证的图片。 diff --git a/src/len_bot/next/platform/onebot_messages.py b/src/len_bot/next/platform/onebot_messages.py index aff810e6a..1d9edcfad 100644 --- a/src/len_bot/next/platform/onebot_messages.py +++ b/src/len_bot/next/platform/onebot_messages.py @@ -131,6 +131,11 @@ def parse_message(raw: dict, *, own_message_ids: set[str]) -> ChatMessage: raise ValueError(f"OneBot message parse failed: {error}; raw={repr(raw)[:500]}") from error +# SnowLuma answers a send that QQ accepted without a message receipt with a failed status and this wording; +# the message may already be in the conversation, so the outcome is unknown rather than failed. +UNCONFIRMED_WORDING = "delivery was not confirmed" + + def parse_send_result(raw: dict) -> SendResult: """Interpret a message send response, never a file-upload receipt.""" if not isinstance(raw, dict): @@ -138,7 +143,8 @@ def parse_send_result(raw: dict) -> SendResult: if raw.get("status") == "failed": wording = raw.get("wording") error = wording if isinstance(wording, str) and wording else repr(raw)[:500] - return SendResult(status="failed", platform_message_id=None, error=error) + status = "unconfirmed" if UNCONFIRMED_WORDING in error else "failed" + return SendResult(status=status, platform_message_id=None, error=error) if raw.get("status") == "ok" and type(raw.get("retcode")) is int and raw["retcode"] == 0: data = raw.get("data") if isinstance(data, dict) and "message_id" in data: diff --git a/tests/test_next_platform_protocol.py b/tests/test_next_platform_protocol.py index f40fe9a6e..963163ab6 100644 --- a/tests/test_next_platform_protocol.py +++ b/tests/test_next_platform_protocol.py @@ -171,6 +171,48 @@ async def peer(websocket): assert image.size == ((320, 320) if image_type == 1 else (1024, 1024)) +@pytest.mark.asyncio +@pytest.mark.parametrize('wording, status', [ + # SnowLuma: QQ took the send but returned no message receipt; the message may already be in the group. + ('group message delivery was not confirmed: QQ returned no message receipt; check the conversation before ' + 'retrying', 'unconfirmed'), + ('send group message rejected: result=120 err=', 'failed'), +]) +async def test_send_without_receipt_is_unconfirmed_so_callers_do_not_send_it_again(wording, status): + from websockets.asyncio.server import serve + from len_bot.next.configuration.onebot import OneBotForward + from len_bot.next.platform.onebot import OneBot + from len_bot.next.platform.messages import ChatMessage, Segment, Sender + import json + + requests = [] + + async def peer(websocket): + while len(requests) < 2: + request = json.loads(await websocket.recv()) + requests.append(request) + response = ({'status': 'ok', 'retcode': 0, 'data': {'user_id': 90001, 'nickname': '脱敏 Bot'}} + if request['action'] == 'get_login_info' else + {'status': 'failed', 'retcode': 100, 'data': None, 'wording': wording}) + await websocket.send(json.dumps({**response, 'echo': request['echo']})) + await websocket.wait_closed() + + async with serve(peer, '127.0.0.1', 0) as server: + port = server.sockets[0].getsockname()[1] + settings = OneBotForward(mode='forward_ws', ws_url=f'ws://127.0.0.1:{port}') + async with OneBot(settings, bot_id='onebot:90001', on_event=lambda event: None, + on_error=lambda error: None) as bot: + card = ChatMessage(id='m1', platform='onebot', bot_id='onebot:90001', scene='onebot:group:80001', + platform_message_id=None, sender=Sender('onebot:90001', '脱敏 Bot', None, None), + time=1790000000, segments=[Segment('mention', {'user': 'all'}), + Segment('text', {'text': '合成主播 开播了'})], + reply_to=None, mentions_bot=False, is_self=True, send_status='simulated') + result = await bot.send_message(card) + assert [item['action'] for item in requests] == ['get_login_info', 'send_group_msg'] + assert requests[1]['params']['message'][0] == {'type': 'at', 'data': {'qq': 'all'}} + assert result.status == status and result.platform_message_id is None and wording in result.error + + @pytest.mark.parametrize('mention', ['onebot:all', 'qq:12345', 'onebot:abc', 'all', 'onebot:0', 'onebot:007', 'telegram:abc', 'telegram:-1001234', 'feishu:oc_room']) def test_model_speech_accepts_only_individual_platform_accounts(mention): diff --git a/website/develop/plugin-sending.md b/website/develop/plugin-sending.md index 1bb1ff4ae..686f554ed 100644 --- a/website/develop/plugin-sending.md +++ b/website/develop/plugin-sending.md @@ -27,7 +27,7 @@ await ctx.reply_parts([Mention("onebot:70001"), Text(" 轮到你了")]) | `report` | 结果说明 | | `message_ids` | 平台消息 ID | -只有 `sent` 表示平台已确认。模型工具要返回发送结果时,把这几个字段原样放进返回值,见[模型工具](plugin-tools)。 +只有 `sent` 表示平台已确认。`unconfirmed` 时消息可能已经在群里,换一种写法重发(例如去掉提及全体成员)只在 `failed` 时做。模型工具要返回发送结果时,把这几个字段原样放进返回值,见[模型工具](plugin-tools)。 ## 唤醒聊天 From 9a2fe827b1714002d0fc50ba3a7e2971ed3f4ba1 Mon Sep 17 00:00:00 2001 From: Lennard <1649211052@qq.com> Date: Tue, 10 Nov 2026 12:24:03 -0800 Subject: [PATCH 02/17] =?UTF-8?q?feat:=20=E5=9B=9E=E5=A4=8D=E6=95=88?= =?UTF-8?q?=E6=9E=9C=E5=8F=8C=E5=90=91=E8=B0=83=E6=95=B4=E6=8F=92=E8=AF=9D?= =?UTF-8?q?=E9=97=B4=E9=9A=94=EF=BC=8C=E6=94=BE=E5=AE=BD=E6=85=A2=E4=BA=8E?= =?UTF-8?q?=E6=94=B6=E7=B4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 环境插话和随机探索的回复效果系数原来只会小于 1:被无视或嫌弃时延长插话 间隔,被接住时不变。现在加权平均大于 0 时系数为 1 加上它的四分之一,最高 1.25,插话间隔最多缩短到 0.8 倍;小于 0 时照旧,最低 0.5,最多延长到 2 倍。 同样多的判定,收紧比放宽快。直接联系、点名、对话继续和持续关注仍不受影响。 - 现场唤醒详情在系数不为 1 时显示。 - developer/attention.md 与文档站唤醒方式一节同步。 - 测试:系数取值范围改为下限到上限,补被接住时缩短等待、同样多的反馈收紧 幅度大于放宽幅度、被 @ 的等待不变。 核对:pytest tests/test_attention_reply_effects.py tests/test_attention_protocol.py 通过;前端 typecheck、lint 通过。 未确认:真实群里放宽后的插话频率,需要开启回复效果后观察。 --- developer/attention.md | 2 +- src/len_bot/next/chat/attention.py | 9 +++++--- .../src/views/groups/live/VerdictMark.vue | 2 +- tests/test_attention_reply_effects.py | 21 ++++++++++++------- website/use/chatting.md | 2 +- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/developer/attention.md b/developer/attention.md index 5f0b83f27..20cab693a 100644 --- a/developer/attention.md +++ b/developer/attention.md @@ -55,7 +55,7 @@ min(ambient_max_interval_seconds, ambient_min_interval_seconds × 2^silence_leve ## 回复效果系数 -插话间隔除以一个系数。系数取本群最近 3 天内、由环境插话或随机探索唤醒的回合里最多 10 条已判定的回复效果:`agree` 和 `continue` 记 1,`unrelated` 和 `negative` 记 -1,其余记 0,每条按 24 小时半衰加权。加权平均(分母另加 2,避免一两条判定就大幅变化)小于 0 时,系数为 1 加上它的一半,最低 0.5;不小于 0 时为 1。直接联系、点名、对话继续和持续关注不受系数影响。系数随唤醒判定保存为 `effect_factor`,写进 `attention_ambient` 日志,现场的唤醒详情在系数小于 1 时显示。 +插话间隔除以一个系数。系数取本群最近 3 天内、由环境插话或随机探索唤醒的回合里最多 10 条已判定的回复效果:`agree` 和 `continue` 记 1,`unrelated` 和 `negative` 记 -1,其余记 0,每条按 24 小时半衰加权。加权平均(分母另加 2,避免一两条判定就大幅变化)小于 0 时,系数为 1 加上它的一半,最低 0.5,插话间隔最多延长到 2 倍;大于 0 时,系数为 1 加上它的四分之一,最高 1.25,插话间隔最多缩短到 0.8 倍。同样多的判定,收紧比放宽快。直接联系、点名、对话继续和持续关注不受系数影响。系数随唤醒判定保存为 `effect_factor`,写进 `attention_ambient` 日志,现场的唤醒详情在系数不为 1 时显示。 `uv run --no-sync python scripts/first_reply_latency.py batches` 用固定 OneBot 到达序列核对图片后补文字、同一人续发、换人、隔着别人续发、旁人发图和上限;`report <数据库>` 读取实际回合的首句等待与合批、模型、工具、发送耗时。 diff --git a/src/len_bot/next/chat/attention.py b/src/len_bot/next/chat/attention.py index a37c7c469..718ab38d5 100644 --- a/src/len_bot/next/chat/attention.py +++ b/src/len_bot/next/chat/attention.py @@ -45,6 +45,8 @@ EFFECT_WINDOW_SECONDS = 3 * 86400 EFFECT_HALF_LIFE_SECONDS = 86400 EFFECT_FLOOR = 0.5 +# Welcomed interjections shorten the interval by at most a fifth; disliked ones may double it. +EFFECT_CEILING = 1.25 PRIORITY = {"direct": 0, "named": 1, "attention": 2, "focus": 3, "ambient": 4, "explore": 5} REACTIONS = {"哈哈", "哈哈哈", "草", "6", "笑死", "啊", "哦", "嗯", ""} # The follow-up an interjection that answered no one opens: the next message from anyone. @@ -748,8 +750,9 @@ async def wait_for_messages(self, seconds: float) -> str: def effect_factor(self) -> float: """Up to EFFECT_SAMPLES judged reactions to this group's interjections in the window, each weighted by - age: ignored or disliked ones lower the factor toward EFFECT_FLOOR, and the interval before the next - interjection grows by its inverse; welcomed ones never shorten it. With no reactions the factor is 1.""" + age: ignored or disliked ones lower the factor toward EFFECT_FLOOR and welcomed ones raise it toward + EFFECT_CEILING; the interval before the next interjection is divided by it. The same balance moves the + factor down twice as far as up, so the bot holds back faster than it opens up. With no reactions it is 1.""" now = self.now() reactions = ReplyEffectStore(self.store).reactions( self.config.scene, ("ambient", "explore"), now - EFFECT_WINDOW_SECONDS, EFFECT_SAMPLES) @@ -757,7 +760,7 @@ def effect_factor(self) -> float: for at, reaction in reactions] # Two neutral samples' worth of prior keeps one bad reaction from doubling the interval. balance = sum(weight * value for weight, value in weights) / (sum(weight for weight, _ in weights) + 2) - return 1 + min(0.0, balance) * (1 - EFFECT_FLOOR) + return 1 + (balance * (1 - EFFECT_FLOOR) if balance < 0 else balance * (EFFECT_CEILING - 1)) def ambient_interval(self) -> float: """How long after the bot last spoke, or last looked in unprompted, it may join in again.""" diff --git a/src/len_bot/web/frontend/src/views/groups/live/VerdictMark.vue b/src/len_bot/web/frontend/src/views/groups/live/VerdictMark.vue index 04d24a5d0..80ff042d4 100644 --- a/src/len_bot/web/frontend/src/views/groups/live/VerdictMark.vue +++ b/src/len_bot/web/frontend/src/views/groups/live/VerdictMark.vue @@ -53,7 +53,7 @@ const parts = computed(() => { -