-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhistory.go
46 lines (38 loc) · 902 Bytes
/
history.go
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
45
46
package main
import (
"context"
"log/slog"
"github.com/leighmacdonald/bd/store"
)
type chatRecorder struct {
incoming chan LogEvent
db store.Querier
}
func newChatRecorder(db store.Querier, ingest *eventBroadcaster) chatRecorder {
cr := chatRecorder{
incoming: make(chan LogEvent),
db: db,
}
ingest.registerConsumer(cr.incoming, EvtMsg)
return cr
}
func (s chatRecorder) start(ctx context.Context) {
for {
select {
case evt := <-s.incoming:
if errUm := s.db.MessageSave(ctx, store.MessageSaveParams{
SteamID: evt.PlayerSID.Int64(),
Message: evt.Message,
CreatedOn: evt.Timestamp,
Team: evt.TeamOnly,
Dead: evt.Dead,
}); errUm != nil {
slog.Error("Failed to save user message", errAttr(errUm))
continue
}
slog.Debug("Chat message saved", slog.String("msg", evt.Message))
case <-ctx.Done():
return
}
}
}