Skip to content

Commit

Permalink
feat: add last support event pubsub handling (#584)
Browse files Browse the repository at this point in the history
* 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
iProdigy and PhilippHeuer committed Jun 18, 2022
1 parent d38bdfb commit e5981b1
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
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 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();
}
}
@@ -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;
}

0 comments on commit e5981b1

Please sign in to comment.