-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructs.go
More file actions
463 lines (434 loc) · 18.1 KB
/
Copy pathstructs.go
File metadata and controls
463 lines (434 loc) · 18.1 KB
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
//Heavily inspired/derived from discordgo https://github.com/bwmarrin/discordgo
package gobeam
import (
"encoding/json"
"github.com/gorilla/websocket"
"net/http"
"reflect"
"sync"
"time"
)
type LoginPayload struct {
Level int `json:"level,omitempty"`
Social struct {
Verified []interface{} `json:"verified,omitempty"`
} `json:"social,omitempty"`
ID int `json:"id,omitempty"`
Username string `json:"username,omitempty"`
Email string `json:"email,omitempty"`
Verified bool `json:"verified,omitempty"`
Experience int `json:"experience,omitempty"`
Sparks int `json:"sparks,omitempty"`
AvatarURL string `json:"avatarUrl,omitempty"`
AllowEmail bool `json:"allowEmail,omitempty"`
Bio int `json:"bio,omitempty"`
PrimaryTeam int `json:"primaryTeam,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
DeletedAt int `json:"deletedAt,omitempty"`
Groups []struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
} `json:"groups,omitempty"`
Channel struct {
ID uint32 `json:"id,omitempty"`
UserID int `json:"userId,omitempty"`
Token string `json:"token,omitempty"`
Online bool `json:"online,omitempty"`
Featured bool `json:"featured,omitempty"`
Partnered bool `json:"partnered,omitempty"`
TranscodingProfileID int `json:"transcodingProfileId,omitempty"`
Suspended bool `json:"suspended,omitempty"`
Name string `json:"name,omitempty"`
Audience string `json:"audience,omitempty"`
ViewersTotal int `json:"viewersTotal,omitempty"`
ViewersCurrent int `json:"viewersCurrent,omitempty"`
NumFollowers int `json:"numFollowers,omitempty"`
NumSubscribers int `json:"numSubscribers,omitempty"`
MaxConcurrentSubscribers int `json:"maxConcurrentSubscribers,omitempty"`
Description string `json:"description,omitempty"`
TypeID int `json:"typeId,omitempty"`
Interactive bool `json:"interactive,omitempty"`
TetrisGameID int `json:"tetrisGameId,omitempty"`
Ftl int `json:"ftl,omitempty"`
HasVod bool `json:"hasVod,omitempty"`
LanguageID int `json:"languageId,omitempty"`
CoverID int `json:"coverId,omitempty"`
ThumbnailID int `json:"thumbnailId,omitempty"`
BadgeID int `json:"badgeId,omitempty"`
HosteeID int `json:"hosteeId,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
DeletedAt int `json:"deletedAt,omitempty"`
} `json:"channel,omitempty"`
TwoFactor struct {
Enabled bool `json:"enabled,omitempty"`
CodesViewed bool `json:"codesViewed,omitempty"`
} `json:"twoFactor,omitempty"`
HasTwoFactor bool `json:"hasTwoFactor,omitempty"`
Preferences struct {
ChatSoundsPlay string `json:"chat:sounds:play,omitempty"`
ChatSoundsHTML5 bool `json:"chat:sounds:html5,omitempty"`
ChatTimestamps bool `json:"chat:timestamps,omitempty"`
ChatWhispers bool `json:"chat:whispers,omitempty"`
ChatChromakey bool `json:"chat:chromakey,omitempty"`
ChatLurkmode bool `json:"chat:lurkmode,omitempty"`
ChannelNotifications struct {
Ids []string `json:"ids,omitempty"`
Transports []string `json:"transports,omitempty"`
} `json:"channel:notifications,omitempty"`
ChannelMatureAllowed bool `json:"channel:mature:allowed,omitempty"`
ChannelPlayer struct {
Vod string `json:"vod,omitempty"`
Rtmp string `json:"rtmp,omitempty"`
Ftl string `json:"ftl,omitempty"`
} `json:"channel:player,omitempty"`
ChatTagging bool `json:"chat:tagging,omitempty"`
ChatColors bool `json:"chat:colors,omitempty"`
ChatSoundsVolume int `json:"chat:sounds:volume,omitempty"`
} `json:"preferences,omitempty"`
}
// A Session represents a connection to the Beam API.
type Session struct {
// Debug for printing JSON request/responses
Debug bool
//Timeout for calls
TimeoutDuration time.Duration
Type string //Session Type
Cookies []*http.Cookie
sync.RWMutex
endpoints []string
authKey string //ws authkey
LoginPayload *LoginPayload
config *GoBeamConfig
CsrfToken string
UseCookies bool
lastTransactionId int
eventReplyChan chan *Event
transactionSubChan chan TransactionBuffer
isReplyMonitorAlive bool
// General configurable settings.
// Authentication token for this session
Token string
// Should the session reconnect the websocket on errors.
ShouldReconnectOnError bool
// Should the session request compressed websocket data.
Compress bool
// Should state tracking be enabled.
// State tracking is the best way for getting the the users
// active guilds and the members of the guilds.
StateEnabled bool
// Exposed but should not be modified by User.
// Whether the Data Websocket is ready
DataReady bool
// Whether the Voice Websocket is ready
VoiceReady bool
// Whether the UDP Connection is ready
UDPReady bool
// Managed state object, updated internally with events when
// StateEnabled is true.
State *State
handlersMu sync.RWMutex
// This is a mapping of event struct to a reflected value
// for event handlers.
// We store the reflected value instead of the function
// reference as it is more performant, instead of re-reflecting
// the function each event.
handlers map[interface{}][]reflect.Value
// The websocket connection.
wsConn *websocket.Conn
// When nil, the session is not listening.
listening chan interface{}
}
type User struct {
Id int `json:"id"`
UserId int `json:"user"` //Used by UserUpdate
Username string `json:"username"`
Roles []string `json:"roles"`
Permissions []string `json:"permissions"`
}
//All chat websocket events are handled with this.
type Event struct {
Type string `json:"type,omitempty"`
Event string `json:"event,omitempty"`
Method string `json:"method,omitempty"`
Id int `json:"id,omitempty"`
Arguments []interface{} `json:"arguments,omitempty"`
Error string `json:"error,omitempty"`
Data json.RawMessage `json:"data,omitempty"` //json.RawMessage `json:"data"`
}
//Handles websocket events of chatmessage
type ChatMessage struct {
Channel int `json:"channel"`
Id string `json:"id"`
Username string `json:"user_name"`
UserId int `json:"user_id"`
UserRoles []string `json:"user_roles"`
Message struct {
Messages []ChatMessageDetail `json:"message"`
} `json:"message"`
Meta ChatMeta `json:"meta,omitempty"`
Target string `json:"target,omitempty"` //Used by whisper
}
//Part of chatmessage
type ChatMeta struct {
Whisper bool `json:"whisper,omitempty"` //Omitted when whisper is not true
Me bool `json:"me,omitempty"` //This is you do an event
}
//Part of chatmessage
type ChatMessageDetail struct {
Type string `json:"type"`
Data string `json:"data"`
Text string `json:"text"`
Path string `json:"path"`
Url string `json:"url"`
Source string `json:"source"`
Pack string `json:"pack"`
Coords Coords `json:"coords"`
Username string `json:"username"` //Used when tagging
Id int `json:"id"` //Used when tagging
}
//Part of chatmessage
type Coords struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Width float64 `json:"width"`
Height float64 `float:"height"`
}
//Used by PollStart and PollEnd
type Poll struct {
Q string `json:"q"` //Question being asked
Answers []string `json:"answers"` //Possible options for answers
Author Author `json:"author"`
Duration int `json:"duration"`
EndsAt int `json:"endsAt"`
Voters int `json:"voters"`
Responses struct {
Good int `json:"good"`
Bad int `json:"bad"`
} `json:"responses"`
}
//Used by Poll
type Author struct {
Username string `json:"user_name"`
UserId int `json:"user_id"`
UserRoles []string `json:"user_roles"`
}
type Channel struct {
ID int `json:"id,omitempty"`
UserID int `json:"userId,omitempty"`
Token string `json:"token,omitempty"`
Online bool `json:"online,omitempty"`
Featured bool `json:"featured,omitempty"`
Partnered bool `json:"partnered,omitempty"`
TranscodingProfileID int `json:"transcodingProfileId,omitempty"`
Suspended bool `json:"suspended,omitempty"`
Name string `json:"name,omitempty"`
Audience string `json:"audience,omitempty"`
ViewersTotal int `json:"viewersTotal,omitempty"`
ViewersCurrent int `json:"viewersCurrent,omitempty"`
NumFollowers int `json:"numFollowers,omitempty"`
Description string `json:"description,omitempty"`
TypeID int `json:"typeId,omitempty"`
Interactive bool `json:"interactive,omitempty"`
TetrisGameID int `json:"tetrisGameId,omitempty"`
Ftl int `json:"ftl,omitempty"`
HasVod bool `json:"hasVod,omitempty"`
LanguageID int `json:"languageId,omitempty"`
CoverID int `json:"coverId,omitempty"`
ThumbnailID int `json:"thumbnailId,omitempty"`
BadgeID int `json:"badgeId,omitempty"`
HosteeID int `json:"hosteeId,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
DeletedAt int `json:"deletedAt,omitempty"`
Thumbnail int `json:"thumbnail,omitempty"`
Cover struct {
Meta struct {
Small string `json:"small,omitempty"`
} `json:"meta,omitempty"`
ID int `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Relid int `json:"relid,omitempty"`
URL string `json:"url,omitempty"`
Store string `json:"store,omitempty"`
RemotePath string `json:"remotePath,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
} `json:"cover,omitempty"`
Badge int `json:"badge,omitempty"`
Type struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Parent string `json:"parent,omitempty"`
Description string `json:"description,omitempty"`
Source string `json:"source,omitempty"`
ViewersCurrent int `json:"viewersCurrent,omitempty"`
CoverURL string `json:"coverUrl,omitempty"`
Online int `json:"online,omitempty"`
} `json:"type,omitempty"`
Cache []interface{} `json:"cache,omitempty"`
Preferences struct {
CostreamAllow string `json:"costream:allow,omitempty"`
Sharetext string `json:"sharetext,omitempty"`
ChannelLinksClickable bool `json:"channel:links:clickable,omitempty"`
ChannelLinksAllowed bool `json:"channel:links:allowed,omitempty"`
ChannelSlowchat int `json:"channel:slowchat,omitempty"`
ChannelNotifyFollow bool `json:"channel:notify:follow,omitempty"`
ChannelNotifyFollowmessage string `json:"channel:notify:followmessage,omitempty"`
ChannelNotifyHostedBy string `json:"channel:notify:hostedBy,omitempty"`
ChannelNotifyHosting string `json:"channel:notify:hosting,omitempty"`
ChannelNotifySubscribemessage string `json:"channel:notify:subscribemessage,omitempty"`
ChannelNotifySubscribe bool `json:"channel:notify:subscribe,omitempty"`
ChannelPartnerSubmail string `json:"channel:partner:submail,omitempty"`
ChannelPlayerMuteOwn bool `json:"channel:player:muteOwn,omitempty"`
ChannelTweetEnabled bool `json:"channel:tweet:enabled,omitempty"`
ChannelTweetBody string `json:"channel:tweet:body,omitempty"`
} `json:"preferences,omitempty"`
User struct {
Level int `json:"level,omitempty"`
Social struct {
Verified []interface{} `json:"verified,omitempty"`
} `json:"social,omitempty"`
ID int `json:"id,omitempty"`
Username string `json:"username,omitempty"`
Verified bool `json:"verified,omitempty"`
Experience int `json:"experience,omitempty"`
Sparks int `json:"sparks,omitempty"`
AvatarURL string `json:"avatarUrl,omitempty"`
Bio int `json:"bio,omitempty"`
PrimaryTeam int `json:"primaryTeam,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
DeletedAt int `json:"deletedAt,omitempty"`
Groups []struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
} `json:"groups,omitempty"`
Channel struct {
ID int `json:"id,omitempty"`
UserID int `json:"userId,omitempty"`
Token string `json:"token,omitempty"`
Online bool `json:"online,omitempty"`
Featured bool `json:"featured,omitempty"`
Partnered bool `json:"partnered,omitempty"`
TranscodingProfileID int `json:"transcodingProfileId,omitempty"`
Suspended bool `json:"suspended,omitempty"`
Name string `json:"name,omitempty"`
Audience string `json:"audience,omitempty"`
ViewersTotal int `json:"viewersTotal,omitempty"`
ViewersCurrent int `json:"viewersCurrent,omitempty"`
NumFollowers int `json:"numFollowers,omitempty"`
Description string `json:"description,omitempty"`
TypeID int `json:"typeId,omitempty"`
Interactive bool `json:"interactive,omitempty"`
TetrisGameID int `json:"tetrisGameId,omitempty"`
Ftl int `json:"ftl,omitempty"`
HasVod bool `json:"hasVod,omitempty"`
LanguageID int `json:"languageId,omitempty"`
CoverID int `json:"coverId,omitempty"`
ThumbnailID int `json:"thumbnailId,omitempty"`
BadgeID int `json:"badgeId,omitempty"`
HosteeID int `json:"hosteeId,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
DeletedAt int `json:"deletedAt,omitempty"`
} `json:"channel,omitempty"`
} `json:"user,omitempty"`
}
type VersionsResponse struct {
Controls struct {
ReportInterval int `json:"reportInterval,omitempty"`
Tactiles []struct {
ID int `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Blueprint []struct {
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Grid string `json:"grid,omitempty"`
State string `json:"state,omitempty"`
X int `json:"x,omitempty"`
Y int `json:"y,omitempty"`
} `json:"blueprint,omitempty"`
Analysis struct {
Holding bool `json:"holding,omitempty"`
Frequency bool `json:"frequency,omitempty"`
} `json:"analysis,omitempty"`
Cost struct {
Press struct {
Cost int `json:"cost,omitempty"`
} `json:"press,omitempty"`
} `json:"cost,omitempty"`
Cooldown struct {
Press int `json:"press,omitempty"`
} `json:"cooldown,omitempty"`
} `json:"tactiles,omitempty"`
Joysticks []struct {
ID int `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Blueprint []struct {
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Grid string `json:"grid,omitempty"`
State string `json:"state,omitempty"`
X int `json:"x,omitempty"`
Y int `json:"y,omitempty"`
} `json:"blueprint,omitempty"`
Analysis struct {
Coords struct {
Mean bool `json:"mean,omitempty"`
StdDev bool `json:"stdDev,omitempty"`
} `json:"coords,omitempty"`
} `json:"analysis,omitempty"`
} `json:"joysticks,omitempty"`
Screens []struct {
ID int `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Blueprint []struct {
State string `json:"state,omitempty"`
} `json:"blueprint,omitempty"`
Analysis struct {
Position struct {
Mean bool `json:"mean,omitempty"`
StdDev bool `json:"stdDev,omitempty"`
} `json:"position,omitempty"`
Clicks bool `json:"clicks,omitempty"`
} `json:"analysis,omitempty"`
} `json:"screens,omitempty"`
} `json:"controls,omitempty"`
ID int `json:"id,omitempty"`
GameID int `json:"gameId,omitempty"`
Version string `json:"version,omitempty"`
VersionOrder int `json:"versionOrder,omitempty"`
Changelog string `json:"changelog,omitempty"`
State string `json:"state,omitempty"`
Installation int `json:"installation,omitempty"`
Download int `json:"download,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
Game struct {
ID int `json:"id,omitempty"`
OwnerID int `json:"ownerId,omitempty"`
Name string `json:"name,omitempty"`
CoverURL int `json:"coverUrl,omitempty"`
Description int `json:"description,omitempty"`
HasPublishedVersions bool `json:"hasPublishedVersions,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
Installation int `json:"installation,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
DeletedAt int `json:"deletedAt,omitempty"`
} `json:"game,omitempty"`
}
//When a timeout event is received
type UserTimeout struct {
User User `json:"user"`
Duration int
}
// A State contains the current known state.
// As Beam sends this in a READY blob, it seems reasonable to simply
// use that struct as the data store.
type State struct {
sync.RWMutex
// Ready
MaxMessageCount int
}