Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: parse new prediction badges over irc #569

Merged
merged 1 commit into from May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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