/
concern_emit_fresher.go
56 lines (54 loc) · 1.46 KB
/
concern_emit_fresher.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
47
48
49
50
51
52
53
54
55
56
package bilibili
import (
"github.com/Sora233/DDBOT/lsp/concern"
"github.com/Sora233/DDBOT/lsp/concern_type"
"time"
)
func (c *Concern) emitQueueFresher() concern.FreshFunc {
return c.EmitQueueFresher(func(p concern_type.Type, id interface{}) ([]concern.Event, error) {
c.SetLastFreshTime(time.Now().Unix())
mid := id.(int64)
var result []concern.Event
for _, subType := range p.Split() {
if subType.ContainAny(Live) {
oldInfo, _ := c.FindUserLiving(mid, false)
newInfo, err := c.FindUserLiving(mid, true)
if err != nil {
logger.WithField("mid", mid).Errorf("FindUserLiving error %v", err)
continue
}
c.ClearNotLiveCount(mid)
if oldInfo == nil {
newInfo.liveStatusChanged = true
} else {
if oldInfo.Living() != newInfo.Living() {
newInfo.liveStatusChanged = true
}
if oldInfo.LiveTitle != newInfo.LiveTitle {
newInfo.liveTitleChanged = true
}
}
if newInfo.Living() {
c.MarkLatestActive(mid, time.Now().Unix())
}
result = append(result, newInfo)
}
if subType.ContainAny(News) {
newsInfo, err := c.FindUserNews(mid, true)
if err != nil {
logger.WithField("mid", mid).Errorf("FindUserNews error %v", err)
continue
}
var cards []*Card
for _, card := range newsInfo.Cards {
if c.filterCard(card) {
cards = append(cards, card)
}
}
newsInfo.Cards = cards
result = append(result, newsInfo)
}
}
return result, nil
})
}