-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
ITwitchPubSub.java
507 lines (426 loc) · 21.2 KB
/
ITwitchPubSub.java
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
package com.github.twitch4j.pubsub;
import com.github.philippheuer.credentialmanager.domain.OAuth2Credential;
import com.github.philippheuer.events4j.core.EventManager;
import com.github.twitch4j.common.annotation.Unofficial;
import com.github.twitch4j.common.util.CryptoUtils;
import com.github.twitch4j.pubsub.domain.PubSubRequest;
import com.github.twitch4j.pubsub.enums.PubSubType;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
public interface ITwitchPubSub extends AutoCloseable {
EventManager getEventManager();
/**
* Send WS Message to subscribe to a topic
*
* @param request Topic
* @return PubSubSubscription to be listened to
*/
PubSubSubscription listenOnTopic(PubSubRequest request);
/**
* Unsubscribe from a topic.
* Usage example:
* <pre>
* PubSubSubscription subscription = twitchPubSub.listenForCheerEvents(...);
* // ...
* twitchPubSub.unsubscribeFromTopic(subscription);
* </pre>
*
* @param subscription PubSubSubscription to be unlistened from
* @return whether the subscription was previously subscribed to
*/
boolean unsubscribeFromTopic(PubSubSubscription subscription);
@Override
void close();
default PubSubSubscription listenOnTopic(PubSubType type, OAuth2Credential credential, Collection<String> topics) {
PubSubRequest request = new PubSubRequest();
request.setType(type);
request.setNonce(CryptoUtils.generateNonce(30));
request.getData().put("auth_token", credential != null ? credential.getAccessToken() : "");
request.getData().put("topics", topics);
return listenOnTopic(request);
}
default PubSubSubscription listenOnTopic(PubSubType type, OAuth2Credential credential, String topic) {
return listenOnTopic(type, credential, Collections.singletonList(topic));
}
default PubSubSubscription listenOnTopic(PubSubType type, OAuth2Credential credential, String... topics) {
return listenOnTopic(type, credential, Arrays.asList(topics));
}
/**
* Event Listener: AutoMod flags a message as potentially inappropriate, and when a moderator takes action on a message.
*
* @param credential Credential (for userId, scope: channel:moderate)
* @param userId The moderator's user id associated with the credential
* @param channelId The user id associated with the target channel
* @return PubSubSubscription
*/
default PubSubSubscription listenForAutomodQueueEvents(OAuth2Credential credential, String userId, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "automod-queue." + userId + "." + channelId);
}
/**
* Event Listener: User earned a new Bits badge and shared the notification with chat
*
* @param credential Credential (for target channel id, scope: bits:read)
* @param channelId Target Channel Id
* @return PubSubSubscription
*/
default PubSubSubscription listenForBitsBadgeEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-bits-badge-unlocks." + channelId);
}
/**
* Event Listener: Anyone cheers on a specified channel.
*
* @param credential Credential (for target channel id, scope: bits:read)
* @param channelId Target Channel Id
* @return PubSubSubscription
*/
default PubSubSubscription listenForCheerEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-bits-events-v2." + channelId);
}
/**
* Event Listener: Anyone subscribes (first month), resubscribes (subsequent months), or gifts a subscription to a channel.
*
* @param credential Credential (for targetChannelId, scope: channel_subscriptions)
* @param channelId Target Channel Id
* @return PubSubSubscription
*/
default PubSubSubscription listenForSubscriptionEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-subscribe-events-v1." + channelId);
}
/**
* Event Listener: Anyone makes a purchase on a channel.
*
* @param credential Credential (any)
* @param channelId Target Channel Id
* @return PubSubSubscription
*/
@Deprecated
default PubSubSubscription listenForCommerceEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-commerce-events-v1." + channelId);
}
/**
* Event Listener: Anyone whispers the specified user.
*
* @param credential Credential (for targetUserId, scope: whispers:read)
* @param userId Target User Id
* @return PubSubSubscription
*/
default PubSubSubscription listenForWhisperEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "whispers." + userId);
}
/**
* Event Listener: A moderator performs an action in the channel
*
* @param credential Credential (for channelId, scope: channel:moderate)
* @param channelId Target Channel Id
* @return PubSubSubscription
* @deprecated in favor of listenForModerationEvents(OAuth2Credential, String, String)
*/
@Deprecated
@Unofficial
default PubSubSubscription listenForModerationEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "chat_moderator_actions." + channelId);
}
/**
* Event Listener: A moderator performs an action in the channel
*
* @param credential Credential (for userId, scope: channel:moderate)
* @param userId The user id associated with the credential
* @param channelId The user id associated with the target channel
* @return PubSubSubscription
*/
@SuppressWarnings("deprecated")
default PubSubSubscription listenForModerationEvents(OAuth2Credential credential, String userId, String channelId) {
return listenForModerationEvents(credential, userId + "." + channelId);
}
/**
* Event Listener: A user’s message held by AutoMod has been approved or denied.
*
* @param credential Credential (for userId, scope: chat:read)
* @param userId The user id associated with the credential
* @param channelId The user id associated with the target channel
* @return PubSubSubscription
*/
default PubSubSubscription listenForUserModerationNotificationEvents(OAuth2Credential credential, String userId, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "user-moderation-notifications." + userId + "." + channelId);
}
/**
* Event Listener: Anyone makes a channel points redemption on a channel.
*
* @param credential Credential (with the channel:read:redemptions scope for maximum information)
* @param channelId Target Channel Id
* @return PubSubSubscription
*/
default PubSubSubscription listenForChannelPointsRedemptionEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "community-points-channel-v1." + channelId);
}
/*
* Undocumented topics - Use at your own risk
*/
@Unofficial
@Deprecated
default PubSubSubscription listenForAdsEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "ads." + channelId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForAdPropertyRefreshEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "ad-property-refresh." + channelId);
}
@Unofficial
default PubSubSubscription listenForAutomodLevelsModificationEvents(OAuth2Credential credential, String userId, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "automod-levels-modification." + userId + "." + channelId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForBountyBoardEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-bounty-board-events.cta." + channelId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForDashboardActivityFeedEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "dashboard-activity-feed." + userId);
}
@Unofficial
default PubSubSubscription listenForCommunityBoostEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "community-boost-events-v1." + channelId);
}
@Unofficial
default PubSubSubscription listenForCreatorGoalsEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "creator-goals-events-v1." + channelId);
}
@Unofficial
default PubSubSubscription listenForCrowdChantEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "crowd-chant-channel-v1." + channelId);
}
@Unofficial
default PubSubSubscription listenForUserChannelPointsEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "community-points-user-v1." + userId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForChannelDropEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-drop-events." + channelId);
}
@Unofficial
default PubSubSubscription listenForChannelBitsLeaderboardEvents(OAuth2Credential credential, String channelId) {
return listenForChannelBitsLeaderboardEvents(credential, channelId, "WEEK");
}
@Unofficial
default PubSubSubscription listenForChannelBitsLeaderboardMonthlyEvents(OAuth2Credential credential, String channelId) {
return listenForChannelBitsLeaderboardEvents(credential, channelId, "MONTH");
}
@Unofficial
default PubSubSubscription listenForChannelBitsLeaderboardAllTimeEvents(OAuth2Credential credential, String channelId) {
return listenForChannelBitsLeaderboardEvents(credential, channelId, "ALLTIME");
}
@Unofficial
default PubSubSubscription listenForChannelBitsLeaderboardEvents(OAuth2Credential credential, String channelId, String timeAggregationUnit) {
return listenOnTopic(PubSubType.LISTEN, credential, "leaderboard-events-v1.bits-usage-by-channel-v1-" + channelId + "-" + timeAggregationUnit);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForChannelPrimeGiftStatusEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-prime-gifting-status." + channelId);
}
@Unofficial
default PubSubSubscription listenForChannelSubLeaderboardEvents(OAuth2Credential credential, String channelId) {
return listenForChannelSubLeaderboardEvents(credential, channelId, "WEEK");
}
@Unofficial
default PubSubSubscription listenForChannelSubLeaderboardMonthlyEvents(OAuth2Credential credential, String channelId) {
return listenForChannelSubLeaderboardEvents(credential, channelId, "MONTH");
}
@Unofficial
default PubSubSubscription listenForChannelSubLeaderboardAllTimeEvents(OAuth2Credential credential, String channelId) {
return listenForChannelSubLeaderboardEvents(credential, channelId, "ALLTIME");
}
@Unofficial
default PubSubSubscription listenForChannelSubLeaderboardEvents(OAuth2Credential credential, String channelId, String timeAggregationUnit) {
return listenOnTopic(PubSubType.LISTEN, credential, "leaderboard-events-v1.sub-gifts-sent-" + channelId + "-" + timeAggregationUnit);
}
@Unofficial
default PubSubSubscription listenForLeaderboardEvents(OAuth2Credential credential, String channelId) {
return listenForLeaderboardEvents(credential, channelId, "WEEK");
}
@Unofficial
default PubSubSubscription listenForLeaderboardMonthlyEvents(OAuth2Credential credential, String channelId) {
return listenForLeaderboardEvents(credential, channelId, "MONTH");
}
@Unofficial
default PubSubSubscription listenForLeaderboardAllTimeEvents(OAuth2Credential credential, String channelId) {
return listenForLeaderboardEvents(credential, channelId, "ALLTIME");
}
@Unofficial
default PubSubSubscription listenForLeaderboardEvents(OAuth2Credential credential, String channelId, String timeAggregationUnit) {
return listenOnTopic(
PubSubType.LISTEN,
credential,
"leaderboard-events-v1.bits-usage-by-channel-v1-" + channelId + "-" + timeAggregationUnit,
"leaderboard-events-v1.sub-gifts-sent-" + channelId + "-" + timeAggregationUnit
);
}
@Unofficial
default PubSubSubscription listenForChannelPredictionsEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "predictions-channel-v1." + channelId);
}
@Unofficial
default PubSubSubscription listenForUserPredictionsEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "predictions-user-v1." + userId);
}
@Unofficial
default PubSubSubscription listenForChannelSubGiftsEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-sub-gifts-v1." + channelId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForChannelSquadEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-squad-updates." + channelId);
}
@Unofficial
default PubSubSubscription listenForRaidEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "raid." + channelId);
}
@Unofficial
default PubSubSubscription listenForChannelUnbanRequestEvents(OAuth2Credential credential, String userId, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-unban-requests." + userId + '.' + channelId);
}
@Unofficial
default PubSubSubscription listenForUserUnbanRequestEvents(OAuth2Credential credential, String userId, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "user-unban-requests." + userId + '.' + channelId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForChannelExtensionEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-ext-v1." + channelId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForExtensionControlEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "extension-control." + channelId);
}
@Unofficial
default PubSubSubscription listenForHypeTrainEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "hype-train-events-v1." + channelId);
}
@Unofficial
default PubSubSubscription listenForHypeTrainRewardEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "hype-train-events-v1.rewards." + channelId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForBroadcastSettingUpdateEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "broadcast-settings-update." + channelId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForCelebrationEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "celebration-events-v1." + channelId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForPublicBitEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-bit-events-public." + channelId);
}
@Unofficial
default PubSubSubscription listenForPublicCheerEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-cheer-events-public-v1." + channelId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForStreamChangeEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "stream-change-by-channel." + channelId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForStreamChatRoomEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "stream-chat-room-v1." + channelId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForChannelChatroomEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "chatrooms-channel-v1." + channelId);
}
@Unofficial
default PubSubSubscription listenForUserChatroomEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "chatrooms-user-v1." + userId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForUserBitsUpdateEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "user-bits-updates-v1." + userId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForUserCampaignEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "user-campaign-events." + userId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForUserDropEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "user-drop-events." + userId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForUserPropertiesUpdateEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "user-properties-update." + userId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForUserSubscribeEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "user-subscribe-events-v1." + userId);
}
@Unofficial
@Deprecated
default PubSubSubscription listenForUserImageUpdateEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "user-image-update." + userId);
}
/**
* Event Listener: Anyone follows the specified channel.
*
* @param credential {@link OAuth2Credential}
* @param channelId the id for the channel
* @return PubSubSubscription
*/
@Unofficial
default PubSubSubscription listenForFollowingEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "following." + channelId);
}
@Unofficial
default PubSubSubscription listenForFriendshipEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "friendship." + userId);
}
@Unofficial
default PubSubSubscription listenForLowTrustUsersEvents(OAuth2Credential credential, String userId, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "low-trust-users." + userId + "." + channelId);
}
@Unofficial
default PubSubSubscription listenForOnsiteNotificationEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "onsite-notifications." + userId);
}
@Unofficial
default PubSubSubscription listenForPollEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "polls." + channelId);
}
@Unofficial
default PubSubSubscription listenForPresenceEvents(OAuth2Credential credential, String userId) {
return listenOnTopic(PubSubType.LISTEN, credential, "presence." + userId);
}
@Unofficial
default PubSubSubscription listenForRadioEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "radio-events-v1." + channelId);
}
@Unofficial
default PubSubSubscription listenForVideoPlaybackEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "video-playback-by-id." + channelId);
}
@Unofficial
default PubSubSubscription listenForVideoPlaybackByNameEvents(OAuth2Credential credential, String channelName) {
return listenOnTopic(PubSubType.LISTEN, credential, "video-playback." + channelName.toLowerCase());
}
@Unofficial
@Deprecated
default PubSubSubscription listenForWatchPartyEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "pv-watch-party-events." + channelId);
}
}