From 148dffcc62eb684dc480c226a27ac795d1646e27 Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Sun, 18 Aug 2024 11:38:23 -0400 Subject: [PATCH] command: record spoken message traces --- command/robot.go | 2 ++ command/talk.go | 22 ++++++++++++++-------- privmsg.go | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/command/robot.go b/command/robot.go index 8ec80c7..885a6bd 100644 --- a/command/robot.go +++ b/command/robot.go @@ -6,6 +6,7 @@ import ( "github.com/zephyrtronium/robot/brain" "github.com/zephyrtronium/robot/channel" "github.com/zephyrtronium/robot/privacy" + "github.com/zephyrtronium/robot/spoken" ) // Robot is the bot state as is visible to commands. @@ -14,4 +15,5 @@ type Robot struct { Channels map[string]*channel.Channel // TODO(zeph): syncmap[string]channel.Channel Brain brain.Brain Privacy *privacy.List + Spoken *spoken.History } diff --git a/command/talk.go b/command/talk.go index c6409a3..009cd3e 100644 --- a/command/talk.go +++ b/command/talk.go @@ -10,7 +10,7 @@ import ( "github.com/zephyrtronium/robot/brain" ) -func speakCmd(ctx context.Context, robo *Robot, call *Invocation) string { +func speakCmd(ctx context.Context, robo *Robot, call *Invocation, effect string) string { t := call.Message.Time() r := call.Channel.Rate.ReserveN(call.Message.Time(), 1) cancel := func() { r.CancelAt(t) } @@ -19,28 +19,34 @@ func speakCmd(ctx context.Context, robo *Robot, call *Invocation) string { cancel() return "" } - // TODO(zeph): record trace - m, _, err := brain.Speak(ctx, robo.Brain, call.Channel.Send, call.Args["prompt"]) + m, trace, err := brain.Speak(ctx, robo.Brain, call.Channel.Send, call.Args["prompt"]) if err != nil { robo.Log.ErrorContext(ctx, "couldn't speak", "err", err.Error()) cancel() return "" } - if call.Channel.Block.MatchString(m) { + e := call.Channel.Emotes.Pick(rand.Uint32()) + s := m + " " + e + if err := robo.Spoken.Record(ctx, call.Channel.Send, m, trace, call.Message.Time(), 0, e, effect); err != nil { + robo.Log.ErrorContext(ctx, "couldn't record trace", slog.Any("err", err)) + cancel() + return "" + } + if call.Channel.Block.MatchString(s) { robo.Log.WarnContext(ctx, "generated blocked message", slog.String("in", call.Channel.Name), slog.String("text", m), + slog.String("emote", e), ) cancel() return "" } - e := call.Channel.Emotes.Pick(rand.Uint32()) slog.InfoContext(ctx, "speak", "in", call.Channel.Name, "text", m, "emote", e) return m + " " + e } func Speak(ctx context.Context, robo *Robot, call *Invocation) { - u := speakCmd(ctx, robo, call) + u := speakCmd(ctx, robo, call, "") if u == "" { return } @@ -53,7 +59,7 @@ func Speak(ctx context.Context, robo *Robot, call *Invocation) { } func OwO(ctx context.Context, robo *Robot, call *Invocation) { - u := speakCmd(ctx, robo, call) + u := speakCmd(ctx, robo, call, "OwO") if u == "" { return } @@ -77,7 +83,7 @@ var owoRep = strings.NewReplacer( ) func AAAAA(ctx context.Context, robo *Robot, call *Invocation) { - u := speakCmd(ctx, robo, call) + u := speakCmd(ctx, robo, call, "AAAAA") if u == "" { return } diff --git a/privmsg.go b/privmsg.go index 9145670..54f6b57 100644 --- a/privmsg.go +++ b/privmsg.go @@ -109,6 +109,7 @@ func (robo *Robot) command(ctx context.Context, ch *channel.Channel, m *message. Channels: robo.channels, Brain: robo.brain, Privacy: robo.privacy, + Spoken: robo.spoken, } inv := command.Invocation{ Channel: ch,