From c55d0e4150b23f2c5c9f96bbc3d4dc2fc6dbaa36 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Thu, 25 Jun 2026 19:37:20 -0400 Subject: feat: yaml conversation trees more robust --- internal/behavior/types.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'internal/behavior/types.go') diff --git a/internal/behavior/types.go b/internal/behavior/types.go index 3c6e290..f8e65f7 100644 --- a/internal/behavior/types.go +++ b/internal/behavior/types.go @@ -1,6 +1,11 @@ package behavior -import "strings" +import ( + "math/rand" + "strings" + + "gopkg.in/yaml.v3" +) func WordPrefixMatch(input, name string) bool { inputWords := strings.Fields(strings.ToLower(input)) @@ -186,3 +191,24 @@ type DropEntry struct { type DropTableDef struct { Drops []DropEntry `yaml:"drops"` } + +type MessageList []string + +func (ml *MessageList) UnmarshalYAML(value *yaml.Node) error { + if value.Kind == yaml.ScalarNode { + var s string + if err := value.Decode(&s); err != nil { + return err + } + *ml = MessageList{s} + return nil + } + return value.Decode((*[]string)(ml)) +} + +func (ml MessageList) Pick() string { + if len(ml) == 0 { + return "" + } + return ml[rand.Intn(len(ml))] +} -- cgit v1.2.3