From 830494889d80a117dc6bb9d122b6ff37fc425903 Mon Sep 17 00:00:00 2001 From: iProdigy Date: Wed, 10 Apr 2024 00:07:58 -0700 Subject: [PATCH] feat(eventsub): add whisper received topic --- .../twitch4j/eventsub/domain/Whisper.java | 16 +++++++ .../events/EventSubUserFromToEvent.java | 47 +++++++++++++++++++ .../eventsub/events/WhisperReceivedEvent.java | 26 ++++++++++ .../subscriptions/SubscriptionTypes.java | 4 +- .../subscriptions/WhisperReceivedType.java | 34 ++++++++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 eventsub-common/src/main/java/com/github/twitch4j/eventsub/domain/Whisper.java create mode 100644 eventsub-common/src/main/java/com/github/twitch4j/eventsub/events/EventSubUserFromToEvent.java create mode 100644 eventsub-common/src/main/java/com/github/twitch4j/eventsub/events/WhisperReceivedEvent.java create mode 100644 eventsub-common/src/main/java/com/github/twitch4j/eventsub/subscriptions/WhisperReceivedType.java diff --git a/eventsub-common/src/main/java/com/github/twitch4j/eventsub/domain/Whisper.java b/eventsub-common/src/main/java/com/github/twitch4j/eventsub/domain/Whisper.java new file mode 100644 index 000000000..ce50fe7c1 --- /dev/null +++ b/eventsub-common/src/main/java/com/github/twitch4j/eventsub/domain/Whisper.java @@ -0,0 +1,16 @@ +package com.github.twitch4j.eventsub.domain; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.Setter; + +@Data +@Setter(AccessLevel.PRIVATE) +public class Whisper { + + /** + * The body of the whisper message. + */ + private String text; + +} diff --git a/eventsub-common/src/main/java/com/github/twitch4j/eventsub/events/EventSubUserFromToEvent.java b/eventsub-common/src/main/java/com/github/twitch4j/eventsub/events/EventSubUserFromToEvent.java new file mode 100644 index 000000000..ea0d4290f --- /dev/null +++ b/eventsub-common/src/main/java/com/github/twitch4j/eventsub/events/EventSubUserFromToEvent.java @@ -0,0 +1,47 @@ +package com.github.twitch4j.eventsub.events; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Data +@Setter(AccessLevel.PRIVATE) +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class EventSubUserFromToEvent extends EventSubEvent { + + /** + * The user ID that triggered the event. + */ + private String fromUserId; + + /** + * The user login name that triggered the event. + */ + private String fromUserLogin; + + /** + * The user display name that triggered the event. + */ + private String fromUserName; + + /** + * The user ID that received the event. + */ + private String toUserId; + + /** + * The user login name that received the event. + */ + private String toUserLogin; + + /** + * The user display name that received the event. + */ + private String toUserName; + +} diff --git a/eventsub-common/src/main/java/com/github/twitch4j/eventsub/events/WhisperReceivedEvent.java b/eventsub-common/src/main/java/com/github/twitch4j/eventsub/events/WhisperReceivedEvent.java new file mode 100644 index 000000000..1862cf65a --- /dev/null +++ b/eventsub-common/src/main/java/com/github/twitch4j/eventsub/events/WhisperReceivedEvent.java @@ -0,0 +1,26 @@ +package com.github.twitch4j.eventsub.events; + +import com.github.twitch4j.eventsub.domain.Whisper; +import lombok.AccessLevel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.Setter; +import lombok.ToString; + +@Data +@Setter(AccessLevel.PRIVATE) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +public class WhisperReceivedEvent extends EventSubUserFromToEvent { + + /** + * The whisper ID. + */ + private String whisperId; + + /** + * Object containing whisper information. + */ + private Whisper whisper; + +} diff --git a/eventsub-common/src/main/java/com/github/twitch4j/eventsub/subscriptions/SubscriptionTypes.java b/eventsub-common/src/main/java/com/github/twitch4j/eventsub/subscriptions/SubscriptionTypes.java index 85b18c087..c8887a471 100644 --- a/eventsub-common/src/main/java/com/github/twitch4j/eventsub/subscriptions/SubscriptionTypes.java +++ b/eventsub-common/src/main/java/com/github/twitch4j/eventsub/subscriptions/SubscriptionTypes.java @@ -74,6 +74,7 @@ public class SubscriptionTypes { public final UserAuthorizationGrantType USER_AUTHORIZATION_GRANT; public final UserAuthorizationRevokeType USER_AUTHORIZATION_REVOKE; public final UserUpdateType USER_UPDATE; + public final WhisperReceivedType WHISPER_RECEIVE; public SubscriptionType getSubscriptionType(String subTypeName, String subTypeVersion) { return SUBSCRIPTION_TYPES.get(subTypeName + ':' + subTypeVersion); @@ -141,7 +142,8 @@ public class SubscriptionTypes { UNBAN_REQUEST_RESOLVE = new UnbanRequestResolveType(), USER_AUTHORIZATION_GRANT = new UserAuthorizationGrantType(), USER_AUTHORIZATION_REVOKE = new UserAuthorizationRevokeType(), - USER_UPDATE = new UserUpdateType() + USER_UPDATE = new UserUpdateType(), + WHISPER_RECEIVE = new WhisperReceivedType() ).collect(Collectors.toMap(type -> type.getName() + ':' + type.getVersion(), Function.identity())) ); } diff --git a/eventsub-common/src/main/java/com/github/twitch4j/eventsub/subscriptions/WhisperReceivedType.java b/eventsub-common/src/main/java/com/github/twitch4j/eventsub/subscriptions/WhisperReceivedType.java new file mode 100644 index 000000000..1b587425a --- /dev/null +++ b/eventsub-common/src/main/java/com/github/twitch4j/eventsub/subscriptions/WhisperReceivedType.java @@ -0,0 +1,34 @@ +package com.github.twitch4j.eventsub.subscriptions; + +import com.github.twitch4j.eventsub.condition.UserEventSubCondition; +import com.github.twitch4j.eventsub.events.WhisperReceivedEvent; + +/** + * Fires when anyone whispers the specified user. + *

+ * Must have oauth scope user:read:whispers or user:manage:whispers. + * + * @see com.github.twitch4j.auth.domain.TwitchScopes#HELIX_USER_WHISPERS_READ + * @see com.github.twitch4j.auth.domain.TwitchScopes#HELIX_USER_WHISPERS_MANAGE + */ +public class WhisperReceivedType implements SubscriptionType, WhisperReceivedEvent> { + @Override + public String getName() { + return "user.whisper.message"; + } + + @Override + public String getVersion() { + return "1"; + } + + @Override + public UserEventSubCondition.UserEventSubConditionBuilder getConditionBuilder() { + return UserEventSubCondition.builder(); + } + + @Override + public Class getEventClass() { + return WhisperReceivedEvent.class; + } +}