-
-
Notifications
You must be signed in to change notification settings - Fork 757
Created a Discord Subscription representation as well as a method for… #2885
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
0fc98c5
3e19266
f4ef5a7
598add1
cca4c55
2888722
670824b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import net.dv8tion.jda.api.entities.emoji.CustomEmoji; | ||
| import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji; | ||
| import net.dv8tion.jda.api.entities.sticker.*; | ||
| import net.dv8tion.jda.api.entities.subscription.Subscription; | ||
| import net.dv8tion.jda.api.events.GenericEvent; | ||
| import net.dv8tion.jda.api.hooks.IEventManager; | ||
| import net.dv8tion.jda.api.interactions.commands.Command; | ||
|
|
@@ -2122,6 +2123,32 @@ default RestAction<Void> deleteTestEntitlement(@Nonnull String entitlementId) | |
| @CheckReturnValue | ||
| RestAction<Void> deleteTestEntitlement(long entitlementId); | ||
|
|
||
| /** | ||
| * Retrieves a List of {@link Subscription} by sku id | ||
| * | ||
| * @param skuId | ||
| * The sku id of the List | ||
| * @return {@link RestAction} - Type: {@link Subscription} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an extra newline between |
||
| * <br>The list of subscriptions by provided sku id | ||
| */ | ||
| @Nonnull | ||
| @CheckReturnValue | ||
| RestAction<Subscription> retrieveSubscriptionsBySkuId(long skuId); | ||
|
||
|
|
||
| /** | ||
| * Retrieves a {@link Subscription} by its id and sku id | ||
| * | ||
| * @param skuId | ||
| * The sku id of the List where to find subscription | ||
| * @param subscriptionId | ||
| * The id of the subscription to retrieve | ||
| * @return {@link RestAction} - Type: {@link Subscription} | ||
| * <br> The Subscription with the provided id | ||
| */ | ||
| @Nonnull | ||
| @CheckReturnValue | ||
| RestAction<Subscription> retrieveSubscriptionBySkuIdAndSubscriptionId(long skuId, long subscriptionId); | ||
|
||
|
|
||
| /** | ||
| * Configures the required scopes applied to the {@link #getInviteUrl(Permission...)} and similar methods. | ||
| * <br>To use slash commands you must add {@code "applications.commands"} to these scopes. The scope {@code "bot"} is always applied. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| package net.dv8tion.jda.api.entities.subscription; | ||
|
|
||
| import net.dv8tion.jda.api.entities.ISnowflake; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
| import java.time.OffsetDateTime; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * Representation of a Discord Subscription | ||
| * | ||
| * @see <a href="https://discord.com/developers/docs/resources/subscription" target="_blank">Discord Docs about Subscriptions</a> | ||
| */ | ||
| public interface Subscription extends ISnowflake | ||
| { | ||
| /** | ||
| * The user who subscribed | ||
| * | ||
| * @return a use who subscribed | ||
| */ | ||
| @Nonnull | ||
| long getSubscriberIdLong(); | ||
|
|
||
| /** | ||
| * The user who subscribed | ||
| * | ||
| * @return a use who subscribed | ||
| */ | ||
| @Nonnull | ||
| default String getSubscriberId() | ||
| { | ||
| return Long.toUnsignedString(getSubscriberIdLong()); | ||
| } | ||
|
|
||
| /** | ||
| * The sku id's related to this | ||
|
||
| * | ||
| * @return The list of sku id's related to this {@link Subscription} | ||
| */ | ||
| @Nonnull | ||
| List<Long> getSkuIdsLong(); | ||
|
|
||
| /** | ||
| * The sku id's related to this | ||
| * | ||
| * @return The list sku id's related to this {@link Subscription} | ||
| */ | ||
| @Nonnull | ||
| default List<String> getSkuIds() | ||
| { | ||
| return getSkuIdsLong().stream() | ||
| .map(Long::toUnsignedString) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| /** | ||
| * The entitlements id's related to this {@link Subscription} | ||
| * | ||
| * @return The sku id's related to this {@link Subscription} | ||
| */ | ||
| @Nonnull | ||
| List<Long> getEntitlementIdsLong(); | ||
|
|
||
| /** | ||
| * The entitlements id's related to this {@link Subscription} | ||
| * | ||
| * @return The entitlements id's related to this {@link Subscription} | ||
| */ | ||
| @Nonnull | ||
| default List<String> getEntitlementIds() | ||
| { | ||
| return getEntitlementIdsLong().stream() | ||
| .map(Long::toUnsignedString) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| /** | ||
| * The renewal sku id's related to this {@link Subscription} | ||
| * | ||
| * @return The renewal sku id's related to this {@link Subscription} | ||
| */ | ||
| @Nullable | ||
| List<Long> getRenewalSkuIdsLong(); | ||
|
|
||
| /** | ||
| * The renewal sku id's related to this {@link Subscription} | ||
| * | ||
| * @return The renewal sku id's related to this {@link Subscription} | ||
| */ | ||
| @Nullable | ||
| default List<String> getRenewalSkuIds() | ||
| { | ||
| return getRenewalSkuIdsLong().stream() | ||
| .map(Long::toUnsignedString) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| /** | ||
| * The start of period of this {@link Subscription} | ||
| * | ||
| * @return The start of period of this {@link Subscription} | ||
| */ | ||
| @Nonnull | ||
| OffsetDateTime getCurrentPeriodStart(); | ||
|
|
||
| /** | ||
| * The end of period of this {@link Subscription} | ||
| * | ||
| * @return The end of period of this {@link Subscription} | ||
| */ | ||
| @Nonnull | ||
| OffsetDateTime getCurrentPeriodEnd(); | ||
|
|
||
| /** | ||
| * The canceled time of this {@link Subscription} | ||
| * | ||
| * @return The canceled time of this {@link Subscription} | ||
| */ | ||
| @Nullable | ||
| OffsetDateTime getCanceledAt(); | ||
|
|
||
| /** | ||
| * The status of this {@link Subscription} | ||
| * | ||
| * @return The status of this {@link Subscription} | ||
| */ | ||
| @Nonnull | ||
| SubscriptionStatus getStatus(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,114 @@ | ||||||||||
| package net.dv8tion.jda.api.entities.subscription; | ||||||||||
|
||||||||||
|
|
||||||||||
| import net.dv8tion.jda.internal.utils.EntityString; | ||||||||||
| import org.jetbrains.annotations.NotNull; | ||||||||||
|
|
||||||||||
| import javax.annotation.Nonnull; | ||||||||||
| import javax.annotation.Nullable; | ||||||||||
| import java.time.OffsetDateTime; | ||||||||||
| import java.util.List; | ||||||||||
|
|
||||||||||
|
|
||||||||||
| public class SubscriptionImpl implements Subscription | ||||||||||
| { | ||||||||||
| private final long id; | ||||||||||
| private final long subscriberId; | ||||||||||
| private final List<Long> skuIDs; | ||||||||||
| private final List<Long> entitlementIDs; | ||||||||||
| private final List<Long> renewalSkuIDs; | ||||||||||
| private final OffsetDateTime currentPeriodStart; | ||||||||||
| private final OffsetDateTime currentPeriodEnd; | ||||||||||
| private final OffsetDateTime canceledAt; | ||||||||||
| private final SubscriptionStatus status; | ||||||||||
|
|
||||||||||
| public SubscriptionImpl(final long id, final long subscriberId, @Nonnull final List<Long> skuIDs, | ||||||||||
| @Nonnull final List<Long> entitlementIDs, @Nullable final List<Long> renewalSkuIDs, | ||||||||||
| @Nonnull final OffsetDateTime currentPeriodStart, @Nonnull final OffsetDateTime currentPeriodEnd, @Nullable final OffsetDateTime canceledAt, | ||||||||||
| @Nonnull final SubscriptionStatus status) | ||||||||||
| { | ||||||||||
|
|
||||||||||
| this.id = id; | ||||||||||
| this.subscriberId = subscriberId; | ||||||||||
| this.skuIDs = skuIDs; | ||||||||||
| this.entitlementIDs = entitlementIDs; | ||||||||||
| this.renewalSkuIDs = renewalSkuIDs; | ||||||||||
| this.currentPeriodStart = currentPeriodStart; | ||||||||||
| this.currentPeriodEnd = currentPeriodEnd; | ||||||||||
| this.canceledAt = canceledAt; | ||||||||||
| this.status = status; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @Nonnull | ||||||||||
| @Override | ||||||||||
| public long getIdLong() | ||||||||||
| { | ||||||||||
| return id; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public long getSubscriberIdLong() | ||||||||||
| { | ||||||||||
| return subscriberId; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public @NotNull List<Long> getSkuIdsLong() | ||||||||||
|
||||||||||
| { | ||||||||||
| return skuIDs; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public @NotNull List<Long> getEntitlementIdsLong() | ||||||||||
| { | ||||||||||
| return entitlementIDs; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public @Nullable List<Long> getRenewalSkuIdsLong() | ||||||||||
| { | ||||||||||
| return renewalSkuIDs; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public @NotNull OffsetDateTime getCurrentPeriodStart() | ||||||||||
| { | ||||||||||
| return currentPeriodStart; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public @NotNull OffsetDateTime getCurrentPeriodEnd() | ||||||||||
| { | ||||||||||
| return currentPeriodEnd; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public OffsetDateTime getCanceledAt() | ||||||||||
| { | ||||||||||
| return canceledAt; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public @NotNull SubscriptionStatus getStatus() | ||||||||||
| { | ||||||||||
| return status; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @Override | ||||||||||
| public int hashCode() | ||||||||||
| { | ||||||||||
| return Long.hashCode(id); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @Override | ||||||||||
| public boolean equals(Object obj) | ||||||||||
| { | ||||||||||
| if (this == obj) | ||||||||||
| return true; | ||||||||||
| if (!(obj instanceof SubscriptionImpl)) | ||||||||||
| { | ||||||||||
| return false; | ||||||||||
| } | ||||||||||
|
||||||||||
| { | |
| return false; | |
| } | |
| return false; |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,47 @@ | ||||||||||
| package net.dv8tion.jda.api.entities.subscription; | ||||||||||
|
|
||||||||||
| import javax.annotation.Nonnull; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Representation of a Discord Subscription Status | ||||||||||
| * | ||||||||||
| * @see <a href="https://discord.com/developers/docs/resources/subscription#subscription-statuses" target="_blank">Discord Docs about Subscription Statuses</a> | ||||||||||
| */ | ||||||||||
| public enum SubscriptionStatus | ||||||||||
|
||||||||||
| { | ||||||||||
| UNKNOWN(-1), ACTIVE(0), ENDING(1), INACTIVE(2); | ||||||||||
|
|
||||||||||
| private final int id; | ||||||||||
|
|
||||||||||
| SubscriptionStatus(int id) | ||||||||||
| { | ||||||||||
| this.id = id; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Gets the Subscription status related to the provided key. | ||||||||||
| * <br>If an unknown key is provided, this returns {@link #UNKNOWN} | ||||||||||
| * | ||||||||||
| * @param key | ||||||||||
| * The Discord key referencing a Subscription status. | ||||||||||
| * | ||||||||||
| * @return The Subscription status that has the key provided, or {@link #UNKNOWN} for unknown key. | ||||||||||
| */ | ||||||||||
| @Nonnull | ||||||||||
| public static SubscriptionStatus fromKey(int key) | ||||||||||
| { | ||||||||||
| for (SubscriptionStatus status : values()) | ||||||||||
| { | ||||||||||
| if (status.id == key) | ||||||||||
| { | ||||||||||
| return status; | ||||||||||
| } | ||||||||||
|
||||||||||
| { | |
| return status; | |
| } | |
| return status; |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,36 @@ | ||||||||||||||
| package net.dv8tion.jda.api.events.subscription; | ||||||||||||||
|
|
||||||||||||||
| import net.dv8tion.jda.api.JDA; | ||||||||||||||
| import net.dv8tion.jda.api.entities.subscription.Subscription; | ||||||||||||||
| import net.dv8tion.jda.api.events.Event; | ||||||||||||||
|
|
||||||||||||||
| import javax.annotation.Nonnull; | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Indicates that an {@link Subscription Subscription} was either created, updated, or deleted | ||||||||||||||
| * | ||||||||||||||
| * @see SubscriptionCreateEvent | ||||||||||||||
| * @see SubscriptionUpdateEvent | ||||||||||||||
| * @see SubscriptionDeleteEvent | ||||||||||||||
| */ | ||||||||||||||
| public abstract class GenericSubscriptionEvent extends Event | ||||||||||||||
| { | ||||||||||||||
| protected final Subscription subscription; | ||||||||||||||
|
|
||||||||||||||
| protected GenericSubscriptionEvent(@Nonnull JDA api, long responseNumber, @Nonnull Subscription subscription) | ||||||||||||||
| { | ||||||||||||||
| super(api, responseNumber); | ||||||||||||||
| this.subscription = subscription; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * The subscription {@link Subscription} | ||||||||||||||
| * | ||||||||||||||
| * @return The subscription {@link Subscription} | ||||||||||||||
|
||||||||||||||
| * The subscription {@link Subscription} | |
| * | |
| * @return The subscription {@link Subscription} | |
| * The {@link Subscription} | |
| * | |
| * @return The {@link Subscription} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package net.dv8tion.jda.api.events.subscription; | ||
|
|
||
| import net.dv8tion.jda.api.JDA; | ||
| import net.dv8tion.jda.api.entities.subscription.Subscription; | ||
|
|
||
| /** | ||
| * Indicate that a Subscription for Premium app was created | ||
| */ | ||
| public class SubscriptionCreateEvent extends GenericSubscriptionEvent | ||
| { | ||
| public SubscriptionCreateEvent(JDA api, long responseNumber, Subscription subscription) | ||
| { | ||
| super(api, responseNumber, subscription); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align with
@return, check other javadocs with the same issue