queue: include send time in messages
This commit is contained in:
parent
0928197781
commit
7cc4482965
@ -125,10 +125,20 @@ func webhook(q *kgo.Client, secret []byte, errs chan<- error) http.HandlerFunc {
|
||||
slog.String("broadcaster", ev.Event.Broadcaster),
|
||||
slog.String("id", ev.Event.ID),
|
||||
)
|
||||
// Use the external clock for timestamps.
|
||||
tm, err := time.Parse(time.RFC3339Nano, r.Header.Get("Twitch-Eventsub-Message-Timestamp"))
|
||||
if err != nil {
|
||||
log.LogAttrs(ctx, slog.LevelWarn, "bad timestamp",
|
||||
slog.String("timestamp", r.Header.Get("Twitch-Eventsub-Message-Timestamp")),
|
||||
slog.Any("err", err),
|
||||
)
|
||||
tm = time.Now()
|
||||
}
|
||||
msg := queue.Message{
|
||||
ID: ev.Event.ID,
|
||||
Channel: ev.Event.Broadcaster,
|
||||
Sender: queue.Sender(secret, ev.Event.Broadcaster, ev.Event.Chatter),
|
||||
Timestamp: tm.UnixNano(),
|
||||
Text: ev.Event.Message.Text,
|
||||
}
|
||||
// TODO(branden): the context in the http request cancels once this
|
||||
|
@ -18,6 +18,9 @@ type Message struct {
|
||||
Channel string `json:"ch"`
|
||||
// Sender is an obfuscated identifier for the sending user.
|
||||
Sender sender `json:"u"`
|
||||
// Timestamp is the time at which the message was sent in nanoseconds since
|
||||
// the Unix epoch.
|
||||
Timestamp int64 `json:"ts"`
|
||||
// Text is the message content.
|
||||
Text string `json:"t"`
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ func TestSend(t *testing.T) {
|
||||
ID: "bocchi",
|
||||
Channel: "kessoku",
|
||||
Sender: queue.Sender(make([]byte, 16), "kessoku", "ryō"),
|
||||
Timestamp: 1,
|
||||
Text: "bocchi the rock!",
|
||||
}
|
||||
var q spyProducer
|
||||
|
Loading…
Reference in New Issue
Block a user