-
Notifications
You must be signed in to change notification settings - Fork 1
/
streamStatusEvent.go
79 lines (71 loc) · 1.86 KB
/
streamStatusEvent.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
package twitch
import (
"encoding/json"
"time"
)
type StreamStatusEventData struct {
ChannelId string
Online bool
Id string
UserId string
UserName string
GameId string
CommunityIds []string
Type string
Title string
ViewerCount int
StartedAt time.Time
Language string
ThumbnailUrl string
timestamp time.Time
}
func (e *StreamStatusEventData) GetType() EventType {
return EventStreamStatus
}
func (e *StreamStatusEventData) GetData() interface{} {
return e
}
func (e *StreamStatusEventData) AsMap() map[string]interface{} {
return map[string]interface{}{
"id": e.Id,
"online": e.Online,
"user_id": e.UserId,
"user_name": e.UserName,
"game_id": e.GameId,
"community_ids": e.CommunityIds,
"title": e.Title,
"viewer_count": e.ViewerCount,
"started_at": e.StartedAt,
"language": e.Language,
"thumbnail_url": e.ThumbnailUrl,
"type": e.GetType(),
"data": e.GetData(),
"channel_id": e.ChannelId,
"timestamp": e.timestamp.Format(time.RFC3339),
}
}
func (e *StreamStatusEventData) AsJson() string {
s, _ := json.Marshal(e.AsMap())
return string(s)
}
func (e *StreamStatusEventData) Timestamp() time.Time {
return e.timestamp
}
func MakeStreamStatusEventData(channelId string, online bool, id, userId, userName, gameId, stype, title, language, thumbnail string, communityIds []string, viewers int, startedAt time.Time) ChatEvent {
return &StreamStatusEventData{
ChannelId: channelId,
Online: online,
Id: id,
UserId: userId,
UserName: userName,
GameId: gameId,
Type: stype,
Title: title,
Language: language,
ThumbnailUrl: thumbnail,
ViewerCount: viewers,
StartedAt: startedAt,
CommunityIds: communityIds,
timestamp: time.Now(),
}
}