-
Notifications
You must be signed in to change notification settings - Fork 5
/
messageStructs.go
241 lines (211 loc) · 5.57 KB
/
messageStructs.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package dggchat
import (
"strings"
"time"
)
// Constants for different types of features a user can have
const (
FeatureSubscriber = "subscriber"
FeatureBot = "bot"
FeatureProtected = "protected"
FeatureVIP = "vip"
FeatureModerator = "moderator"
FeatureAdministrator = "admin"
FeatureTier2 = "flair1"
FeatureNotable = "flair2"
FeatureTier3 = "flair3"
FeatureTrusted = "flair4"
FeatureContributor = "flair5"
FeatureCompChallenge = "flair6"
FeatureEve = "flair7"
FeatureTier4 = "flair8"
FeatureTwitch = "flair9"
FeatureSC2 = "flair10"
FeatureBot2 = "flair11"
FeatureBroadcaster = "flair12"
FeatureTier1 = "flair13"
FeatureBirthday = "flair15"
)
// Constants for different types of errors the chat can return
const (
ErrorTooManyConnections = "toomanyconnections"
ErrorProtocol = "protocolerror"
ErrorNeedLogin = "needlogin"
ErrorNoPermission = "nopermission"
ErrorInvalidMessage = "invalidmsg"
ErrorMuted = "muted"
ErrorSubMode = "submode"
ErrorThorttled = "throttled"
ErrorDuplicate = "duplicate"
ErrorNotFound = "notfound"
ErrorNeedBanReason = "needbanreason"
)
type (
// Message reprents a normal dgg chat message
Message struct {
Sender User
Timestamp time.Time
Message string
}
message struct {
User
Timestamp int64 `json:"timestamp"`
Data string `json:"data"`
}
// Pin represents a pinned dgg message, AKA message of the day (MOTD)
Pin struct {
Sender User
Timestamp time.Time
Message string
UUID string
}
pin struct {
User
UUID string `json:"uuid"`
Data string `json:"data"`
Timestamp int64 `json:"timestamp"`
}
// Mute represents (un)mutes issued by chat moderators
Mute struct {
Sender User
Timestamp time.Time
Target User
// Online indicates whether the target was online when targeted
Online bool
}
// Ban represents (un)bans issued by chat moderators
Ban struct {
Sender User
Timestamp time.Time
Target User
// Online indicates whether the target was online when targeted
Online bool
}
// Names reprents the initial status message containing user information
Names struct {
Connections int `json:"connectioncount"`
Users []User `json:"users"`
}
// User represents a user with a list of features
User struct {
ID int64 `json:"id"`
Nick string `json:"nick"`
Features []string `json:"features"`
CreatedDate time.Time `json:"createdDate"`
Watching watching `json:"watching"`
}
watching struct {
Platform string `json:"platform"`
ID string `json:"id"`
}
// RoomAction represents a user joining or quitting the chat
RoomAction struct {
User User
Timestamp time.Time
}
roomAction struct {
User
Timestamp int64 `json:"timestamp"`
}
// PrivateMessage represents a received private message from a user
PrivateMessage struct {
User User
Message string
Timestamp time.Time
ID int
}
privateMessage struct {
MessageID int `json:"messageid"`
Timestamp int64 `json:"timestamp"`
Nick string `json:"nick"`
Data string `json:"data"`
}
// Broadcast represents a chat broadcast
Broadcast struct {
Sender User
Timestamp time.Time
Message string `json:"data"`
UUID string `json:"uuid"`
}
// SubTier represents a dgg subscription tier
SubTier struct {
Tier int64
Label string
}
// Subscription represents a dgg subscription message
Subscription struct {
Sender User
Recipient User
Timestamp time.Time
Message string
Tier SubTier
Quantity int64
UUID string
}
subscription struct {
Data string `json:"data"`
Timestamp int64 `json:"timestamp"`
Nick string `json:"nick"`
Tier int64 `json:"tier"`
TierLabel string `json:"tierLabel"`
Giftee string `json:"giftee"`
Quantity int64 `json:"quantity"`
User User `json:"user"`
Recipient User `json:"recipient"`
UUID string `json:"uuid"`
}
// Donation represents a dgg donation message
Donation struct {
Sender User
Timestamp time.Time
Message string
Amount int64
UUID string
}
donation struct {
Data string `json:"data"`
Timestamp int64 `json:"timestamp"`
Nick string `json:"nick"`
Amount int64 `json:"amount"`
User User `json:"user"`
UUID string `json:"uuid"`
}
// Ping represents a pong response from the server
Ping struct {
Timestamp int64 `json:"timestamp"`
}
// SubOnly represents a subonly message from the server
// if active, only subscribers and some other special user classes are allowed to send messages,
// until another SubOnly message is received with active set to false
SubOnly struct {
Sender User
Timestamp time.Time
Active bool
}
subOnly struct {
User
Data string `json:"data"`
Timestamp int64 `json:"timestamp"`
}
)
// HasFeature returns true if user has given feature
func (u *User) HasFeature(s string) bool {
for _, feature := range u.Features {
if feature == s {
return true
}
}
return false
}
// IsAction returns true if the message was an action (/me)
func (m *Message) IsAction() bool {
return strings.HasPrefix(m.Message, "/me ")
}
// IsGift returns true if the subscription was a gift
func (s *Subscription) IsGift() bool {
return s.Sender.Nick != s.Recipient.Nick
}
// IsMassGift returns true if the subscription was a mass gift
func (s *Subscription) IsMassGift() bool {
return s.Quantity > 0
}