From 812be4196fb2e83e8ef9513969f14eb687d04599 Mon Sep 17 00:00:00 2001 From: Sidd Date: Fri, 13 May 2022 16:12:00 -0700 Subject: [PATCH] feat: parse new prediction badges over irc --- .../chat/events/channel/IRCMessageEvent.java | 24 +++++++++++++++++++ .../common/enums/CommandPermission.java | 6 +++-- .../twitch4j/common/util/TwitchUtils.java | 7 +++--- .../pubsub/domain/ChannelPointsReward.java | 1 + 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/chat/src/main/java/com/github/twitch4j/chat/events/channel/IRCMessageEvent.java b/chat/src/main/java/com/github/twitch4j/chat/events/channel/IRCMessageEvent.java index a086b8915..7d255a77e 100644 --- a/chat/src/main/java/com/github/twitch4j/chat/events/channel/IRCMessageEvent.java +++ b/chat/src/main/java/com/github/twitch4j/chat/events/channel/IRCMessageEvent.java @@ -313,6 +313,30 @@ public OptionalInt getCheererTier() { return OptionalInt.empty(); } + /** + * @return the index of the choice this user is predicting, in an optional wrapper + */ + public OptionalInt getPredictedChoiceIndex() { + String predictions = badges.get("predictions"); + + if (predictions != null) { + int delim = predictions.indexOf('-'); + try { + return OptionalInt.of(Integer.parseInt(predictions.substring(delim + 1))); + } catch (NumberFormatException ignored) { + } + } + + return OptionalInt.empty(); + } + + /** + * @return the title of the choice this user is predicting, in an optional wrapper + */ + public Optional getPredictedChoiceTitle() { + return Optional.ofNullable(badgeInfo.get("predictions")).map(EscapeUtils::unescapeTagValue); + } + /** * Gets a optional tag from the irc message * diff --git a/common/src/main/java/com/github/twitch4j/common/enums/CommandPermission.java b/common/src/main/java/com/github/twitch4j/common/enums/CommandPermission.java index f7fdd38b6..8913e3f61 100644 --- a/common/src/main/java/com/github/twitch4j/common/enums/CommandPermission.java +++ b/common/src/main/java/com/github/twitch4j/common/enums/CommandPermission.java @@ -47,12 +47,14 @@ public enum CommandPermission { CURRENT_HYPE_TRAIN_CONDUCTOR, /** - * Participated in the most recent predictions event for the blue/first option + * Participated in the most recent predictions event for a blue option + *

+ * Warning: when there are three or more prediction choices, they are all blue */ PREDICTIONS_BLUE, /** - * Participated in the most recent predictions event for the pink/second option + * Participated in the most recent predictions event for a pink option */ PREDICTIONS_PINK, diff --git a/common/src/main/java/com/github/twitch4j/common/util/TwitchUtils.java b/common/src/main/java/com/github/twitch4j/common/util/TwitchUtils.java index 48076d44c..935736195 100644 --- a/common/src/main/java/com/github/twitch4j/common/util/TwitchUtils.java +++ b/common/src/main/java/com/github/twitch4j/common/util/TwitchUtils.java @@ -58,7 +58,7 @@ public static Set getPermissionsFromTags(@NonNull Map getPermissionsFromTags(@NonNull Map