barbed 0.0.3

Twitch Helix, EventSub, OAuth, IRC, and provider helpers
Documentation
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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
// @generated by tools/twitch_surface.py. DO NOT EDIT BY HAND.
#![allow(dead_code)]
use std::collections::BTreeMap;

use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

use super::{
    EndpointStability, EventSubChatMessage, EventSubChatMessageDeleted,
    EventSubSubscriptionDefinition,
};

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct GenericEventSubPayload {
    #[serde(flatten)]
    pub fields: BTreeMap<String, serde_json::Value>,
    #[serde(skip)]
    pub source_timestamp: Option<OffsetDateTime>,
}

pub type AutomodMessageHold1Event = GenericEventSubPayload;
pub type AutomodMessageHold2Event = GenericEventSubPayload;
pub type AutomodMessageUpdate1Event = GenericEventSubPayload;
pub type AutomodMessageUpdate2Event = GenericEventSubPayload;
pub type AutomodSettingsUpdate1Event = GenericEventSubPayload;
pub type AutomodTermsUpdate1Event = GenericEventSubPayload;
pub type ChannelBitsUse1Event = GenericEventSubPayload;
pub type ChannelUpdate2Event = GenericEventSubPayload;
pub type ChannelFollow2Event = GenericEventSubPayload;
pub type ChannelAdBreakBegin1Event = GenericEventSubPayload;
pub type ChannelChatClear1Event = GenericEventSubPayload;
pub type ChannelChatClearUserMessages1Event = GenericEventSubPayload;
pub type ChannelChatMessage1Event = GenericEventSubPayload;
pub type ChannelChatMessageDelete1Event = GenericEventSubPayload;
pub type ChannelChatNotification1Event = GenericEventSubPayload;
pub type ChannelChatSettingsUpdate1Event = GenericEventSubPayload;
pub type ChannelChatUserMessageHold1Event = GenericEventSubPayload;
pub type ChannelChatUserMessageUpdate1Event = GenericEventSubPayload;
pub type ChannelSharedChatBegin1Event = GenericEventSubPayload;
pub type ChannelSharedChatUpdate1Event = GenericEventSubPayload;
pub type ChannelSharedChatEnd1Event = GenericEventSubPayload;
pub type ChannelSubscribe1Event = GenericEventSubPayload;
pub type ChannelSubscriptionEnd1Event = GenericEventSubPayload;
pub type ChannelSubscriptionGift1Event = GenericEventSubPayload;
pub type ChannelSubscriptionMessage1Event = GenericEventSubPayload;
pub type ChannelCheer1Event = GenericEventSubPayload;
pub type ChannelRaid1Event = GenericEventSubPayload;
pub type ChannelBan1Event = GenericEventSubPayload;
pub type ChannelUnban1Event = GenericEventSubPayload;
pub type ChannelModerate1Event = GenericEventSubPayload;
pub type ChannelModerate2Event = GenericEventSubPayload;
pub type ChannelModeratorAdd1Event = GenericEventSubPayload;
pub type ChannelModeratorRemove1Event = GenericEventSubPayload;
pub type ChannelGuestStarSessionBeginBetaEvent = GenericEventSubPayload;
pub type ChannelGuestStarSessionEndBetaEvent = GenericEventSubPayload;
pub type ChannelGuestStarGuestUpdateBetaEvent = GenericEventSubPayload;
pub type ChannelGuestStarSettingsUpdateBetaEvent = GenericEventSubPayload;
pub type ChannelChannelPointsAutomaticRewardRedemptionAdd1Event = GenericEventSubPayload;
pub type ChannelChannelPointsAutomaticRewardRedemptionAdd2Event = GenericEventSubPayload;
pub type ChannelChannelPointsCustomRewardAdd1Event = GenericEventSubPayload;
pub type ChannelChannelPointsCustomRewardUpdate1Event = GenericEventSubPayload;
pub type ChannelChannelPointsCustomRewardRemove1Event = GenericEventSubPayload;
pub type ChannelChannelPointsCustomRewardRedemptionAdd1Event = GenericEventSubPayload;
pub type ChannelChannelPointsCustomRewardRedemptionUpdate1Event = GenericEventSubPayload;
pub type ChannelPollBegin1Event = GenericEventSubPayload;
pub type ChannelPollProgress1Event = GenericEventSubPayload;
pub type ChannelPollEnd1Event = GenericEventSubPayload;
pub type ChannelPredictionBegin1Event = GenericEventSubPayload;
pub type ChannelPredictionProgress1Event = GenericEventSubPayload;
pub type ChannelPredictionLock1Event = GenericEventSubPayload;
pub type ChannelPredictionEnd1Event = GenericEventSubPayload;
pub type ChannelSuspiciousUserMessage1Event = GenericEventSubPayload;
pub type ChannelSuspiciousUserUpdate1Event = GenericEventSubPayload;
pub type ChannelVipAdd1Event = GenericEventSubPayload;
pub type ChannelVipRemove1Event = GenericEventSubPayload;
pub type ChannelWarningAcknowledge1Event = GenericEventSubPayload;
pub type ChannelWarningSend1Event = GenericEventSubPayload;
pub type ChannelCharityCampaignDonate1Event = GenericEventSubPayload;
pub type ChannelCharityCampaignStart1Event = GenericEventSubPayload;
pub type ChannelCharityCampaignProgress1Event = GenericEventSubPayload;
pub type ChannelCharityCampaignStop1Event = GenericEventSubPayload;
pub type ConduitShardDisabled1Event = GenericEventSubPayload;
pub type DropEntitlementGrant1Event = GenericEventSubPayload;
pub type ExtensionBitsTransactionCreate1Event = GenericEventSubPayload;
pub type ChannelGoalBegin1Event = GenericEventSubPayload;
pub type ChannelGoalProgress1Event = GenericEventSubPayload;
pub type ChannelGoalEnd1Event = GenericEventSubPayload;
pub type ChannelHypeTrainBegin2Event = GenericEventSubPayload;
pub type ChannelHypeTrainProgress2Event = GenericEventSubPayload;
pub type ChannelHypeTrainEnd2Event = GenericEventSubPayload;
pub type ChannelShieldModeBegin1Event = GenericEventSubPayload;
pub type ChannelShieldModeEnd1Event = GenericEventSubPayload;
pub type ChannelShoutoutCreate1Event = GenericEventSubPayload;
pub type ChannelShoutoutReceive1Event = GenericEventSubPayload;
pub type StreamOnline1Event = GenericEventSubPayload;
pub type StreamOffline1Event = GenericEventSubPayload;
pub type UserAuthorizationGrant1Event = GenericEventSubPayload;
pub type UserAuthorizationRevoke1Event = GenericEventSubPayload;
pub type UserUpdate1Event = GenericEventSubPayload;
pub type UserWhisperMessage1Event = GenericEventSubPayload;

#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum KnownEventSubPayload {
    /// A user is notified if a message is caught by automod for review.
    AutomodMessageHold1(GenericEventSubPayload),
    /// A user is notified if a message is caught by automod for review. Only public blocked terms trigger notifications, not private ones.
    AutomodMessageHold2(GenericEventSubPayload),
    /// A message in the automod queue had its status changed.
    AutomodMessageUpdate1(GenericEventSubPayload),
    /// A message in the automod queue had its status changed. Only public blocked terms trigger notifications, not private ones.
    AutomodMessageUpdate2(GenericEventSubPayload),
    /// A notification is sent when a broadcaster’s automod settings are updated.
    AutomodSettingsUpdate1(GenericEventSubPayload),
    /// A notification is sent when a broadcaster’s automod terms are updated. Changes to private terms are not sent.
    AutomodTermsUpdate1(GenericEventSubPayload),
    /// A notification is sent whenever Bits are used on a channel.
    ChannelBitsUse1(GenericEventSubPayload),
    /// A broadcaster updates their channel properties e.g., category, title, content classification labels, broadcast, or language.
    ChannelUpdate2(GenericEventSubPayload),
    /// A specified channel receives a follow.
    ChannelFollow2(GenericEventSubPayload),
    /// A midroll commercial break has started running.
    ChannelAdBreakBegin1(GenericEventSubPayload),
    /// A moderator or bot has cleared all messages from the chat room.
    ChannelChatClear1(GenericEventSubPayload),
    /// A moderator or bot has cleared all messages from a specific user.
    ChannelChatClearUserMessages1(GenericEventSubPayload),
    /// Any user sends a message to a specific chat room.
    ChannelChatMessage1(EventSubChatMessage),
    /// A moderator has removed a specific message.
    ChannelChatMessageDelete1(EventSubChatMessageDeleted),
    /// A notification for when an event that appears in chat has occurred.
    ChannelChatNotification1(GenericEventSubPayload),
    /// A notification for when a broadcaster’s chat settings are updated.
    ChannelChatSettingsUpdate1(GenericEventSubPayload),
    /// A user is notified if their message is caught by automod.
    ChannelChatUserMessageHold1(GenericEventSubPayload),
    /// A user is notified if their message’s automod status is updated.
    ChannelChatUserMessageUpdate1(GenericEventSubPayload),
    /// A notification when a channel becomes active in an active shared chat session.
    ChannelSharedChatBegin1(GenericEventSubPayload),
    /// A notification when the active shared chat session the channel is in changes.
    ChannelSharedChatUpdate1(GenericEventSubPayload),
    /// A notification when a channel leaves a shared chat session or the session ends.
    ChannelSharedChatEnd1(GenericEventSubPayload),
    /// A notification is sent when a specified channel receives a subscriber. This does not include resubscribes.
    ChannelSubscribe1(GenericEventSubPayload),
    /// A notification when a subscription to the specified channel ends.
    ChannelSubscriptionEnd1(GenericEventSubPayload),
    /// A notification when a viewer gives a gift subscription to one or more users in the specified channel.
    ChannelSubscriptionGift1(GenericEventSubPayload),
    /// A notification when a user sends a resubscription chat message in a specific channel.
    ChannelSubscriptionMessage1(GenericEventSubPayload),
    /// A user cheers on the specified channel.
    ChannelCheer1(GenericEventSubPayload),
    /// A broadcaster raids another broadcaster’s channel.
    ChannelRaid1(GenericEventSubPayload),
    /// A viewer is banned from the specified channel.
    ChannelBan1(GenericEventSubPayload),
    /// A viewer is unbanned from the specified channel.
    ChannelUnban1(GenericEventSubPayload),
    /// A moderator performs a moderation action in a channel.
    ChannelModerate1(GenericEventSubPayload),
    /// A moderator performs a moderation action in a channel. Includes warnings.
    ChannelModerate2(GenericEventSubPayload),
    /// Moderator privileges were added to a user on a specified channel.
    ChannelModeratorAdd1(GenericEventSubPayload),
    /// Moderator privileges were removed from a user on a specified channel.
    ChannelModeratorRemove1(GenericEventSubPayload),
    /// The host began a new Guest Star session.
    ChannelGuestStarSessionBeginBeta(GenericEventSubPayload),
    /// A running Guest Star session has ended.
    ChannelGuestStarSessionEndBeta(GenericEventSubPayload),
    /// A guest or a slot is updated in an active Guest Star session.
    ChannelGuestStarGuestUpdateBeta(GenericEventSubPayload),
    /// The host preferences for Guest Star have been updated.
    ChannelGuestStarSettingsUpdateBeta(GenericEventSubPayload),
    /// A viewer has redeemed an automatic channel points reward on the specified channel.
    ChannelChannelPointsAutomaticRewardRedemptionAdd1(GenericEventSubPayload),
    /// A viewer has redeemed an automatic channel points reward on the specified channel.
    ChannelChannelPointsAutomaticRewardRedemptionAdd2(GenericEventSubPayload),
    /// A custom channel points reward has been created for the specified channel.
    ChannelChannelPointsCustomRewardAdd1(GenericEventSubPayload),
    /// A custom channel points reward has been updated for the specified channel.
    ChannelChannelPointsCustomRewardUpdate1(GenericEventSubPayload),
    /// A custom channel points reward has been removed from the specified channel.
    ChannelChannelPointsCustomRewardRemove1(GenericEventSubPayload),
    /// A viewer has redeemed a custom channel points reward on the specified channel.
    ChannelChannelPointsCustomRewardRedemptionAdd1(GenericEventSubPayload),
    /// A redemption of a channel points custom reward has been updated for the specified channel.
    ChannelChannelPointsCustomRewardRedemptionUpdate1(GenericEventSubPayload),
    /// A poll started on a specified channel.
    ChannelPollBegin1(GenericEventSubPayload),
    /// Users respond to a poll on a specified channel.
    ChannelPollProgress1(GenericEventSubPayload),
    /// A poll ended on a specified channel.
    ChannelPollEnd1(GenericEventSubPayload),
    /// A Prediction started on a specified channel.
    ChannelPredictionBegin1(GenericEventSubPayload),
    /// Users participated in a Prediction on a specified channel.
    ChannelPredictionProgress1(GenericEventSubPayload),
    /// A Prediction was locked on a specified channel.
    ChannelPredictionLock1(GenericEventSubPayload),
    /// A Prediction ended on a specified channel.
    ChannelPredictionEnd1(GenericEventSubPayload),
    /// A chat message has been sent by a suspicious user.
    ChannelSuspiciousUserMessage1(GenericEventSubPayload),
    /// A suspicious user has been updated.
    ChannelSuspiciousUserUpdate1(GenericEventSubPayload),
    /// A VIP is added to the channel.
    ChannelVipAdd1(GenericEventSubPayload),
    /// A VIP is removed from the channel.
    ChannelVipRemove1(GenericEventSubPayload),
    /// A user awknowledges a warning. Broadcasters and moderators can see the warning’s details.
    ChannelWarningAcknowledge1(GenericEventSubPayload),
    /// A user is sent a warning. Broadcasters and moderators can see the warning’s details.
    ChannelWarningSend1(GenericEventSubPayload),
    /// Sends an event notification when a user donates to the broadcaster’s charity campaign.
    ChannelCharityCampaignDonate1(GenericEventSubPayload),
    /// Sends an event notification when the broadcaster starts a charity campaign.
    ChannelCharityCampaignStart1(GenericEventSubPayload),
    /// Sends an event notification when progress is made towards the campaign’s goal or when the broadcaster changes the fundraising goal.
    ChannelCharityCampaignProgress1(GenericEventSubPayload),
    /// Sends an event notification when the broadcaster stops a charity campaign.
    ChannelCharityCampaignStop1(GenericEventSubPayload),
    /// Sends a notification when EventSub disables a shard due to the status of the underlying transport changing.
    ConduitShardDisabled1(GenericEventSubPayload),
    /// An entitlement for a Drop is granted to a user.
    DropEntitlementGrant1(GenericEventSubPayload),
    /// A Bits transaction occurred for a specified Twitch Extension.
    ExtensionBitsTransactionCreate1(GenericEventSubPayload),
    /// Get notified when a broadcaster begins a goal.
    ChannelGoalBegin1(GenericEventSubPayload),
    /// Get notified when progress (either positive or negative) is made towards a broadcaster’s goal.
    ChannelGoalProgress1(GenericEventSubPayload),
    /// Get notified when a broadcaster ends a goal.
    ChannelGoalEnd1(GenericEventSubPayload),
    /// A Hype Train begins on the specified channel.
    ChannelHypeTrainBegin2(GenericEventSubPayload),
    /// A Hype Train makes progress on the specified channel.
    ChannelHypeTrainProgress2(GenericEventSubPayload),
    /// A Hype Train ends on the specified channel.
    ChannelHypeTrainEnd2(GenericEventSubPayload),
    /// Sends a notification when the broadcaster activates Shield Mode.
    ChannelShieldModeBegin1(GenericEventSubPayload),
    /// Sends a notification when the broadcaster deactivates Shield Mode.
    ChannelShieldModeEnd1(GenericEventSubPayload),
    /// Sends a notification when the specified broadcaster sends a Shoutout.
    ChannelShoutoutCreate1(GenericEventSubPayload),
    /// Sends a notification when the specified broadcaster receives a Shoutout.
    ChannelShoutoutReceive1(GenericEventSubPayload),
    /// The specified broadcaster starts a stream.
    StreamOnline1(GenericEventSubPayload),
    /// The specified broadcaster stops a stream.
    StreamOffline1(GenericEventSubPayload),
    /// A user’s authorization has been granted to your client id.
    UserAuthorizationGrant1(GenericEventSubPayload),
    /// A user’s authorization has been revoked for your client id.
    UserAuthorizationRevoke1(GenericEventSubPayload),
    /// A user has updated their account.
    UserUpdate1(GenericEventSubPayload),
    /// A user receives a whisper.
    UserWhisperMessage1(GenericEventSubPayload),
}

pub static ALL_SUBSCRIPTIONS: &[EventSubSubscriptionDefinition] = &[
    EventSubSubscriptionDefinition {
        id: "automod_message_hold_1",
        name: "Automod Message Hold",
        subscription_type: "automod.message.hold",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A user is notified if a message is caught by automod for review.",
    },
    EventSubSubscriptionDefinition {
        id: "automod_message_hold_2",
        name: "Automod Message Hold V2\nNEW",
        subscription_type: "automod.message.hold",
        version: "2",
        stability: EndpointStability::New,
        description: "A user is notified if a message is caught by automod for review. Only public blocked terms trigger notifications, not private ones.",
    },
    EventSubSubscriptionDefinition {
        id: "automod_message_update_1",
        name: "Automod Message Update",
        subscription_type: "automod.message.update",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A message in the automod queue had its status changed.",
    },
    EventSubSubscriptionDefinition {
        id: "automod_message_update_2",
        name: "Automod Message Update V2\nNEW",
        subscription_type: "automod.message.update",
        version: "2",
        stability: EndpointStability::New,
        description: "A message in the automod queue had its status changed. Only public blocked terms trigger notifications, not private ones.",
    },
    EventSubSubscriptionDefinition {
        id: "automod_settings_update_1",
        name: "Automod Settings Update",
        subscription_type: "automod.settings.update",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A notification is sent when a broadcaster’s automod settings are updated.",
    },
    EventSubSubscriptionDefinition {
        id: "automod_terms_update_1",
        name: "Automod Terms Update",
        subscription_type: "automod.terms.update",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A notification is sent when a broadcaster’s automod terms are updated. Changes to private terms are not sent.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_bits_use_1",
        name: "Channel Bits Use\nNEW",
        subscription_type: "channel.bits.use",
        version: "1",
        stability: EndpointStability::New,
        description: "A notification is sent whenever Bits are used on a channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_update_2",
        name: "Channel Update",
        subscription_type: "channel.update",
        version: "2",
        stability: EndpointStability::Ga,
        description: "A broadcaster updates their channel properties e.g., category, title, content classification labels, broadcast, or language.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_follow_2",
        name: "Channel Follow",
        subscription_type: "channel.follow",
        version: "2",
        stability: EndpointStability::Ga,
        description: "A specified channel receives a follow.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_ad_break_begin_1",
        name: "Channel Ad Break Begin",
        subscription_type: "channel.ad_break.begin",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A midroll commercial break has started running.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_chat_clear_1",
        name: "Channel Chat Clear",
        subscription_type: "channel.chat.clear",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A moderator or bot has cleared all messages from the chat room.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_chat_clear_user_messages_1",
        name: "Channel Chat Clear User Messages",
        subscription_type: "channel.chat.clear_user_messages",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A moderator or bot has cleared all messages from a specific user.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_chat_message_1",
        name: "Channel Chat Message\nNEW",
        subscription_type: "channel.chat.message",
        version: "1",
        stability: EndpointStability::New,
        description: "Any user sends a message to a specific chat room.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_chat_message_delete_1",
        name: "Channel Chat Message Delete",
        subscription_type: "channel.chat.message_delete",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A moderator has removed a specific message.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_chat_notification_1",
        name: "Channel Chat Notification",
        subscription_type: "channel.chat.notification",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A notification for when an event that appears in chat has occurred.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_chat_settings_update_1",
        name: "Channel Chat Settings Update\nNEW",
        subscription_type: "channel.chat_settings.update",
        version: "1",
        stability: EndpointStability::New,
        description: "A notification for when a broadcaster’s chat settings are updated.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_chat_user_message_hold_1",
        name: "Channel Chat User Message Hold\nNEW",
        subscription_type: "channel.chat.user_message_hold",
        version: "1",
        stability: EndpointStability::New,
        description: "A user is notified if their message is caught by automod.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_chat_user_message_update_1",
        name: "Channel Chat User Message Update\nNEW",
        subscription_type: "channel.chat.user_message_update",
        version: "1",
        stability: EndpointStability::New,
        description: "A user is notified if their message’s automod status is updated.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_shared_chat_begin_1",
        name: "Channel Shared Chat Session Begin\nNEW",
        subscription_type: "channel.shared_chat.begin",
        version: "1",
        stability: EndpointStability::New,
        description: "A notification when a channel becomes active in an active shared chat session.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_shared_chat_update_1",
        name: "Channel Shared Chat Session Update\nNEW",
        subscription_type: "channel.shared_chat.update",
        version: "1",
        stability: EndpointStability::New,
        description: "A notification when the active shared chat session the channel is in changes.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_shared_chat_end_1",
        name: "Channel Shared Chat Session End",
        subscription_type: "channel.shared_chat.end",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A notification when a channel leaves a shared chat session or the session ends.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_subscribe_1",
        name: "Channel Subscribe",
        subscription_type: "channel.subscribe",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A notification is sent when a specified channel receives a subscriber. This does not include resubscribes.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_subscription_end_1",
        name: "Channel Subscription End",
        subscription_type: "channel.subscription.end",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A notification when a subscription to the specified channel ends.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_subscription_gift_1",
        name: "Channel Subscription Gift",
        subscription_type: "channel.subscription.gift",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A notification when a viewer gives a gift subscription to one or more users in the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_subscription_message_1",
        name: "Channel Subscription Message",
        subscription_type: "channel.subscription.message",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A notification when a user sends a resubscription chat message in a specific channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_cheer_1",
        name: "Channel Cheer",
        subscription_type: "channel.cheer",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A user cheers on the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_raid_1",
        name: "Channel Raid",
        subscription_type: "channel.raid",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A broadcaster raids another broadcaster’s channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_ban_1",
        name: "Channel Ban",
        subscription_type: "channel.ban",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A viewer is banned from the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_unban_1",
        name: "Channel Unban",
        subscription_type: "channel.unban",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A viewer is unbanned from the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_moderate_1",
        name: "Channel Unban Request Create\nNEW\nchannel.unban_request.create\n1\nA user creates an unban request.\nChannel Unban Request Resolve\nNEW\nchannel.unban_request.resolve\n1\nAn unban request has been resolved.\nChannel Moderate",
        subscription_type: "channel.moderate",
        version: "1",
        stability: EndpointStability::New,
        description: "A moderator performs a moderation action in a channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_moderate_2",
        name: "Channel Moderate V2\nNEW",
        subscription_type: "channel.moderate",
        version: "2",
        stability: EndpointStability::New,
        description: "A moderator performs a moderation action in a channel. Includes warnings.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_moderator_add_1",
        name: "Channel Moderator Add",
        subscription_type: "channel.moderator.add",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Moderator privileges were added to a user on a specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_moderator_remove_1",
        name: "Channel Moderator Remove",
        subscription_type: "channel.moderator.remove",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Moderator privileges were removed from a user on a specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_guest_star_session_begin_beta",
        name: "Channel Guest Star Session Begin\nBETA",
        subscription_type: "channel.guest_star_session.begin",
        version: "beta",
        stability: EndpointStability::Beta,
        description: "The host began a new Guest Star session.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_guest_star_session_end_beta",
        name: "Channel Guest Star Session End\nBETA",
        subscription_type: "channel.guest_star_session.end",
        version: "beta",
        stability: EndpointStability::Beta,
        description: "A running Guest Star session has ended.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_guest_star_guest_update_beta",
        name: "Channel Guest Star Guest Update\nBETA",
        subscription_type: "channel.guest_star_guest.update",
        version: "beta",
        stability: EndpointStability::Beta,
        description: "A guest or a slot is updated in an active Guest Star session.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_guest_star_settings_update_beta",
        name: "Channel Guest Star Settings Update\nBETA",
        subscription_type: "channel.guest_star_settings.update",
        version: "beta",
        stability: EndpointStability::Beta,
        description: "The host preferences for Guest Star have been updated.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_channel_points_automatic_reward_redemption_add_1",
        name: "Channel Points Automatic Reward Redemption Add",
        subscription_type: "channel.channel_points_automatic_reward_redemption.add",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A viewer has redeemed an automatic channel points reward on the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_channel_points_automatic_reward_redemption_add_2",
        name: "Channel Points Automatic Reward Redemption Add V2\nNEW",
        subscription_type: "channel.channel_points_automatic_reward_redemption.add",
        version: "2",
        stability: EndpointStability::New,
        description: "A viewer has redeemed an automatic channel points reward on the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_channel_points_custom_reward_add_1",
        name: "Channel Points Custom Reward Add",
        subscription_type: "channel.channel_points_custom_reward.add",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A custom channel points reward has been created for the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_channel_points_custom_reward_update_1",
        name: "Channel Points Custom Reward Update",
        subscription_type: "channel.channel_points_custom_reward.update",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A custom channel points reward has been updated for the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_channel_points_custom_reward_remove_1",
        name: "Channel Points Custom Reward Remove",
        subscription_type: "channel.channel_points_custom_reward.remove",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A custom channel points reward has been removed from the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_channel_points_custom_reward_redemption_add_1",
        name: "Channel Points Custom Reward Redemption Add",
        subscription_type: "channel.channel_points_custom_reward_redemption.add",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A viewer has redeemed a custom channel points reward on the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_channel_points_custom_reward_redemption_update_1",
        name: "Channel Points Custom Reward Redemption Update",
        subscription_type: "channel.channel_points_custom_reward_redemption.update",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A redemption of a channel points custom reward has been updated for the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_poll_begin_1",
        name: "Channel Poll Begin",
        subscription_type: "channel.poll.begin",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A poll started on a specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_poll_progress_1",
        name: "Channel Poll Progress",
        subscription_type: "channel.poll.progress",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Users respond to a poll on a specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_poll_end_1",
        name: "Channel Poll End",
        subscription_type: "channel.poll.end",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A poll ended on a specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_prediction_begin_1",
        name: "Channel Prediction Begin",
        subscription_type: "channel.prediction.begin",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A Prediction started on a specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_prediction_progress_1",
        name: "Channel Prediction Progress",
        subscription_type: "channel.prediction.progress",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Users participated in a Prediction on a specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_prediction_lock_1",
        name: "Channel Prediction Lock",
        subscription_type: "channel.prediction.lock",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A Prediction was locked on a specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_prediction_end_1",
        name: "Channel Prediction End",
        subscription_type: "channel.prediction.end",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A Prediction ended on a specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_suspicious_user_message_1",
        name: "Channel Suspicious User Message\nNEW",
        subscription_type: "channel.suspicious_user.message",
        version: "1",
        stability: EndpointStability::New,
        description: "A chat message has been sent by a suspicious user.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_suspicious_user_update_1",
        name: "Channel Suspicious User Update\nNEW",
        subscription_type: "channel.suspicious_user.update",
        version: "1",
        stability: EndpointStability::New,
        description: "A suspicious user has been updated.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_vip_add_1",
        name: "Channel VIP Add\nNEW",
        subscription_type: "channel.vip.add",
        version: "1",
        stability: EndpointStability::New,
        description: "A VIP is added to the channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_vip_remove_1",
        name: "Channel VIP Remove\nNEW",
        subscription_type: "channel.vip.remove",
        version: "1",
        stability: EndpointStability::New,
        description: "A VIP is removed from the channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_warning_acknowledge_1",
        name: "Channel Warning Acknowledgement\nNEW",
        subscription_type: "channel.warning.acknowledge",
        version: "1",
        stability: EndpointStability::New,
        description: "A user awknowledges a warning. Broadcasters and moderators can see the warning’s details.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_warning_send_1",
        name: "Channel Warning Send\nNEW",
        subscription_type: "channel.warning.send",
        version: "1",
        stability: EndpointStability::New,
        description: "A user is sent a warning. Broadcasters and moderators can see the warning’s details.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_charity_campaign_donate_1",
        name: "Charity Donation",
        subscription_type: "channel.charity_campaign.donate",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Sends an event notification when a user donates to the broadcaster’s charity campaign.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_charity_campaign_start_1",
        name: "Charity Campaign Start",
        subscription_type: "channel.charity_campaign.start",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Sends an event notification when the broadcaster starts a charity campaign.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_charity_campaign_progress_1",
        name: "Charity Campaign Progress",
        subscription_type: "channel.charity_campaign.progress",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Sends an event notification when progress is made towards the campaign’s goal or when the broadcaster changes the fundraising goal.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_charity_campaign_stop_1",
        name: "Charity Campaign Stop",
        subscription_type: "channel.charity_campaign.stop",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Sends an event notification when the broadcaster stops a charity campaign.",
    },
    EventSubSubscriptionDefinition {
        id: "conduit_shard_disabled_1",
        name: "Conduit Shard Disabled\nNEW",
        subscription_type: "conduit.shard.disabled",
        version: "1",
        stability: EndpointStability::New,
        description: "Sends a notification when EventSub disables a shard due to the status of the underlying transport changing.",
    },
    EventSubSubscriptionDefinition {
        id: "drop_entitlement_grant_1",
        name: "Drop Entitlement Grant",
        subscription_type: "drop.entitlement.grant",
        version: "1",
        stability: EndpointStability::Ga,
        description: "An entitlement for a Drop is granted to a user.",
    },
    EventSubSubscriptionDefinition {
        id: "extension_bits_transaction_create_1",
        name: "Extension Bits Transaction Create",
        subscription_type: "extension.bits_transaction.create",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A Bits transaction occurred for a specified Twitch Extension.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_goal_begin_1",
        name: "Goal Begin",
        subscription_type: "channel.goal.begin",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Get notified when a broadcaster begins a goal.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_goal_progress_1",
        name: "Goal Progress",
        subscription_type: "channel.goal.progress",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Get notified when progress (either positive or negative) is made towards a broadcaster’s goal.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_goal_end_1",
        name: "Goal End",
        subscription_type: "channel.goal.end",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Get notified when a broadcaster ends a goal.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_hype_train_begin_2",
        name: "Hype Train Begin",
        subscription_type: "channel.hype_train.begin",
        version: "2",
        stability: EndpointStability::Ga,
        description: "A Hype Train begins on the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_hype_train_progress_2",
        name: "Hype Train Progress",
        subscription_type: "channel.hype_train.progress",
        version: "2",
        stability: EndpointStability::Ga,
        description: "A Hype Train makes progress on the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_hype_train_end_2",
        name: "Hype Train End",
        subscription_type: "channel.hype_train.end",
        version: "2",
        stability: EndpointStability::Ga,
        description: "A Hype Train ends on the specified channel.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_shield_mode_begin_1",
        name: "Shield Mode Begin",
        subscription_type: "channel.shield_mode.begin",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Sends a notification when the broadcaster activates Shield Mode.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_shield_mode_end_1",
        name: "Shield Mode End",
        subscription_type: "channel.shield_mode.end",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Sends a notification when the broadcaster deactivates Shield Mode.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_shoutout_create_1",
        name: "Shoutout Create",
        subscription_type: "channel.shoutout.create",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Sends a notification when the specified broadcaster sends a Shoutout.",
    },
    EventSubSubscriptionDefinition {
        id: "channel_shoutout_receive_1",
        name: "Shoutout Received",
        subscription_type: "channel.shoutout.receive",
        version: "1",
        stability: EndpointStability::Ga,
        description: "Sends a notification when the specified broadcaster receives a Shoutout.",
    },
    EventSubSubscriptionDefinition {
        id: "stream_online_1",
        name: "Stream Online",
        subscription_type: "stream.online",
        version: "1",
        stability: EndpointStability::Ga,
        description: "The specified broadcaster starts a stream.",
    },
    EventSubSubscriptionDefinition {
        id: "stream_offline_1",
        name: "Stream Offline",
        subscription_type: "stream.offline",
        version: "1",
        stability: EndpointStability::Ga,
        description: "The specified broadcaster stops a stream.",
    },
    EventSubSubscriptionDefinition {
        id: "user_authorization_grant_1",
        name: "User Authorization Grant",
        subscription_type: "user.authorization.grant",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A user’s authorization has been granted to your client id.",
    },
    EventSubSubscriptionDefinition {
        id: "user_authorization_revoke_1",
        name: "User Authorization Revoke",
        subscription_type: "user.authorization.revoke",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A user’s authorization has been revoked for your client id.",
    },
    EventSubSubscriptionDefinition {
        id: "user_update_1",
        name: "User Update",
        subscription_type: "user.update",
        version: "1",
        stability: EndpointStability::Ga,
        description: "A user has updated their account.",
    },
    EventSubSubscriptionDefinition {
        id: "user_whisper_message_1",
        name: "Whisper Received\nNEW",
        subscription_type: "user.whisper.message",
        version: "1",
        stability: EndpointStability::New,
        description: "A user receives a whisper.",
    },
];

pub(crate) fn decode_known_payload(
    subscription_type: &str,
    version: Option<&str>,
    event: Option<serde_json::Value>,
    source_timestamp: Option<OffsetDateTime>,
) -> Option<KnownEventSubPayload> {
    match (subscription_type, version) {
        ("automod.message.hold", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::AutomodMessageHold1),
        ("automod.message.hold", Some("2")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::AutomodMessageHold2),
        ("automod.message.update", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::AutomodMessageUpdate1),
        ("automod.message.update", Some("2")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::AutomodMessageUpdate2),
        ("automod.settings.update", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::AutomodSettingsUpdate1),
        ("automod.terms.update", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::AutomodTermsUpdate1),
        ("channel.bits.use", Some("1")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::ChannelBitsUse1)
        }
        ("channel.update", Some("2")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::ChannelUpdate2)
        }
        ("channel.follow", Some("2")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::ChannelFollow2)
        }
        ("channel.ad_break.begin", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelAdBreakBegin1),
        ("channel.chat.clear", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelChatClear1),
        ("channel.chat.clear_user_messages", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelChatClearUserMessages1)
        }
        ("channel.chat.message", Some("1")) => decode_typed_event::<EventSubChatMessage>(event)
            .map(KnownEventSubPayload::ChannelChatMessage1),
        ("channel.chat.message_delete", Some("1")) => {
            decode_typed_event::<EventSubChatMessageDeleted>(event)
                .map(KnownEventSubPayload::ChannelChatMessageDelete1)
        }
        ("channel.chat.notification", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelChatNotification1),
        ("channel.chat_settings.update", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelChatSettingsUpdate1)
        }
        ("channel.chat.user_message_hold", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelChatUserMessageHold1)
        }
        ("channel.chat.user_message_update", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelChatUserMessageUpdate1)
        }
        ("channel.shared_chat.begin", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelSharedChatBegin1),
        ("channel.shared_chat.update", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelSharedChatUpdate1),
        ("channel.shared_chat.end", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelSharedChatEnd1),
        ("channel.subscribe", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelSubscribe1),
        ("channel.subscription.end", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelSubscriptionEnd1),
        ("channel.subscription.gift", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelSubscriptionGift1),
        ("channel.subscription.message", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelSubscriptionMessage1)
        }
        ("channel.cheer", Some("1")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::ChannelCheer1)
        }
        ("channel.raid", Some("1")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::ChannelRaid1)
        }
        ("channel.ban", Some("1")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::ChannelBan1)
        }
        ("channel.unban", Some("1")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::ChannelUnban1)
        }
        ("channel.moderate", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelModerate1),
        ("channel.moderate", Some("2")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelModerate2),
        ("channel.moderator.add", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelModeratorAdd1),
        ("channel.moderator.remove", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelModeratorRemove1),
        ("channel.guest_star_session.begin", Some("beta")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelGuestStarSessionBeginBeta)
        }
        ("channel.guest_star_session.end", Some("beta")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelGuestStarSessionEndBeta)
        }
        ("channel.guest_star_guest.update", Some("beta")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelGuestStarGuestUpdateBeta)
        }
        ("channel.guest_star_settings.update", Some("beta")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelGuestStarSettingsUpdateBeta)
        }
        ("channel.channel_points_automatic_reward_redemption.add", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelChannelPointsAutomaticRewardRedemptionAdd1)
        }
        ("channel.channel_points_automatic_reward_redemption.add", Some("2")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelChannelPointsAutomaticRewardRedemptionAdd2)
        }
        ("channel.channel_points_custom_reward.add", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelChannelPointsCustomRewardAdd1)
        }
        ("channel.channel_points_custom_reward.update", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelChannelPointsCustomRewardUpdate1)
        }
        ("channel.channel_points_custom_reward.remove", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelChannelPointsCustomRewardRemove1)
        }
        ("channel.channel_points_custom_reward_redemption.add", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelChannelPointsCustomRewardRedemptionAdd1)
        }
        ("channel.channel_points_custom_reward_redemption.update", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelChannelPointsCustomRewardRedemptionUpdate1)
        }
        ("channel.poll.begin", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelPollBegin1),
        ("channel.poll.progress", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelPollProgress1),
        ("channel.poll.end", Some("1")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::ChannelPollEnd1)
        }
        ("channel.prediction.begin", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelPredictionBegin1),
        ("channel.prediction.progress", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelPredictionProgress1),
        ("channel.prediction.lock", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelPredictionLock1),
        ("channel.prediction.end", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelPredictionEnd1),
        ("channel.suspicious_user.message", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelSuspiciousUserMessage1)
        }
        ("channel.suspicious_user.update", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelSuspiciousUserUpdate1)
        }
        ("channel.vip.add", Some("1")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::ChannelVipAdd1)
        }
        ("channel.vip.remove", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelVipRemove1),
        ("channel.warning.acknowledge", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelWarningAcknowledge1),
        ("channel.warning.send", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelWarningSend1),
        ("channel.charity_campaign.donate", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelCharityCampaignDonate1)
        }
        ("channel.charity_campaign.start", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelCharityCampaignStart1)
        }
        ("channel.charity_campaign.progress", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelCharityCampaignProgress1)
        }
        ("channel.charity_campaign.stop", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ChannelCharityCampaignStop1)
        }
        ("conduit.shard.disabled", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ConduitShardDisabled1),
        ("drop.entitlement.grant", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::DropEntitlementGrant1),
        ("extension.bits_transaction.create", Some("1")) => {
            decode_generic_event(event, source_timestamp)
                .map(KnownEventSubPayload::ExtensionBitsTransactionCreate1)
        }
        ("channel.goal.begin", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelGoalBegin1),
        ("channel.goal.progress", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelGoalProgress1),
        ("channel.goal.end", Some("1")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::ChannelGoalEnd1)
        }
        ("channel.hype_train.begin", Some("2")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelHypeTrainBegin2),
        ("channel.hype_train.progress", Some("2")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelHypeTrainProgress2),
        ("channel.hype_train.end", Some("2")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelHypeTrainEnd2),
        ("channel.shield_mode.begin", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelShieldModeBegin1),
        ("channel.shield_mode.end", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelShieldModeEnd1),
        ("channel.shoutout.create", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelShoutoutCreate1),
        ("channel.shoutout.receive", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::ChannelShoutoutReceive1),
        ("stream.online", Some("1")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::StreamOnline1)
        }
        ("stream.offline", Some("1")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::StreamOffline1)
        }
        ("user.authorization.grant", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::UserAuthorizationGrant1),
        ("user.authorization.revoke", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::UserAuthorizationRevoke1),
        ("user.update", Some("1")) => {
            decode_generic_event(event, source_timestamp).map(KnownEventSubPayload::UserUpdate1)
        }
        ("user.whisper.message", Some("1")) => decode_generic_event(event, source_timestamp)
            .map(KnownEventSubPayload::UserWhisperMessage1),
        _ => None,
    }
}

fn decode_typed_event<T: serde::de::DeserializeOwned>(
    event: Option<serde_json::Value>,
) -> Option<T> {
    serde_json::from_value(event?).ok()
}

fn decode_generic_event(
    event: Option<serde_json::Value>,
    source_timestamp: Option<OffsetDateTime>,
) -> Option<GenericEventSubPayload> {
    let mut payload: GenericEventSubPayload = serde_json::from_value(event?).ok()?;
    payload.source_timestamp = source_timestamp;
    Some(payload)
}