屏蔽机器人消息
This commit is contained in:
@@ -290,27 +290,24 @@ 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"])
|
||||
_, err = s.EnqueueLLMMessage(LLMMessageQueueInput{
|
||||
BotID: bot.ID,
|
||||
BotNodeID: bot.NodeID,
|
||||
BotNodeNum: bot.NodeNum,
|
||||
FromNodeID: peerNodeID,
|
||||
FromNodeNum: int64(peerNum),
|
||||
LongName: longName,
|
||||
ShortName: shortName,
|
||||
Text: text,
|
||||
PacketID: int64(packetID),
|
||||
ChannelID: channelID,
|
||||
Topic: topic,
|
||||
MessageType: "direct",
|
||||
ContentJSON: contentPtr,
|
||||
})
|
||||
}
|
||||
longName := NullableString(record["long_name"])
|
||||
shortName := NullableString(record["short_name"])
|
||||
channelID := NullableString(record["channel_id"])
|
||||
_, err = s.EnqueueLLMMessage(LLMMessageQueueInput{
|
||||
BotID: bot.ID,
|
||||
BotNodeID: bot.NodeID,
|
||||
BotNodeNum: bot.NodeNum,
|
||||
FromNodeID: peerNodeID,
|
||||
FromNodeNum: int64(peerNum),
|
||||
LongName: longName,
|
||||
ShortName: shortName,
|
||||
Text: text,
|
||||
PacketID: int64(packetID),
|
||||
ChannelID: channelID,
|
||||
Topic: topic,
|
||||
MessageType: "direct",
|
||||
ContentJSON: contentPtr,
|
||||
})
|
||||
if err != nil {
|
||||
printJSON(map[string]any{
|
||||
"event": "llm_queue_enqueue_failed",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user