diff options
| author | historia <[not public]> | 2026-06-25 19:37:20 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-25 19:37:20 -0400 |
| commit | c55d0e4150b23f2c5c9f96bbc3d4dc2fc6dbaa36 (patch) | |
| tree | d1c02acea2b4c8d0f672c1539cfdb373b6272ed0 /internal/behavior/types.go | |
| parent | 068ce514ea3eebdc42b595c631b4b00ce4594577 (diff) | |
| download | thehouseoficarus-c55d0e4150b23f2c5c9f96bbc3d4dc2fc6dbaa36.tar.gz | |
feat: yaml conversation trees more robust
Diffstat (limited to 'internal/behavior/types.go')
| -rw-r--r-- | internal/behavior/types.go | 28 |
1 files changed, 27 insertions, 1 deletions
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))] +} |
