Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/main/java/net/dv8tion/jda/api/JDA.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Copy link
Contributor

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

* @return {@link RestAction} - Type: {@link Subscription}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an extra newline between @param and @return

* <br>The list of subscriptions by provided sku id
*/
@Nonnull
@CheckReturnValue
RestAction<Subscription> retrieveSubscriptionsBySkuId(long skuId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should accept a SkuSnowflake instead


/**
* 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to retrieveSubscriptionBySkuId, accept a SkuSnowflake, also make an overload where the subscriptionId is a String.

The overload accepting a String should be implemented, while the long one should be default

@Nonnull
default RestAction<Subscription> retrieveSubscriptionBySkuId(@Nonnull SkuSnowflake sku, long subscriptionId)
{
    return retrieveSubscriptionBySkuId(sku, Long.toUnsignedString(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.
Expand Down
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SKU is an acronym, so use all caps for it

*
* @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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to internal package


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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Use @Nonnull instead
  2. Annotations are on the line before the method declaration

{
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{
return false;
}
return false;

SubscriptionImpl other = (SubscriptionImpl) obj;
return other.id == this.id;
}

@Override
public String toString()
{
return new EntityString(this)
.addMetadata("id", id)
.toString();
}
}
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run the formatter on this class

{
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{
return status;
}
return status;

}
return UNKNOWN;
}

public int getId()
{
return id;
}
}
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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The subscription {@link Subscription}
*
* @return The subscription {@link Subscription}
* The {@link Subscription}
*
* @return The {@link Subscription}

*/
@Nonnull
public Subscription getSubscription()
{
return 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);
}
}
Loading