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.
This commit is contained in:
huer512 2026-02-23 18:19:57 +08:00
parent b9a66248d8
commit f7644b796c
4 changed files with 21 additions and 7 deletions

View file

@ -112,6 +112,7 @@
"access_token": "",
"reconnect_interval": 5,
"group_trigger_prefix": [],
"mentioned_only": true,
"allow_from": []
},
"wecom": {

View file

@ -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白名单空表示允许所有用户 |
## 设置流程

View file

@ -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,

View file

@ -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"`
}