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 shield mode helix and eventsub beta support #687

Merged
merged 4 commits into from Jan 3, 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 @@ -22,6 +22,10 @@ public enum EventSubSubscriptionStatus {
* Authorization for user(s) in the condition was revoked.
*/
AUTHORIZATION_REVOKED,
/**
* The moderator that authorized the subscription is no longer one of the broadcaster’s moderators.
*/
MODERATOR_REMOVED,
/**
* A user in the condition of the subscription was removed.
*/
Expand Down
@@ -0,0 +1,25 @@
package com.github.twitch4j.eventsub.condition;

import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@Data
@Setter(AccessLevel.PRIVATE)
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
@Jacksonized
public class ModeratorEventSubCondition extends ChannelEventSubCondition {

/**
* The ID of the broadcaster or one of the broadcaster’s moderators.
* <p>
* For webhooks, the user must have granted your app (client ID) the relevant permissions for the subscription type.
* For websockets, the ID must match the user ID in the user access token.
*/
private String moderatorUserId;

}
@@ -0,0 +1,12 @@
package com.github.twitch4j.eventsub.condition;

import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Jacksonized
public class ShieldModeCondition extends ModeratorEventSubCondition {}
@@ -0,0 +1,24 @@
package com.github.twitch4j.eventsub.events;

import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.time.Instant;

@Data
@Setter(AccessLevel.PRIVATE)
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class ShieldModeBeginEvent extends EventSubModerationEvent {

/**
* The UTC timestamp of when the moderator activated Shield Mode.
*/
private Instant startedAt;

}
@@ -0,0 +1,24 @@
package com.github.twitch4j.eventsub.events;

import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.time.Instant;

@Data
@Setter(AccessLevel.PRIVATE)
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class ShieldModeEndEvent extends EventSubModerationEvent {

/**
* The UTC timestamp of when the moderator deactivated Shield Mode.
*/
private Instant endedAt;

}
@@ -0,0 +1,35 @@
package com.github.twitch4j.eventsub.subscriptions;

import com.github.twitch4j.common.annotation.Unofficial;
import com.github.twitch4j.eventsub.condition.ShieldModeCondition;
import com.github.twitch4j.eventsub.events.ShieldModeBeginEvent;

/**
* Sends a notification when the broadcaster activates Shield Mode.
* <p>
* This event informs the subscriber that the broadcaster’s moderation settings were changed based on the broadcaster’s Shield Mode configuration settings.
* <p>
* Requires the moderator:read:shield_mode or moderator:manage:shield_mode scope.
*/
@Unofficial
public class BetaShieldModeBeginType implements SubscriptionType<ShieldModeCondition, ShieldModeCondition.ShieldModeConditionBuilder<?, ?>, ShieldModeBeginEvent> {
@Override
public String getName() {
return "channel.shield_mode.begin";
}

@Override
public String getVersion() {
return "beta";
}

@Override
public ShieldModeCondition.ShieldModeConditionBuilder<?, ?> getConditionBuilder() {
return ShieldModeCondition.builder();
}

@Override
public Class<ShieldModeBeginEvent> getEventClass() {
return ShieldModeBeginEvent.class;
}
}
@@ -0,0 +1,36 @@
package com.github.twitch4j.eventsub.subscriptions;

import com.github.twitch4j.common.annotation.Unofficial;
import com.github.twitch4j.eventsub.condition.ShieldModeCondition;
import com.github.twitch4j.eventsub.events.ShieldModeBeginEvent;
import com.github.twitch4j.eventsub.events.ShieldModeEndEvent;

/**
* Sends a notification when the broadcaster deactivates Shield Mode.
* <p>
* This event informs the subscriber that the broadcaster’s moderation settings were changed based on the broadcaster’s Shield Mode configuration settings.
* <p>
* Requires the moderator:read:shield_mode or moderator:manage:shield_mode scope.
*/
@Unofficial
public class BetaShieldModeEndType implements SubscriptionType<ShieldModeCondition, ShieldModeCondition.ShieldModeConditionBuilder<?, ?>, ShieldModeEndEvent> {
@Override
public String getName() {
return "channel.shield_mode.end";
}

@Override
public String getVersion() {
return "beta";
}

@Override
public ShieldModeCondition.ShieldModeConditionBuilder<?, ?> getConditionBuilder() {
return ShieldModeCondition.builder();
}

@Override
public Class<ShieldModeEndEvent> getEventClass() {
return ShieldModeEndEvent.class;
}
}
Expand Up @@ -14,7 +14,7 @@ public class SubscriptionTypes {
private final Map<String, SubscriptionType<?, ?, ?>> SUBSCRIPTION_TYPES;

public final ChannelBanType CHANNEL_BAN;
@Unofficial public final BetaChannelCharityDonateType BETA_CHANNEL_CHARITY_DONATE;
public final @Unofficial BetaChannelCharityDonateType BETA_CHANNEL_CHARITY_DONATE;
public final ChannelCheerType CHANNEL_CHEER;
public final ChannelFollowType CHANNEL_FOLLOW;
public final ChannelGoalBeginType CHANNEL_GOAL_BEGIN;
Expand Down Expand Up @@ -46,6 +46,8 @@ public class SubscriptionTypes {
public final PredictionProgressType PREDICTION_PROGRESS;
public final PredictionLockType PREDICTION_LOCK;
public final PredictionEndType PREDICTION_END;
public final @Unofficial BetaShieldModeBeginType BETA_SHIELD_MODE_BEGIN_TYPE;
public final @Unofficial BetaShieldModeEndType BETA_SHIELD_MODE_END_TYPE;
public final StreamOfflineType STREAM_OFFLINE;
public final StreamOnlineType STREAM_ONLINE;
public final UserAuthorizationGrantType USER_AUTHORIZATION_GRANT;
Expand Down Expand Up @@ -92,6 +94,8 @@ public class SubscriptionTypes {
PREDICTION_PROGRESS = new PredictionProgressType(),
PREDICTION_LOCK = new PredictionLockType(),
PREDICTION_END = new PredictionEndType(),
BETA_SHIELD_MODE_BEGIN_TYPE = new BetaShieldModeBeginType(),
BETA_SHIELD_MODE_END_TYPE = new BetaShieldModeEndType(),
STREAM_OFFLINE = new StreamOfflineType(),
STREAM_ONLINE = new StreamOnlineType(),
USER_AUTHORIZATION_GRANT = new UserAuthorizationGrantType(),
Expand Down
Expand Up @@ -1811,6 +1811,46 @@ default HystrixCommand<ModeratorEventList> getModeratorEvents(
return this.getModeratorEvents(authToken, broadcasterId, userIds, after, 20);
}

/**
* Gets the broadcaster’s Shield Mode activation status.
*
* @param authToken User access token that includes the moderator:read:shield_mode or moderator:manage:shield_mode scope.
* @param broadcasterId The ID of the broadcaster whose Shield Mode activation status you want to get.
* @param moderatorId The ID of the broadcaster or a user that is one of the broadcaster’s moderators. This ID must match the user ID in the access token.
* @return ShieldModeStatusWrapper
*/
@Unofficial
@RequestLine("GET /moderation/shield_mode?broadcaster_id={broadcaster_id}&moderator_id={moderator_id}")
@Headers("Authorization: Bearer {token}")
HystrixCommand<ShieldModeStatusWrapper> getShieldModeStatus(
@Param("token") String authToken,
@Param("broadcaster_id") String broadcasterId,
@Param("moderator_id") String moderatorId
);

/**
* Activates or deactivates the broadcaster’s Shield Mode.
*
* @param authToken User access token that includes the moderator:manage:shield_mode scope.
* @param broadcasterId The ID of the broadcaster whose Shield Mode you want to activate or deactivate.
* @param moderatorId The ID of the broadcaster or a user that is one of the broadcaster’s moderators. This ID must match the user ID in the access token.
* @param active A Boolean value that determines whether to activate Shield Mode.
* @return ShieldModeStatusWrapper
*/
@Unofficial
@RequestLine("PUT /moderation/shield_mode?broadcaster_id={broadcaster_id}&moderator_id={moderator_id}")
@Headers({
"Authorization: Bearer {token}",
"Content-Type: application/json"
})
@Body("%7B\"is_active\":{is_active}%7D")
HystrixCommand<ShieldModeStatusWrapper> updateShieldModeStatus(
@Param("token") String authToken,
@Param("broadcaster_id") String broadcasterId,
@Param("moderator_id") String moderatorId,
@Param("is_active") boolean active
);

/**
* Get information about all polls or specific polls for a Twitch channel.
* <p>
Expand Down
@@ -0,0 +1,50 @@
package com.github.twitch4j.helix.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.time.Instant;

@Data
@Setter(AccessLevel.PRIVATE)
public class ShieldModeStatus {

/**
* Whether Shield Mode is active.
*/
@Accessors(fluent = true)
@JsonProperty("is_active")
private Boolean isActive;

/**
* An ID that identifies the moderator that last activated Shield Mode.
* <p>
* Is an empty string if Shield Mode hasn't been previously activated.
*/
private String moderatorId;

/**
* The moderator’s display name.
* <p>
* Is an empty string if Shield Mode hasn't been previously activated.
*/
private String moderatorName;

/**
* The moderator’s login name.
* <p>
* Is an empty string if Shield Mode hasn't been previously activated.
*/
private String moderatorLogin;

/**
* The UTC timestamp of when Shield Mode was last activated.
* <p>
* Is an empty string if Shield Mode hasn't been previously activated.
*/
private Instant lastActivatedAt;

}
@@ -0,0 +1,25 @@
package com.github.twitch4j.helix.domain;

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

import java.util.List;

@Data
@Setter(AccessLevel.PRIVATE)
public class ShieldModeStatusWrapper {

/**
* A list that contains a single object with the broadcaster’s Shield Mode status.
*/
private List<ShieldModeStatus> data;

/**
* @return a single object with the broadcaster’s Shield Mode status.
*/
public ShieldModeStatus get() {
return data.get(0);
}

}