Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add last support event pubsub handling (#584)
* feat: add last support event pubsub handling * chore: rename isCheer to isBitsCheer Co-authored-by: iProdigy <iProdigy@users.noreply.github.com> Co-authored-by: Philipp Heuer <git@philippheuer.me>
- Loading branch information
1 parent
d38bdfb
commit e5981b1
Showing
3 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
pubsub/src/main/java/com/github/twitch4j/pubsub/domain/SupportActivityFeedData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.github.twitch4j.pubsub.domain; | ||
|
||
import com.github.twitch4j.common.annotation.Unofficial; | ||
import lombok.AccessLevel; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.OptionalInt; | ||
|
||
@Unofficial | ||
@Data | ||
@Setter(AccessLevel.NONE) | ||
@NoArgsConstructor | ||
public class SupportActivityFeedData { | ||
private String channelId; | ||
private String eventId; | ||
private String userId; | ||
private String userLogin; | ||
private String userDisplayName; | ||
private String userProfileImageUrl; | ||
private String action; | ||
private String source; | ||
private Integer quantity; | ||
|
||
@Unofficial | ||
public boolean isBitsCheer() { | ||
return "BITS".equals(source) && "CHEER".equals(action); | ||
} | ||
|
||
@Unofficial | ||
public boolean isSub() { | ||
return "SUBS".equals(source); | ||
} | ||
|
||
@Unofficial | ||
public boolean isGiftSub() { | ||
return action != null && action.endsWith("GIFTED_SUB"); | ||
} | ||
|
||
@Unofficial | ||
public OptionalInt getSubTier() { | ||
if (action != null) { | ||
int i = action.indexOf("TIER_"); | ||
if (i >= 0) { | ||
i += "TIER_".length(); | ||
int j = action.indexOf('_', i); | ||
if (j > i) { | ||
try { | ||
return OptionalInt.of(Integer.parseInt(action.substring(i, j))); | ||
} catch (Exception ignored) { | ||
} | ||
} | ||
} | ||
} | ||
return OptionalInt.empty(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
pubsub/src/main/java/com/github/twitch4j/pubsub/events/SupportActivityFeedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.twitch4j.pubsub.events; | ||
|
||
import com.github.twitch4j.common.events.TwitchEvent; | ||
import com.github.twitch4j.pubsub.domain.SupportActivityFeedData; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
|
||
@Value | ||
@EqualsAndHashCode(callSuper = false) | ||
public class SupportActivityFeedEvent extends TwitchEvent { | ||
String channelId; | ||
SupportActivityFeedData data; | ||
} |