blob: 01fc0d61122c6bd322ebc63e4147599d13b593e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package main
import (
"encoding/json"
"go.wit.com/lib/protobuf/chatpb"
"go.wit.com/log"
"google.golang.org/protobuf/types/known/timestamppb"
)
func doStats() {
sessionUuid := argv.Uuid
statsString := "todo: set this somehow"
// 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.Printf("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())
}
|