屏蔽机器人消息

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
+18 -21
View File
@@ -290,27 +290,24 @@ func insertInboundBotDirectMessage(s *Store, record map[string]any, clientInfo M
} }
_ = clientInfo // mqtt 元数据已经记录在 content_json 里,这里保留参数以保持队列签名一致 _ = clientInfo // mqtt 元数据已经记录在 content_json 里,这里保留参数以保持队列签名一致
// 同时将消息添加到 LLM 队列(忽略机器人自己发送的消息) longName := NullableString(record["long_name"])
if peerNodeID != bot.NodeID { shortName := NullableString(record["short_name"])
longName := NullableString(record["long_name"]) channelID := NullableString(record["channel_id"])
shortName := NullableString(record["short_name"]) _, err = s.EnqueueLLMMessage(LLMMessageQueueInput{
channelID := NullableString(record["channel_id"]) BotID: bot.ID,
_, err = s.EnqueueLLMMessage(LLMMessageQueueInput{ BotNodeID: bot.NodeID,
BotID: bot.ID, BotNodeNum: bot.NodeNum,
BotNodeID: bot.NodeID, FromNodeID: peerNodeID,
BotNodeNum: bot.NodeNum, FromNodeNum: int64(peerNum),
FromNodeID: peerNodeID, LongName: longName,
FromNodeNum: int64(peerNum), ShortName: shortName,
LongName: longName, Text: text,
ShortName: shortName, PacketID: int64(packetID),
Text: text, ChannelID: channelID,
PacketID: int64(packetID), Topic: topic,
ChannelID: channelID, MessageType: "direct",
Topic: topic, ContentJSON: contentPtr,
MessageType: "direct", })
ContentJSON: contentPtr,
})
}
if err != nil { if err != nil {
printJSON(map[string]any{ printJSON(map[string]any{
"event": "llm_queue_enqueue_failed", "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 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) { func (s *Store) GetBotNode(id uint64) (*BotNodeRecord, error) {
var row BotNodeRecord var row BotNodeRecord
if err := s.db.Where("id = ?", id).Take(&row).Error; err != nil { 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 队列未启用,静默返回 return nil, nil // 机器人的 LLM 队列未启用,静默返回
} }
// 忽略机器人自己发送的消息,避免自循环 if s.IsBotNodeID(input.FromNodeID) {
if input.FromNodeID == bot.NodeID {
return nil, nil return nil, nil
} }
@@ -526,6 +525,10 @@ func enqueueChannelMessageToLLM(s *Store, record map[string]any) error {
shortName = &sn shortName = &sn
} }
if s.IsBotNodeID(fromNodeID) {
return nil
}
var channelID *string var channelID *string
if cid, ok := record["channel_id"].(string); ok && cid != "" { if cid, ok := record["channel_id"].(string); ok && cid != "" {
channelID = &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) return fmt.Errorf("query bots for channel message enqueue: %w", err)
} }
// 为每个符合条件的机器人创建一条队列记录(忽略机器人自己发送的消息)
for _, bot := range bots { for _, bot := range bots {
if fromNodeID == bot.NodeID {
continue
}
_, err = s.EnqueueLLMMessage(LLMMessageQueueInput{ _, err = s.EnqueueLLMMessage(LLMMessageQueueInput{
BotID: bot.ID, BotID: bot.ID,
BotNodeID: bot.NodeID, BotNodeID: bot.NodeID,