-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
model.go
122 lines (104 loc) · 2.19 KB
/
model.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package youtube
import (
"encoding/json"
"github.com/Sora233/DDBOT/concern"
)
type UserInfo struct {
ChannelId string `json:"channel_id"`
ChannelName string `json:"channel_name"`
}
type EventType int64
const (
Video EventType = iota
Live
)
type ConcernEvent interface {
Type() EventType
}
// VideoInfo may be a video or a live, depend on the VideoType
type VideoInfo struct {
UserInfo
Cover string `json:"cover"`
VideoId string `json:"video_id"`
VideoTitle string `json:"video_title"`
VideoType VideoType `json:"video_type"`
VideoStatus VideoStatus `json:"video_status"`
VideoTimestamp int64 `json:"video_timestamp"`
}
func (v *VideoInfo) Type() EventType {
if v.IsLive() {
return Live
} else {
return Video
}
}
func (v *VideoInfo) IsLive() bool {
if v == nil {
return false
}
return v.VideoType == VideoType_FirstLive || v.VideoType == VideoType_Live
}
func (v *VideoInfo) IsLiving() bool {
if v == nil {
return false
}
return v.IsLive() && v.VideoStatus == VideoStatus_Living
}
func (v *VideoInfo) IsWaiting() bool {
if v == nil {
return false
}
return v.IsLive() && v.VideoStatus == VideoStatus_Waiting
}
func (v *VideoInfo) IsVideo() bool {
if v == nil {
return false
}
return v.VideoType == VideoType_Video
}
type Info struct {
VideoInfo []*VideoInfo `json:"video_info"`
UserInfo
}
func (i *Info) ToString() string {
if i == nil {
return ""
}
b, _ := json.Marshal(i)
return string(b)
}
func NewInfo(vinfo []*VideoInfo) *Info {
info := new(Info)
info.VideoInfo = vinfo
if len(vinfo) > 0 {
info.ChannelId = vinfo[0].ChannelId
info.ChannelName = vinfo[0].ChannelName
}
return info
}
type ConcernNotify struct {
VideoInfo
GroupCode int64 `json:"group_code"`
}
func (c *ConcernNotify) Type() concern.Type {
if c.IsLive() {
return concern.YoutubeLive
} else {
return concern.YoutubeVideo
}
}
func NewConcernNotify(groupCode int64, info *VideoInfo) *ConcernNotify {
if info == nil {
return nil
}
return &ConcernNotify{
VideoInfo: *info,
GroupCode: groupCode,
}
}
func NewUserInfo(channelId, channelName string) *UserInfo {
return &UserInfo{
ChannelId: channelId,
ChannelName: channelName,
}
}