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: add last support event pubsub handling #584

Merged
merged 2 commits into from Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -54,6 +54,7 @@
import com.github.twitch4j.pubsub.domain.RedemptionProgress;
import com.github.twitch4j.pubsub.domain.SubGiftData;
import com.github.twitch4j.pubsub.domain.SubscriptionData;
import com.github.twitch4j.pubsub.domain.SupportActivityFeedData;
import com.github.twitch4j.pubsub.domain.UpdateSummaryData;
import com.github.twitch4j.pubsub.domain.UpdatedUnbanRequest;
import com.github.twitch4j.pubsub.domain.UserAutomodCaughtMessage;
Expand Down Expand Up @@ -111,6 +112,7 @@
import com.github.twitch4j.pubsub.events.RedemptionStatusUpdateEvent;
import com.github.twitch4j.pubsub.events.RewardRedeemedEvent;
import com.github.twitch4j.pubsub.events.SubLeaderboardEvent;
import com.github.twitch4j.pubsub.events.SupportActivityFeedEvent;
import com.github.twitch4j.pubsub.events.UpdateOnsiteNotificationSummaryEvent;
import com.github.twitch4j.pubsub.events.UpdateRedemptionFinishedEvent;
import com.github.twitch4j.pubsub.events.UpdateRedemptionProgressEvent;
Expand Down Expand Up @@ -595,7 +597,9 @@ protected void onTextMessage(String text) {
eventManager.publish(new HypeTrainCooldownExpirationEvent(lastTopicIdentifier));
break;
case "last-x-experiment-event":
// ignore for now (experiment is not publicly deployed)
// note: this isn't a true hype train event (it can be fired with no train active), but twitch hacked together the feature to use the hype pubsub infrastructure
final SupportActivityFeedData lastData = TypeConvert.convertValue(msgData, SupportActivityFeedData.class);
eventManager.publish(new SupportActivityFeedEvent(lastTopicIdentifier, lastData));
break;
default:
log.warn("Unparsable Message: " + message.getType() + "|" + message.getData());
Expand Down
@@ -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 isCheer() {
return "BITS".equals(source) || "CHEER".equals(action);
PhilippHeuer marked this conversation as resolved.
Show resolved Hide resolved
}

@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();
}
}
@@ -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;
}