屏蔽机器人消息

This commit is contained in:
2026-07-02 11:02:48 +08:00
parent 6052bf90ec
commit 7bc2e53ce6
3 changed files with 29 additions and 27 deletions
@@ -290,8 +290,6 @@ func insertInboundBotDirectMessage(s *Store, record map[string]any, clientInfo M
}
_ = clientInfo // mqtt 元数据已经记录在 content_json 里,这里保留参数以保持队列签名一致
// 同时将消息添加到 LLM 队列(忽略机器人自己发送的消息)
if peerNodeID != bot.NodeID {
longName := NullableString(record["long_name"])
shortName := NullableString(record["short_name"])
channelID := NullableString(record["channel_id"])
@@ -310,7 +308,6 @@ func insertInboundBotDirectMessage(s *Store, record map[string]any, clientInfo M
MessageType: "direct",
ContentJSON: contentPtr,
})
}
if err != nil {
printJSON(map[string]any{
"event": "llm_queue_enqueue_failed",
+6
View File
@@ -66,6 +66,12 @@ func (s *Store) CountBotNodes(opts ListOptions) (int64, error) {
return total, s.db.Model(&BotNodeRecord{}).Count(&total).Error
}
func (s *Store) IsBotNodeID(nodeID string) bool {
var count int64
s.db.Model(&BotNodeRecord{}).Where("node_id = ?", nodeID).Count(&count)
return count > 0
}
func (s *Store) GetBotNode(id uint64) (*BotNodeRecord, error) {
var row BotNodeRecord
if err := s.db.Where("id = ?", id).Take(&row).Error; err != nil {
+5 -6
View File
@@ -306,8 +306,7 @@ func (s *Store) EnqueueLLMMessage(input LLMMessageQueueInput) (*LLMMessageQueueR
return nil, nil // 机器人的 LLM 队列未启用,静默返回
}
// 忽略机器人自己发送的消息,避免自循环
if input.FromNodeID == bot.NodeID {
if s.IsBotNodeID(input.FromNodeID) {
return nil, nil
}
@@ -526,6 +525,10 @@ func enqueueChannelMessageToLLM(s *Store, record map[string]any) error {
shortName = &sn
}
if s.IsBotNodeID(fromNodeID) {
return nil
}
var channelID *string
if cid, ok := record["channel_id"].(string); ok && cid != "" {
channelID = &cid
@@ -546,11 +549,7 @@ func enqueueChannelMessageToLLM(s *Store, record map[string]any) error {
return fmt.Errorf("query bots for channel message enqueue: %w", err)
}
// 为每个符合条件的机器人创建一条队列记录(忽略机器人自己发送的消息)
for _, bot := range bots {
if fromNodeID == bot.NodeID {
continue
}
_, err = s.EnqueueLLMMessage(LLMMessageQueueInput{
BotID: bot.ID,
BotNodeID: bot.NodeID,