-
Notifications
You must be signed in to change notification settings - Fork 1
/
chat.go
88 lines (72 loc) · 1.97 KB
/
chat.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
package structures
import (
"time"
"github.com/AdmiralBulldogTv/VodApi/graph/model"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type Chat struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
VodID primitive.ObjectID `json:"vod_id" bson:"vod_id"`
Twitch ChatTwitch `json:"twitch" bson:"twitch"`
Timestamp time.Time `json:"timestamp" bson:"timestamp"`
Content string `json:"content" bson:"content"`
Badges []ChatBadge `json:"badges" bson:"badges"`
Emotes []ChatEmote `json:"emotes" bson:"chat_emote"`
}
func (c Chat) ToModel() *model.Chat {
badges := make([]*model.ChatBadge, len(c.Badges))
for i, v := range c.Badges {
badges[i] = v.ToModel()
}
emotes := make([]*model.ChatEmote, len(c.Emotes))
for i, v := range c.Emotes {
emotes[i] = v.ToModel()
}
return &model.Chat{
ID: c.ID,
VodID: c.VodID,
Twitch: c.Twitch.ToModel(),
Timestamp: c.Timestamp,
Content: c.Content,
Badges: badges,
Emotes: emotes,
}
}
type ChatTwitch struct {
ID string `json:"id" bson:"id"`
UserID string `json:"user_id" bson:"user_id"`
Login string `json:"login" bson:"login"`
DisplayName string `json:"display_name" bson:"display_name"`
Color string `json:"color" bson:"color"`
}
func (c ChatTwitch) ToModel() *model.ChatTwitch {
return &model.ChatTwitch{
ID: c.ID,
UserID: c.UserID,
Login: c.Login,
DisplayName: c.DisplayName,
Color: c.Color,
}
}
type ChatBadge struct {
Name string `json:"name" bson:"name"`
URLs []string `json:"urls" bson:"urls"`
}
func (c ChatBadge) ToModel() *model.ChatBadge {
return &model.ChatBadge{
Name: c.Name,
Urls: c.URLs,
}
}
type ChatEmote struct {
Name string `json:"name" bson:"name"`
ZeroWidth bool `json:"zero_width" bson:"zero_width"`
URLs []string `json:"urls" bson:"urls"`
}
func (c ChatEmote) ToModel() *model.ChatEmote {
return &model.ChatEmote{
Name: c.Name,
ZeroWidth: c.ZeroWidth,
Urls: c.URLs,
}
}