-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.go
More file actions
40 lines (34 loc) · 1.31 KB
/
Copy pathfeed.go
File metadata and controls
40 lines (34 loc) · 1.31 KB
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
package idlerpg
import (
"context"
"encoding/json"
)
// The activity feed is a capped, newest-first log of the realm's dramatic
// moments — level-ups, monster and boss kills, deaths, duels, feats, godsends.
// The bots write it as those events fire; the web dashboard reads it to show a
// live "what's happening" panel, giving the game a memory beyond ephemeral chat.
const (
feedKey = "rpg:feed"
feedCap = 150 // most recent events retained
)
// FeedEvent is one entry in the activity log.
type FeedEvent struct {
Ts int64 `json:"ts"` // unix seconds when it happened
Text string `json:"text"` // the announcement, exactly as it appeared in channel
}
// record appends an event to the capped feed. Best-effort — a feed hiccup must
// never disrupt the game.
func (m *Manager) record(text string) {
blob, err := json.Marshal(FeedEvent{Ts: m.now().Unix(), Text: text})
if err != nil {
return
}
_ = m.store.ListPush(context.Background(), feedKey, string(blob), feedCap)
}
// drama announces a dramatic event in-channel AND records it to the activity
// feed. Use it in place of out.Say for highlight-reel moments; keep plain Say for
// command replies and routine chatter that shouldn't clutter the feed.
func (m *Manager) drama(network, channel, text string) {
m.out.Say(network, channel, text)
m.record(text)
}