Skip to content

Commit

Permalink
feat: parse new prediction badges over irc (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy committed May 15, 2022
1 parent 3ba1e1f commit 73e16a1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Expand Up @@ -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<String> getPredictedChoiceTitle() {
return Optional.ofNullable(badgeInfo.get("predictions")).map(EscapeUtils::unescapeTagValue);
}

/**
* Gets a optional tag from the irc message
*
Expand Down
Expand Up @@ -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
* <p>
* 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,

Expand Down
Expand Up @@ -58,7 +58,7 @@ public static Set<CommandPermission> getPermissionsFromTags(@NonNull Map<String,
permissionSet.add(CommandPermission.MODERATOR);
}
// Partner
if (badges.containsKey("partner")) {
if (badges.containsKey("partner") || badges.containsKey("ambassador")) {
permissionSet.add(CommandPermission.PARTNER);
}
// VIP
Expand Down Expand Up @@ -112,10 +112,9 @@ public static Set<CommandPermission> getPermissionsFromTags(@NonNull Map<String,
String predictionBadge = badges.get("predictions");
if (StringUtils.isNotEmpty(predictionBadge)) {
char first = predictionBadge.charAt(0);
char last = predictionBadge.charAt(predictionBadge.length() - 1);
if (first == 'b' || last == '1') {
if (first == 'b') {
permissionSet.add(CommandPermission.PREDICTIONS_BLUE);
} else if (first == 'p' || last == '2') {
} else if (first == 'p') {
permissionSet.add(CommandPermission.PREDICTIONS_PINK);
}
}
Expand Down
Expand Up @@ -30,6 +30,7 @@ public class ChannelPointsReward {
private GlobalCooldown globalCooldown;
private Integer redemptionsRedeemedCurrentStream;
private Instant cooldownExpiresAt;
private String templateId;

@Data
public static class Image {
Expand Down

0 comments on commit 73e16a1

Please sign in to comment.