Enha: use slices methods
This commit is contained in:
12
bot.go
12
bot.go
@@ -19,6 +19,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -154,15 +155,8 @@ func filterMessagesForCharacter(messages []models.RoleMsg, character string) []m
|
|||||||
filtered = append(filtered, msg)
|
filtered = append(filtered, msg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Check if character is in KnownTo list
|
if slices.Contains(msg.KnownTo, character) {
|
||||||
found := false
|
// Check if character is in KnownTo lis
|
||||||
for _, k := range msg.KnownTo {
|
|
||||||
if k == character {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if found {
|
|
||||||
filtered = append(filtered, msg)
|
filtered = append(filtered, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
@@ -198,6 +199,7 @@ func listRolesWithUser() []string {
|
|||||||
}
|
}
|
||||||
// Prepend user role to the beginning of the list
|
// Prepend user role to the beginning of the list
|
||||||
result := append([]string{cfg.UserRole}, filteredRoles...)
|
result := append([]string{cfg.UserRole}, filteredRoles...)
|
||||||
|
slices.Sort(result)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
tui.go
3
tui.go
@@ -1187,7 +1187,6 @@ func init() {
|
|||||||
persona = cfg.WriteNextMsgAs
|
persona = cfg.WriteNextMsgAs
|
||||||
}
|
}
|
||||||
roles := listRolesWithUser()
|
roles := listRolesWithUser()
|
||||||
logger.Info("list roles", "roles", roles)
|
|
||||||
for i, role := range roles {
|
for i, role := range roles {
|
||||||
if strings.EqualFold(role, persona) {
|
if strings.EqualFold(role, persona) {
|
||||||
if i == len(roles)-1 {
|
if i == len(roles)-1 {
|
||||||
@@ -1197,7 +1196,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
cfg.WriteNextMsgAs = roles[i+1] // get next role
|
cfg.WriteNextMsgAs = roles[i+1] // get next role
|
||||||
persona = cfg.WriteNextMsgAs
|
persona = cfg.WriteNextMsgAs
|
||||||
// logger.Info("picked role", "roles", roles, "index", i+1)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1228,7 +1226,6 @@ func init() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
cfg.WriteNextMsgAsCompletionAgent = roles[i+1] // get next role
|
cfg.WriteNextMsgAsCompletionAgent = roles[i+1] // get next role
|
||||||
// logger.Info("picked role", "roles", roles, "index", i+1)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user