From f7644b796c459df11087f1a8caa042f8c840f989 Mon Sep 17 00:00:00 2001 From: huer512 Date: Mon, 23 Feb 2026 18:19:57 +0800 Subject: [PATCH] feat: add mentioned_only config for OneBot channel - add `mentioned_only` for OneBot channel to control whether the message contains a mention of the bot (@bot_id) can be processed. - update the documentation accordingly. --- config/config.example.json | 1 + docs/channels/onebot/README.zh.md | 14 ++++++++------ pkg/channels/onebot.go | 12 +++++++++++- pkg/config/config.go | 1 + 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/config/config.example.json b/config/config.example.json index 77a8c0683..ec1d2b1a3 100644 --- a/config/config.example.json +++ b/config/config.example.json @@ -112,6 +112,7 @@ "access_token": "", "reconnect_interval": 5, "group_trigger_prefix": [], + "mentioned_only": true, "allow_from": [] }, "wecom": { diff --git a/docs/channels/onebot/README.zh.md b/docs/channels/onebot/README.zh.md index 6195f1c98..4a9b62187 100644 --- a/docs/channels/onebot/README.zh.md +++ b/docs/channels/onebot/README.zh.md @@ -17,12 +17,14 @@ OneBot 是一个面向 QQ 机器人的开放协议标准,为多种 QQ 机器 } ``` -| 字段 | 类型 | 必填 | 描述 | -| ------------ | ------ | ---- | -------------------------------- | -| enabled | bool | 是 | 是否启用 OneBot 频道 | -| ws_url | string | 是 | OneBot 服务器的 WebSocket URL | -| access_token | string | 否 | 连接 OneBot 服务器的访问令牌 | -| allow_from | array | 否 | 用户ID白名单,空表示允许所有用户 | +| 字段 | 类型 | 必填 | 默认值 | 描述 | +| ------------------ | ------ | ---- | ------ | -------------------------------------------------------------------- | +| enabled | bool | 是 | - | 是否启用 OneBot 频道 | +| ws_url | string | 是 | - | OneBot 服务器的 WebSocket URL | +| access_token | string | 否 | - | 连接 OneBot 服务器的访问令牌 | +| mentioned_only | bool | 否 | true | 为 true 时仅处理 @ 了机器人的群消息;为 false 时处理所有群消息(适用于官方机器人等仅推送已 @ 消息的实现) | +| group_trigger_prefix | array | 否 | [] | 群消息触发前缀,消息以此列表中某一项开头也会触发 | +| allow_from | array | 否 | [] | 用户ID白名单,空表示允许所有用户 | ## 设置流程 diff --git a/pkg/channels/onebot.go b/pkg/channels/onebot.go index cee8ad9d3..d3509a032 100644 --- a/pkg/channels/onebot.go +++ b/pkg/channels/onebot.go @@ -887,7 +887,17 @@ func (c *OneBotChannel) handleMessage(raw *oneBotRawEvent) { metadata["sender_name"] = sender.Nickname } - triggered, strippedContent := c.checkGroupTrigger(content, isBotMentioned) + mentionedOnly := true + if c.config.MentionedOnly != nil { + mentionedOnly = *c.config.MentionedOnly + } + var triggered bool + var strippedContent string + if mentionedOnly { + triggered, strippedContent = c.checkGroupTrigger(content, isBotMentioned) + } else { + triggered, strippedContent = true, content + } if !triggered { logger.DebugCF("onebot", "Group message ignored (no trigger)", map[string]any{ "sender": senderID, diff --git a/pkg/config/config.go b/pkg/config/config.go index 20556011a..fa6e928c3 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -267,6 +267,7 @@ type OneBotConfig struct { AccessToken string `json:"access_token" env:"PICOCLAW_CHANNELS_ONEBOT_ACCESS_TOKEN"` ReconnectInterval int `json:"reconnect_interval" env:"PICOCLAW_CHANNELS_ONEBOT_RECONNECT_INTERVAL"` GroupTriggerPrefix []string `json:"group_trigger_prefix" env:"PICOCLAW_CHANNELS_ONEBOT_GROUP_TRIGGER_PREFIX"` + MentionedOnly *bool `json:"mentioned_only" env:"PICOCLAW_CHANNELS_ONEBOT_MENTIONED_ONLY"` AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_ONEBOT_ALLOW_FROM"` }