diff options
| author | Castor Gemini <[email protected]> | 2025-08-24 09:01:34 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-08-24 09:01:34 -0500 |
| commit | 1a6b3671443c86ced2f7143116b3f8ff7206cef5 (patch) | |
| tree | 524d88f633f5f2e298356eaafd5fedb739153655 | |
| parent | cd170de6777c517920abf7894c9dc2379fb12e5a (diff) | |
feat(stats): add --stats flag to save session stats
| -rw-r--r-- | argv.go | 1 | ||||
| -rw-r--r-- | doStats.go | 49 | ||||
| -rw-r--r-- | main.go | 5 |
3 files changed, 55 insertions, 0 deletions
@@ -16,6 +16,7 @@ type args struct { Output string `arg:"--output" help:"should get a string from regex-cli"` Input string `arg:"--input" help:"should get a string from regex-cli"` ImportFile string `arg:"--import" help:"import a file from regex-cli"` + Stats []string `arg:"--stats" help:"add stats to a chat"` Force bool `arg:"--force" help:"try to strong arm things"` Verbose bool `arg:"--verbose" help:"show more output"` Bash bool `arg:"--bash" help:"generate bash completion"` diff --git a/doStats.go b/doStats.go new file mode 100644 index 0000000..19ca180 --- /dev/null +++ b/doStats.go @@ -0,0 +1,49 @@ +package main + +import ( + "encoding/json" + "fmt" + + "go.wit.com/lib/protobuf/chatpb" + "go.wit.com/log" + "google.golang.org/protobuf/types/known/timestamppb" +) + +func doStats() { + if len(argv.Stats) != 2 { + log.Error(fmt.Errorf("expected 2 arguments for --stats")) + return + } + sessionUuid := argv.Stats[0] + statsString := argv.Stats[1] + + // Find the "auto" chat, or create it if it doesn't exist. + var autoChat *chatpb.Chat + for _, chat := range me.chats.GetChats() { + if chat.GetChatName() == "auto" { + autoChat = chat + break + } + } + if autoChat == nil { + autoChat = &chatpb.Chat{ + ChatName: "auto", + Ctime: timestamppb.Now(), + } + me.chats.Chats = append(me.chats.Chats, autoChat) + } + + var stats chatpb.SessionStats + err := json.Unmarshal([]byte(statsString), &stats) + if err != nil { + log.Error(fmt.Errorf("error unmarshalling stats: %w", err)) + return + } + + // The session UUID from the command line is the UUID of the session. + stats.Uuid = sessionUuid + + autoChat.Session = append(autoChat.Session, &stats) + me.chats.ConfigSave() + log.Info("stats saved for session", sessionUuid, "in chat", autoChat.GetChatName()) +} @@ -53,6 +53,11 @@ func main() { me.chats.ConfigSave() } + if argv.Stats != nil { + doStats() + okExit("") + } + if argv.Output != "" { doOutput(argv.Output) okExit("") |
