-
Notifications
You must be signed in to change notification settings - Fork 4
/
conn.go
803 lines (677 loc) · 30.3 KB
/
conn.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
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
package twitch
import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/coder/websocket"
)
const (
twitchWebsocketUrl = "wss://eventsub.wss.twitch.tv/ws"
)
var (
ErrConnClosed = fmt.Errorf("connection closed")
ErrNilOnWelcome = fmt.Errorf("OnWelcome function was not set")
messageTypeMap = map[string]func() any{
"session_welcome": zeroPtrGen[WelcomeMessage](),
"session_keepalive": zeroPtrGen[KeepAliveMessage](),
"notification": zeroPtrGen[NotificationMessage](),
"session_reconnect": zeroPtrGen[ReconnectMessage](),
"revocation": zeroPtrGen[RevokeMessage](),
}
)
func zeroPtrGen[T any]() func() any {
return func() any {
return new(T)
}
}
func callFunc[T any](f func(T), v T) {
if f != nil {
go f(v)
}
}
type Client struct {
Address string
ws *websocket.Conn
connected bool
ctx context.Context
reconnecting bool
reconnected chan struct{}
// Responses
onError func(err error)
onWelcome func(message WelcomeMessage)
onKeepAlive func(message KeepAliveMessage)
onNotification func(message NotificationMessage)
onReconnect func(message ReconnectMessage)
onRevoke func(message RevokeMessage)
// Events
onRawEvent func(event string, metadata MessageMetadata, subscription PayloadSubscription)
onEventChannelUpdate func(event EventChannelUpdate)
onEventChannelFollow func(event EventChannelFollow)
onEventChannelSubscribe func(event EventChannelSubscribe)
onEventChannelSubscriptionEnd func(event EventChannelSubscriptionEnd)
onEventChannelSubscriptionGift func(event EventChannelSubscriptionGift)
onEventChannelSubscriptionMessage func(event EventChannelSubscriptionMessage)
onEventChannelCheer func(event EventChannelCheer)
onEventChannelRaid func(event EventChannelRaid)
onEventChannelBan func(event EventChannelBan)
onEventChannelUnban func(event EventChannelUnban)
onEventChannelModeratorAdd func(event EventChannelModeratorAdd)
onEventChannelModeratorRemove func(event EventChannelModeratorRemove)
onEventChannelVIPAdd func(event EventChannelVIPAdd)
onEventChannelVIPRemove func(event EventChannelVIPRemove)
onEventChannelChannelPointsCustomRewardAdd func(event EventChannelChannelPointsCustomRewardAdd)
onEventChannelChannelPointsCustomRewardUpdate func(event EventChannelChannelPointsCustomRewardUpdate)
onEventChannelChannelPointsCustomRewardRemove func(event EventChannelChannelPointsCustomRewardRemove)
onEventChannelChannelPointsCustomRewardRedemptionAdd func(event EventChannelChannelPointsCustomRewardRedemptionAdd)
onEventChannelChannelPointsCustomRewardRedemptionUpdate func(event EventChannelChannelPointsCustomRewardRedemptionUpdate)
onEventChannelChannelPointsAutomaticRewardRedemptionAdd func(event EventChannelChannelPointsAutomaticRewardRedemptionAdd)
onEventChannelPollBegin func(event EventChannelPollBegin)
onEventChannelPollProgress func(event EventChannelPollProgress)
onEventChannelPollEnd func(event EventChannelPollEnd)
onEventChannelPredictionBegin func(event EventChannelPredictionBegin)
onEventChannelPredictionProgress func(event EventChannelPredictionProgress)
onEventChannelPredictionLock func(event EventChannelPredictionLock)
onEventChannelPredictionEnd func(event EventChannelPredictionEnd)
onEventDropEntitlementGrant func(event []EventDropEntitlementGrant)
onEventExtensionBitsTransactionCreate func(event EventExtensionBitsTransactionCreate)
onEventChannelGoalBegin func(event EventChannelGoalBegin)
onEventChannelGoalProgress func(event EventChannelGoalProgress)
onEventChannelGoalEnd func(event EventChannelGoalEnd)
onEventChannelHypeTrainBegin func(event EventChannelHypeTrainBegin)
onEventChannelHypeTrainProgress func(event EventChannelHypeTrainProgress)
onEventChannelHypeTrainEnd func(event EventChannelHypeTrainEnd)
onEventStreamOnline func(event EventStreamOnline)
onEventStreamOffline func(event EventStreamOffline)
onEventUserAuthorizationGrant func(event EventUserAuthorizationGrant)
onEventUserAuthorizationRevoke func(event EventUserAuthorizationRevoke)
onEventUserUpdate func(event EventUserUpdate)
onEventChannelCharityCampaignDonate func(event EventChannelCharityCampaignDonate)
onEventChannelCharityCampaignProgress func(event EventChannelCharityCampaignProgress)
onEventChannelCharityCampaignStart func(event EventChannelCharityCampaignStart)
onEventChannelCharityCampaignStop func(event EventChannelCharityCampaignStop)
onEventChannelShieldModeBegin func(event EventChannelShieldModeBegin)
onEventChannelShieldModeEnd func(event EventChannelShieldModeEnd)
onEventChannelShoutoutCreate func(event EventChannelShoutoutCreate)
onEventChannelShoutoutReceive func(event EventChannelShoutoutReceive)
onEventChannelModerate func(event EventChannelModerate)
onEventAutomodMessageHold func(event EventAutomodMessageHold)
onEventAutomodMessageUpdate func(event EventAutomodMessageUpdate)
onEventAutomodSettingsUpdate func(event EventAutomodSettingsUpdate)
onEventAutomodTermsUpdate func(event EventAutomodTermsUpdate)
onEventChannelChatUserMessageHold func(event EventChannelChatUserMessageHold)
onEventChannelChatUserMessageUpdate func(event EventChannelChatUserMessageUpdate)
onEventChannelChatClear func(event EventChannelChatClear)
onEventChannelChatClearUserMessages func(event EventChannelChatClearUserMessages)
onEventChannelChatMessage func(event EventChannelChatMessage)
onEventChannelChatMessageDelete func(event EventChannelChatMessageDelete)
onEventChannelChatNotification func(event EventChannelChatNotification)
onEventChannelChatSettingsUpdate func(event EventChannelChatSettingsUpdate)
onEventChannelSuspiciousUserMessage func(event EventChannelSuspiciousUserMessage)
onEventChannelSuspiciousUserUpdate func(event EventChannelSuspiciousUserUpdate)
onEventChannelSharedChatBegin func(event EventChannelSharedChatBegin)
onEventChannelSharedChatUpdate func(event EventChannelSharedChatUpdate)
onEventChannelSharedChatEnd func(event EventChannelSharedChatEnd)
onEventUserWhisperMessage func(event EventUserWhisperMessage)
onEventChannelAdBreakBegin func(event EventChannelAdBreakBegin)
onEventChannelWarningAcknowledge func(event EventChannelWarningAcknowledge)
onEventChannelWarningSend func(event EventChannelWarningSend)
onEventChannelUnbanRequestCreate func(event EventChannelUnbanRequestCreate)
onEventChannelUnbanRequestResolve func(event EventChannelUnbanRequestResolve)
onEventConduitShardDisabled func(event EventConduitShardDisabled)
}
func NewClient() *Client {
return NewClientWithUrl(twitchWebsocketUrl)
}
func NewClientWithUrl(url string) *Client {
return &Client{
Address: url,
reconnected: make(chan struct{}),
onError: func(err error) { fmt.Printf("ERROR: %v\n", err) },
}
}
func (c *Client) Connect() error {
return c.ConnectWithContext(context.Background())
}
func (c *Client) ConnectWithContext(ctx context.Context) error {
if c.onWelcome == nil {
return ErrNilOnWelcome
}
c.ctx = ctx
ws, err := c.dial()
if err != nil {
return err
}
c.ws = ws
c.connected = true
for {
_, data, err := c.ws.Read(ctx)
if err != nil {
if errors.Is(err, context.Canceled) {
return nil
}
if websocket.CloseStatus(err) == websocket.StatusNormalClosure {
if c.reconnecting {
c.reconnecting = false
<-c.reconnected
continue
}
return nil
}
return fmt.Errorf("could not read message: %w", err)
}
err = c.handleMessage(data)
if err != nil {
c.onError(err)
}
}
}
func (c *Client) Close() error {
defer func() { c.ws = nil }()
if !c.connected {
return nil
}
c.connected = false
err := c.ws.Close(websocket.StatusNormalClosure, "Stopping Connection")
var closeError websocket.CloseError
if err != nil && !errors.As(err, &closeError) {
return fmt.Errorf("could not close websocket connection: %w", err)
}
return nil
}
func (c *Client) handleMessage(data []byte) error {
metadata, err := parseBaseMessage(data)
if err != nil {
return err
}
messageType := metadata.MessageType
genMessage, ok := messageTypeMap[messageType]
if !ok {
return fmt.Errorf("unknown message type %s: %s", messageType, string(data))
}
message := genMessage()
err = json.Unmarshal(data, message)
if err != nil {
return fmt.Errorf("could not unmarshal message into %s: %w", messageType, err)
}
switch msg := message.(type) {
case *WelcomeMessage:
callFunc(c.onWelcome, *msg)
case *KeepAliveMessage:
callFunc(c.onKeepAlive, *msg)
case *NotificationMessage:
callFunc(c.onNotification, *msg)
err = c.handleNotification(*msg)
if err != nil {
return fmt.Errorf("could not handle notification: %w", err)
}
case *ReconnectMessage:
callFunc(c.onReconnect, *msg)
err = c.reconnect(*msg)
if err != nil {
return fmt.Errorf("could not handle reconnect: %w", err)
}
case *RevokeMessage:
callFunc(c.onRevoke, *msg)
default:
return fmt.Errorf("unhandled %T message: %v", msg, msg)
}
return nil
}
func (c *Client) reconnect(message ReconnectMessage) error {
c.Address = message.Payload.Session.ReconnectUrl
ws, err := c.dial()
if err != nil {
return fmt.Errorf("could not dial to reconnect")
}
go func() {
_, data, err := ws.Read(c.ctx)
if err != nil {
c.onError(fmt.Errorf("reconnect failed: could not read reconnect websocket for welcome: %w", err))
}
metadata, err := parseBaseMessage(data)
if err != nil {
c.onError(fmt.Errorf("reconnect failed: could parse base message: %w", err))
}
if metadata.MessageType != "session_welcome" {
c.onError(fmt.Errorf("reconnect failed: did not get a session_welcome message first: got message %s", metadata.MessageType))
return
}
c.reconnecting = true
c.ws.Close(websocket.StatusNormalClosure, "Stopping Connection")
c.ws = ws
c.reconnected <- struct{}{}
}()
return nil
}
func (c *Client) handleNotification(message NotificationMessage) error {
data, err := message.Payload.Event.MarshalJSON()
if err != nil {
return fmt.Errorf("could not get event json: %w", err)
}
subscription := message.Payload.Subscription
metadata, ok := subMetadata[subscription.Type]
if !ok {
return fmt.Errorf("unknown subscription type %s", subscription.Type)
}
if c.onRawEvent != nil {
c.onRawEvent(string(data), message.Metadata, subscription)
}
var newEvent any
if metadata.EventGen != nil {
newEvent = metadata.EventGen()
err = json.Unmarshal(data, newEvent)
if err != nil {
return fmt.Errorf("could not unmarshal %s into %T: %w", subscription.Type, newEvent, err)
}
}
switch event := newEvent.(type) {
case *EventChannelUpdate:
callFunc(c.onEventChannelUpdate, *event)
case *EventChannelFollow:
callFunc(c.onEventChannelFollow, *event)
case *EventChannelSubscribe:
callFunc(c.onEventChannelSubscribe, *event)
case *EventChannelSubscriptionEnd:
callFunc(c.onEventChannelSubscriptionEnd, *event)
case *EventChannelSubscriptionGift:
callFunc(c.onEventChannelSubscriptionGift, *event)
case *EventChannelSubscriptionMessage:
callFunc(c.onEventChannelSubscriptionMessage, *event)
case *EventChannelCheer:
callFunc(c.onEventChannelCheer, *event)
case *EventChannelRaid:
callFunc(c.onEventChannelRaid, *event)
case *EventChannelBan:
callFunc(c.onEventChannelBan, *event)
case *EventChannelUnban:
callFunc(c.onEventChannelUnban, *event)
case *EventChannelModeratorAdd:
callFunc(c.onEventChannelModeratorAdd, *event)
case *EventChannelModeratorRemove:
callFunc(c.onEventChannelModeratorRemove, *event)
case *EventChannelVIPAdd:
callFunc(c.onEventChannelVIPAdd, *event)
case *EventChannelVIPRemove:
callFunc(c.onEventChannelVIPRemove, *event)
case *EventChannelChannelPointsCustomRewardAdd:
callFunc(c.onEventChannelChannelPointsCustomRewardAdd, *event)
case *EventChannelChannelPointsCustomRewardUpdate:
callFunc(c.onEventChannelChannelPointsCustomRewardUpdate, *event)
case *EventChannelChannelPointsCustomRewardRemove:
callFunc(c.onEventChannelChannelPointsCustomRewardRemove, *event)
case *EventChannelChannelPointsCustomRewardRedemptionAdd:
callFunc(c.onEventChannelChannelPointsCustomRewardRedemptionAdd, *event)
case *EventChannelChannelPointsCustomRewardRedemptionUpdate:
callFunc(c.onEventChannelChannelPointsCustomRewardRedemptionUpdate, *event)
case *EventChannelChannelPointsAutomaticRewardRedemptionAdd:
callFunc(c.onEventChannelChannelPointsAutomaticRewardRedemptionAdd, *event)
case *EventChannelPollBegin:
callFunc(c.onEventChannelPollBegin, *event)
case *EventChannelPollProgress:
callFunc(c.onEventChannelPollProgress, *event)
case *EventChannelPollEnd:
callFunc(c.onEventChannelPollEnd, *event)
case *EventChannelPredictionBegin:
callFunc(c.onEventChannelPredictionBegin, *event)
case *EventChannelPredictionProgress:
callFunc(c.onEventChannelPredictionProgress, *event)
case *EventChannelPredictionLock:
callFunc(c.onEventChannelPredictionLock, *event)
case *EventChannelPredictionEnd:
callFunc(c.onEventChannelPredictionEnd, *event)
case *[]EventDropEntitlementGrant:
callFunc(c.onEventDropEntitlementGrant, *event)
case *EventExtensionBitsTransactionCreate:
callFunc(c.onEventExtensionBitsTransactionCreate, *event)
case *EventChannelGoalBegin:
callFunc(c.onEventChannelGoalBegin, *event)
case *EventChannelGoalProgress:
callFunc(c.onEventChannelGoalProgress, *event)
case *EventChannelGoalEnd:
callFunc(c.onEventChannelGoalEnd, *event)
case *EventChannelHypeTrainBegin:
callFunc(c.onEventChannelHypeTrainBegin, *event)
case *EventChannelHypeTrainProgress:
callFunc(c.onEventChannelHypeTrainProgress, *event)
case *EventChannelHypeTrainEnd:
callFunc(c.onEventChannelHypeTrainEnd, *event)
case *EventStreamOnline:
callFunc(c.onEventStreamOnline, *event)
case *EventStreamOffline:
callFunc(c.onEventStreamOffline, *event)
case *EventUserAuthorizationGrant:
callFunc(c.onEventUserAuthorizationGrant, *event)
case *EventUserAuthorizationRevoke:
callFunc(c.onEventUserAuthorizationRevoke, *event)
case *EventUserUpdate:
callFunc(c.onEventUserUpdate, *event)
case *EventChannelCharityCampaignDonate:
callFunc(c.onEventChannelCharityCampaignDonate, *event)
case *EventChannelCharityCampaignProgress:
callFunc(c.onEventChannelCharityCampaignProgress, *event)
case *EventChannelCharityCampaignStart:
callFunc(c.onEventChannelCharityCampaignStart, *event)
case *EventChannelCharityCampaignStop:
callFunc(c.onEventChannelCharityCampaignStop, *event)
case *EventChannelShieldModeBegin:
callFunc(c.onEventChannelShieldModeBegin, *event)
case *EventChannelShieldModeEnd:
callFunc(c.onEventChannelShieldModeEnd, *event)
case *EventChannelShoutoutCreate:
callFunc(c.onEventChannelShoutoutCreate, *event)
case *EventChannelShoutoutReceive:
callFunc(c.onEventChannelShoutoutReceive, *event)
case *EventChannelModerate:
callFunc(c.onEventChannelModerate, *event)
case *EventAutomodMessageHold:
callFunc(c.onEventAutomodMessageHold, *event)
case *EventAutomodMessageUpdate:
callFunc(c.onEventAutomodMessageUpdate, *event)
case *EventAutomodSettingsUpdate:
callFunc(c.onEventAutomodSettingsUpdate, *event)
case *EventAutomodTermsUpdate:
callFunc(c.onEventAutomodTermsUpdate, *event)
case *EventChannelChatUserMessageHold:
callFunc(c.onEventChannelChatUserMessageHold, *event)
case *EventChannelChatUserMessageUpdate:
callFunc(c.onEventChannelChatUserMessageUpdate, *event)
case *EventChannelChatClear:
callFunc(c.onEventChannelChatClear, *event)
case *EventChannelChatClearUserMessages:
callFunc(c.onEventChannelChatClearUserMessages, *event)
case *EventChannelChatMessage:
callFunc(c.onEventChannelChatMessage, *event)
case *EventChannelChatMessageDelete:
callFunc(c.onEventChannelChatMessageDelete, *event)
case *EventChannelChatNotification:
callFunc(c.onEventChannelChatNotification, *event)
case *EventChannelChatSettingsUpdate:
callFunc(c.onEventChannelChatSettingsUpdate, *event)
case *EventChannelSuspiciousUserMessage:
callFunc(c.onEventChannelSuspiciousUserMessage, *event)
case *EventChannelSuspiciousUserUpdate:
callFunc(c.onEventChannelSuspiciousUserUpdate, *event)
case *EventChannelSharedChatBegin:
callFunc(c.onEventChannelSharedChatBegin, *event)
case *EventChannelSharedChatUpdate:
callFunc(c.onEventChannelSharedChatUpdate, *event)
case *EventChannelSharedChatEnd:
callFunc(c.onEventChannelSharedChatEnd, *event)
case *EventUserWhisperMessage:
callFunc(c.onEventUserWhisperMessage, *event)
case *EventChannelAdBreakBegin:
callFunc(c.onEventChannelAdBreakBegin, *event)
case *EventChannelWarningAcknowledge:
callFunc(c.onEventChannelWarningAcknowledge, *event)
case *EventChannelWarningSend:
callFunc(c.onEventChannelWarningSend, *event)
case *EventChannelUnbanRequestCreate:
callFunc(c.onEventChannelUnbanRequestCreate, *event)
case *EventChannelUnbanRequestResolve:
callFunc(c.onEventChannelUnbanRequestResolve, *event)
case *EventConduitShardDisabled:
callFunc(c.onEventConduitShardDisabled, *event)
default:
c.onError(fmt.Errorf("unknown event type %s", subscription.Type))
}
return nil
}
func (c *Client) dial() (*websocket.Conn, error) {
ws, _, err := websocket.Dial(c.ctx, c.Address, nil)
if err != nil {
return nil, fmt.Errorf("could not dial %s: %w", c.Address, err)
}
return ws, nil
}
func parseBaseMessage(data []byte) (MessageMetadata, error) {
type BaseMessage struct {
Metadata MessageMetadata `json:"metadata"`
}
var baseMessage BaseMessage
err := json.Unmarshal(data, &baseMessage)
if err != nil {
return MessageMetadata{}, fmt.Errorf("could not unmarshal basemessage to get message type: %w", err)
}
return baseMessage.Metadata, nil
}
func (c *Client) OnError(callback func(err error)) {
c.onError = callback
}
func (c *Client) OnWelcome(callback func(message WelcomeMessage)) {
c.onWelcome = callback
}
func (c *Client) OnKeepAlive(callback func(message KeepAliveMessage)) {
c.onKeepAlive = callback
}
func (c *Client) OnNotification(callback func(message NotificationMessage)) {
c.onNotification = callback
}
func (c *Client) OnReconnect(callback func(message ReconnectMessage)) {
c.onReconnect = callback
}
func (c *Client) OnRevoke(callback func(message RevokeMessage)) {
c.onRevoke = callback
}
func (c *Client) OnRawEvent(callback func(event string, metadata MessageMetadata, subscription PayloadSubscription)) {
c.onRawEvent = callback
}
func (c *Client) OnEventChannelUpdate(callback func(event EventChannelUpdate)) {
c.onEventChannelUpdate = callback
}
func (c *Client) OnEventChannelFollow(callback func(event EventChannelFollow)) {
c.onEventChannelFollow = callback
}
func (c *Client) OnEventChannelSubscribe(callback func(event EventChannelSubscribe)) {
c.onEventChannelSubscribe = callback
}
func (c *Client) OnEventChannelSubscriptionEnd(callback func(event EventChannelSubscriptionEnd)) {
c.onEventChannelSubscriptionEnd = callback
}
func (c *Client) OnEventChannelSubscriptionGift(callback func(event EventChannelSubscriptionGift)) {
c.onEventChannelSubscriptionGift = callback
}
func (c *Client) OnEventChannelSubscriptionMessage(callback func(event EventChannelSubscriptionMessage)) {
c.onEventChannelSubscriptionMessage = callback
}
func (c *Client) OnEventChannelCheer(callback func(event EventChannelCheer)) {
c.onEventChannelCheer = callback
}
func (c *Client) OnEventChannelRaid(callback func(event EventChannelRaid)) {
c.onEventChannelRaid = callback
}
func (c *Client) OnEventChannelBan(callback func(event EventChannelBan)) {
c.onEventChannelBan = callback
}
func (c *Client) OnEventChannelUnban(callback func(event EventChannelUnban)) {
c.onEventChannelUnban = callback
}
func (c *Client) OnEventChannelModeratorAdd(callback func(event EventChannelModeratorAdd)) {
c.onEventChannelModeratorAdd = callback
}
func (c *Client) OnEventChannelModeratorRemove(callback func(event EventChannelModeratorRemove)) {
c.onEventChannelModeratorRemove = callback
}
func (c *Client) OnEventChannelVIPAdd(callback func(event EventChannelVIPAdd)) {
c.onEventChannelVIPAdd = callback
}
func (c *Client) OnEventChannelVIPRemove(callback func(event EventChannelVIPRemove)) {
c.onEventChannelVIPRemove = callback
}
func (c *Client) OnEventChannelChannelPointsCustomRewardAdd(callback func(event EventChannelChannelPointsCustomRewardAdd)) {
c.onEventChannelChannelPointsCustomRewardAdd = callback
}
func (c *Client) OnEventChannelChannelPointsCustomRewardUpdate(callback func(event EventChannelChannelPointsCustomRewardUpdate)) {
c.onEventChannelChannelPointsCustomRewardUpdate = callback
}
func (c *Client) OnEventChannelChannelPointsCustomRewardRemove(callback func(event EventChannelChannelPointsCustomRewardRemove)) {
c.onEventChannelChannelPointsCustomRewardRemove = callback
}
func (c *Client) OnEventChannelChannelPointsCustomRewardRedemptionAdd(callback func(event EventChannelChannelPointsCustomRewardRedemptionAdd)) {
c.onEventChannelChannelPointsCustomRewardRedemptionAdd = callback
}
func (c *Client) OnEventChannelChannelPointsCustomRewardRedemptionUpdate(callback func(event EventChannelChannelPointsCustomRewardRedemptionUpdate)) {
c.onEventChannelChannelPointsCustomRewardRedemptionUpdate = callback
}
func (c *Client) OnEventChannelChannelPointsAutomaticRewardRedemptionAdd(callback func(event EventChannelChannelPointsAutomaticRewardRedemptionAdd)) {
c.onEventChannelChannelPointsAutomaticRewardRedemptionAdd = callback
}
func (c *Client) OnEventChannelPollBegin(callback func(event EventChannelPollBegin)) {
c.onEventChannelPollBegin = callback
}
func (c *Client) OnEventChannelPollProgress(callback func(event EventChannelPollProgress)) {
c.onEventChannelPollProgress = callback
}
func (c *Client) OnEventChannelPollEnd(callback func(event EventChannelPollEnd)) {
c.onEventChannelPollEnd = callback
}
func (c *Client) OnEventChannelPredictionBegin(callback func(event EventChannelPredictionBegin)) {
c.onEventChannelPredictionBegin = callback
}
func (c *Client) OnEventChannelPredictionProgress(callback func(event EventChannelPredictionProgress)) {
c.onEventChannelPredictionProgress = callback
}
func (c *Client) OnEventChannelPredictionLock(callback func(event EventChannelPredictionLock)) {
c.onEventChannelPredictionLock = callback
}
func (c *Client) OnEventChannelPredictionEnd(callback func(event EventChannelPredictionEnd)) {
c.onEventChannelPredictionEnd = callback
}
func (c *Client) OnEventDropEntitlementGrant(callback func(event []EventDropEntitlementGrant)) {
c.onEventDropEntitlementGrant = callback
}
func (c *Client) OnEventExtensionBitsTransactionCreate(callback func(event EventExtensionBitsTransactionCreate)) {
c.onEventExtensionBitsTransactionCreate = callback
}
func (c *Client) OnEventChannelGoalBegin(callback func(event EventChannelGoalBegin)) {
c.onEventChannelGoalBegin = callback
}
func (c *Client) OnEventChannelGoalProgress(callback func(event EventChannelGoalProgress)) {
c.onEventChannelGoalProgress = callback
}
func (c *Client) OnEventChannelGoalEnd(callback func(event EventChannelGoalEnd)) {
c.onEventChannelGoalEnd = callback
}
func (c *Client) OnEventChannelHypeTrainBegin(callback func(event EventChannelHypeTrainBegin)) {
c.onEventChannelHypeTrainBegin = callback
}
func (c *Client) OnEventChannelHypeTrainProgress(callback func(event EventChannelHypeTrainProgress)) {
c.onEventChannelHypeTrainProgress = callback
}
func (c *Client) OnEventChannelHypeTrainEnd(callback func(event EventChannelHypeTrainEnd)) {
c.onEventChannelHypeTrainEnd = callback
}
func (c *Client) OnEventStreamOnline(callback func(event EventStreamOnline)) {
c.onEventStreamOnline = callback
}
func (c *Client) OnEventStreamOffline(callback func(event EventStreamOffline)) {
c.onEventStreamOffline = callback
}
func (c *Client) OnEventUserAuthorizationGrant(callback func(event EventUserAuthorizationGrant)) {
c.onEventUserAuthorizationGrant = callback
}
func (c *Client) OnEventUserAuthorizationRevoke(callback func(event EventUserAuthorizationRevoke)) {
c.onEventUserAuthorizationRevoke = callback
}
func (c *Client) OnEventUserUpdate(callback func(event EventUserUpdate)) {
c.onEventUserUpdate = callback
}
func (c *Client) OnEventChannelCharityCampaignDonate(callback func(event EventChannelCharityCampaignDonate)) {
c.onEventChannelCharityCampaignDonate = callback
}
func (c *Client) OnEventChannelCharityCampaignProgress(callback func(event EventChannelCharityCampaignProgress)) {
c.onEventChannelCharityCampaignProgress = callback
}
func (c *Client) OnEventChannelCharityCampaignStart(callback func(event EventChannelCharityCampaignStart)) {
c.onEventChannelCharityCampaignStart = callback
}
func (c *Client) OnEventChannelCharityCampaignStop(callback func(event EventChannelCharityCampaignStop)) {
c.onEventChannelCharityCampaignStop = callback
}
func (c *Client) OnEventChannelShieldModeBegin(callback func(event EventChannelShieldModeBegin)) {
c.onEventChannelShieldModeBegin = callback
}
func (c *Client) OnEventChannelShieldModeEnd(callback func(event EventChannelShieldModeEnd)) {
c.onEventChannelShieldModeEnd = callback
}
func (c *Client) OnEventChannelShoutoutCreate(callback func(event EventChannelShoutoutCreate)) {
c.onEventChannelShoutoutCreate = callback
}
func (c *Client) OnEventChannelShoutoutReceive(callback func(event EventChannelShoutoutReceive)) {
c.onEventChannelShoutoutReceive = callback
}
func (c *Client) OnEventChannelModerate(callback func(event EventChannelModerate)) {
c.onEventChannelModerate = callback
}
func (c *Client) OnEventAutomodMessageHold(callback func(event EventAutomodMessageHold)) {
c.onEventAutomodMessageHold = callback
}
func (c *Client) OnEventAutomodMessageUpdate(callback func(event EventAutomodMessageUpdate)) {
c.onEventAutomodMessageUpdate = callback
}
func (c *Client) OnEventAutomodSettingsUpdate(callback func(event EventAutomodSettingsUpdate)) {
c.onEventAutomodSettingsUpdate = callback
}
func (c *Client) OnEventAutomodTermsUpdate(callback func(event EventAutomodTermsUpdate)) {
c.onEventAutomodTermsUpdate = callback
}
func (c *Client) OnEventChannelChatUserMessageHold(callback func(event EventChannelChatUserMessageHold)) {
c.onEventChannelChatUserMessageHold = callback
}
func (c *Client) OnEventChannelChatUserMessageUpdate(callback func(event EventChannelChatUserMessageUpdate)) {
c.onEventChannelChatUserMessageUpdate = callback
}
func (c *Client) OnEventChannelChatClear(callback func(event EventChannelChatClear)) {
c.onEventChannelChatClear = callback
}
func (c *Client) OnEventChannelChatClearUserMessages(callback func(event EventChannelChatClearUserMessages)) {
c.onEventChannelChatClearUserMessages = callback
}
func (c *Client) OnEventChannelChatMessage(callback func(event EventChannelChatMessage)) {
c.onEventChannelChatMessage = callback
}
func (c *Client) OnEventChannelChatMessageDelete(callback func(event EventChannelChatMessageDelete)) {
c.onEventChannelChatMessageDelete = callback
}
func (c *Client) OnEventChannelChatNotification(callback func(event EventChannelChatNotification)) {
c.onEventChannelChatNotification = callback
}
func (c *Client) OnEventChannelChatSettingsUpdate(callback func(event EventChannelChatSettingsUpdate)) {
c.onEventChannelChatSettingsUpdate = callback
}
func (c *Client) OnEventChannelSuspiciousUserMessage(callback func(event EventChannelSuspiciousUserMessage)) {
c.onEventChannelSuspiciousUserMessage = callback
}
func (c *Client) OnEventChannelSuspiciousUserUpdate(callback func(event EventChannelSuspiciousUserUpdate)) {
c.onEventChannelSuspiciousUserUpdate = callback
}
func (c *Client) OnEventChannelSharedChatBegin(callback func(event EventChannelSharedChatBegin)) {
c.onEventChannelSharedChatBegin = callback
}
func (c *Client) OnEventChannelSharedChatUpdate(callback func(event EventChannelSharedChatUpdate)) {
c.onEventChannelSharedChatUpdate = callback
}
func (c *Client) OnEventChannelSharedChatEnd(callback func(event EventChannelSharedChatEnd)) {
c.onEventChannelSharedChatEnd = callback
}
func (c *Client) OnEventUserWhisperMessage(callback func(event EventUserWhisperMessage)) {
c.onEventUserWhisperMessage = callback
}
func (c *Client) OnEventChannelAdBreakBegin(callback func(event EventChannelAdBreakBegin)) {
c.onEventChannelAdBreakBegin = callback
}
func (c *Client) OnEventChannelWarningAcknowledge(callback func(event EventChannelWarningAcknowledge)) {
c.onEventChannelWarningAcknowledge = callback
}
func (c *Client) OnEventChannelWarningSend(callback func(event EventChannelWarningSend)) {
c.onEventChannelWarningSend = callback
}
func (c *Client) OnEventChannelUnbanRequestCreate(callback func(event EventChannelUnbanRequestCreate)) {
c.onEventChannelUnbanRequestCreate = callback
}
func (c *Client) OnEventChannelUnbanRequestResolve(callback func(event EventChannelUnbanRequestResolve)) {
c.onEventChannelUnbanRequestResolve = callback
}
func (c *Client) OnEventConduitShardDisabled(callback func(event EventConduitShardDisabled)) {
c.onEventConduitShardDisabled = callback
}