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(pubsub): add unofficial chat highlights topic #853

Merged
merged 1 commit into from Sep 17, 2023
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 @@ -421,6 +421,11 @@ default PubSubSubscription listenForPublicBitEvents(OAuth2Credential credential,
return listenOnTopic(PubSubType.LISTEN, credential, "channel-bit-events-public." + channelId);
}

@Unofficial
default PubSubSubscription listenForChatHighlightEvents(OAuth2Credential credential, String userId, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-chat-highlights." + userId + '.' + channelId);
}

@Unofficial
default PubSubSubscription listenForPublicCheerEvents(OAuth2Credential credential, String channelId) {
return listenOnTopic(PubSubType.LISTEN, credential, "channel-cheer-events-public-v1." + channelId);
Expand Down
Expand Up @@ -90,6 +90,7 @@
import com.github.twitch4j.pubsub.events.ChannelUnbanRequestUpdateEvent;
import com.github.twitch4j.pubsub.events.CharityCampaignDonationEvent;
import com.github.twitch4j.pubsub.events.CharityCampaignStatusEvent;
import com.github.twitch4j.pubsub.events.ChatHighlightEvent;
import com.github.twitch4j.pubsub.events.ChatModerationEvent;
import com.github.twitch4j.pubsub.events.CheerbombEvent;
import com.github.twitch4j.pubsub.events.ClaimAvailableEvent;
Expand Down Expand Up @@ -847,6 +848,12 @@ protected void onTextMessage(String text) {
boolean hasId = topicName.endsWith("d");
VideoPlaybackData data = TypeConvert.jsonToObject(rawMessage, VideoPlaybackData.class);
eventManager.publish(new VideoPlaybackEvent(hasId ? lastTopicIdentifier : null, hasId ? null : lastTopicIdentifier, data));
} else if ("channel-chat-highlights".equals(topicName)) {
if ("chat-highlight".equals(type)) {
eventManager.publish(TypeConvert.convertValue(msgData, ChatHighlightEvent.class));
} else {
log.warn("Unparsable Message: " + message.getType() + "|" + message.getData());
}
} else if ("channel-unban-requests".equals(topicName) && topicParts.length == 3) {
String userId = topicParts[1];
String channelId = topicParts[2];
Expand Down
@@ -0,0 +1,17 @@
package com.github.twitch4j.pubsub.domain;

import lombok.AccessLevel;
import lombok.Data;
import lombok.Setter;

@Data
@Setter(AccessLevel.PRIVATE)
public class ChatHighlight {
private String type;
private String sourceChannelId;
private Long secondsSinceEvent;

public boolean isRaider() {
return "raider".equalsIgnoreCase(type);
}
}
@@ -0,0 +1,25 @@
package com.github.twitch4j.pubsub.events;

import com.github.twitch4j.common.annotation.Unofficial;
import com.github.twitch4j.common.events.TwitchEvent;
import com.github.twitch4j.pubsub.domain.ChatHighlight;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Setter;

import java.time.Instant;
import java.util.List;

@Data
@Unofficial
@Setter(AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false)
public class ChatHighlightEvent extends TwitchEvent {
private String channelId;
private String userId;
private String msgId;
private Instant chatSentAt;
private Instant highlightsSentAt;
private List<ChatHighlight> highlights;
}