diff options
| author | Grail Finder <wohilas@gmail.com> | 2026-02-08 21:50:03 +0300 |
|---|---|---|
| committer | Grail Finder <wohilas@gmail.com> | 2026-02-08 21:50:03 +0300 |
| commit | 1bf9e6eef72ec2eec7282b1554b41a0dc3d8d1b8 (patch) | |
| tree | fc9a6d47d2a1c69ae6ec98baae300a241f06405c /bot.go | |
| parent | 93284312cfdb5784654fa4817c726728739b1b34 (diff) | |
Enha: extract first valid recipient from knownto
Diffstat (limited to 'bot.go')
| -rw-r--r-- | bot.go | 55 |
1 files changed, 34 insertions, 21 deletions
@@ -1305,15 +1305,17 @@ func init() { go chatWatcher(ctx) } -// triggerPrivateMessageResponses checks if a message was sent privately to specific characters -// and triggers those non-user characters to respond -func triggerPrivateMessageResponses(msg *models.RoleMsg) { +func getValidKnowToRecipient(msg *models.RoleMsg) (string, bool) { if cfg == nil || !cfg.CharSpecificContextEnabled { - return + return "", false } - userCharacter := cfg.UserRole - if cfg.WriteNextMsgAs != "" { - userCharacter = cfg.WriteNextMsgAs + // case where all roles are in the tag => public message + cr := listChatRoles() + slices.Sort(cr) + slices.Sort(msg.KnownTo) + if slices.Equal(cr, msg.KnownTo) { + logger.Info("got msg with tag mentioning every role") + return "", false } // Check each character in the KnownTo list for _, recipient := range msg.KnownTo { @@ -1323,20 +1325,31 @@ func triggerPrivateMessageResponses(msg *models.RoleMsg) { } // Skip if this is the user character (user handles their own turn) // If user is in KnownTo, stop processing - it's the user's turn - if recipient == cfg.UserRole || recipient == userCharacter { - return // user in known_to => user's turn - } - // Trigger the recipient character to respond - triggerMsg := recipient + ":\n" - // Send empty message so LLM continues naturally from the conversation - crr := &models.ChatRoundReq{ - UserMsg: triggerMsg, - Role: recipient, - Resume: true, + if recipient == cfg.UserRole || recipient == cfg.WriteNextMsgAs { + return "", false } - fmt.Fprintf(textView, "\n[-:-:b](%d) ", len(chatBody.Messages)) - fmt.Fprint(textView, roleToIcon(recipient)) - fmt.Fprint(textView, "[-:-:-]\n") - chatRoundChan <- crr + return recipient, true } + return "", false +} + +// triggerPrivateMessageResponses checks if a message was sent privately to specific characters +// and triggers those non-user characters to respond +func triggerPrivateMessageResponses(msg *models.RoleMsg) { + recipient, ok := getValidKnowToRecipient(msg) + if !ok || recipient == "" { + return + } + // Trigger the recipient character to respond + triggerMsg := recipient + ":\n" + // Send empty message so LLM continues naturally from the conversation + crr := &models.ChatRoundReq{ + UserMsg: triggerMsg, + Role: recipient, + Resume: true, + } + fmt.Fprintf(textView, "\n[-:-:b](%d) ", len(chatBody.Messages)) + fmt.Fprint(textView, roleToIcon(recipient)) + fmt.Fprint(textView, "[-:-:-]\n") + chatRoundChan <- crr } |
