-
-
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 2 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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,122 @@ | ||||||||||
| package net.dv8tion.jda.api.entities.subscription; | ||||||||||
|
|
||||||||||
| import net.dv8tion.jda.internal.JDAImpl; | ||||||||||
| import net.dv8tion.jda.internal.utils.EntityString; | ||||||||||
|
|
||||||||||
| import javax.annotation.Nonnull; | ||||||||||
| import javax.annotation.Nullable; | ||||||||||
| import java.time.OffsetDateTime; | ||||||||||
| import java.util.List; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Representation of a Discord Subscription | ||||||||||
| * <br> This class is immutable | ||||||||||
| */ | ||||||||||
| public class Subscription | ||||||||||
| { | ||||||||||
| private final JDAImpl api; | ||||||||||
| 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 Subscription(@Nonnull final JDAImpl api, 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.api = api; | ||||||||||
| 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; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public Long getId() | ||||||||||
|
||||||||||
| public Long getId() | |
| public long getId() |
Outdated
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.
| public Long getSubscriberId() | |
| public long getSubscriberId() |
Outdated
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.
Not needed imo, and also don't expose internals in API
Outdated
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.
| { | |
| return false; | |
| } | |
| return false; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package net.dv8tion.jda.api.entities.subscription; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| /** | ||
| * Representation of a Discord Subscription Status | ||
| */ | ||
| public enum SubscriptionStatus | ||
|
||
| { | ||
| UNKNOWN(-1),ACTIVE(0), ENDING(1), INACTIVE(2); | ||
|
|
||
| private final int id; | ||
|
|
||
| SubscriptionStatus(int id){ | ||
| this.id = id; | ||
| } | ||
|
|
||
| @Nonnull | ||
| public static SubscriptionStatus fromKey(int id){ | ||
| for (SubscriptionStatus status : values()){ | ||
| if(status.id == id){ | ||
| return status; | ||
| } | ||
| } | ||
| return UNKNOWN; | ||
| } | ||
|
|
||
| public int getId(){ | ||
| return id; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -48,6 +48,8 @@ | |||||
| import net.dv8tion.jda.api.entities.messages.MessagePoll; | ||||||
| import net.dv8tion.jda.api.entities.messages.MessageSnapshot; | ||||||
| import net.dv8tion.jda.api.entities.sticker.*; | ||||||
| import net.dv8tion.jda.api.entities.subscription.Subscription; | ||||||
| import net.dv8tion.jda.api.entities.subscription.SubscriptionStatus; | ||||||
| import net.dv8tion.jda.api.entities.templates.Template; | ||||||
| import net.dv8tion.jda.api.entities.templates.TemplateChannel; | ||||||
| import net.dv8tion.jda.api.entities.templates.TemplateGuild; | ||||||
|
|
@@ -392,7 +394,8 @@ public GuildImpl createGuild(long guildId, DataObject guildJson, TLongObjectMap< | |||||
| LOG.error("Guild is missing a SelfMember. GuildId: {}", guildId); | ||||||
| LOG.debug("Guild is missing a SelfMember. GuildId: {} JSON: \n{}", guildId, guildJson); | ||||||
| // This is actually a gateway request | ||||||
| guildObj.retrieveMembersByIds(api.getSelfUser().getIdLong()).onSuccess(m -> { | ||||||
| guildObj.retrieveMembersByIds(api.getSelfUser().getIdLong()).onSuccess(m -> | ||||||
| { | ||||||
| if (m.isEmpty()) | ||||||
| LOG.warn("Was unable to recover SelfMember for guild with id {}. This guild might be corrupted!", guildId); | ||||||
| else | ||||||
|
|
@@ -2613,6 +2616,42 @@ public Entitlement createEntitlement(DataObject object) | |||||
| ); | ||||||
| } | ||||||
|
|
||||||
| public Subscription createSubscription(DataObject object) | ||||||
| { | ||||||
| DataArray skuIDs = object.getArray("sku_ids"); | ||||||
| DataArray entitlementsIDs = object.getArray("entitlement_ids"); | ||||||
| DataArray renewalSkuIDs = object.optArray("renewal_sku_ids").orElse(null); | ||||||
| OffsetDateTime canceledAt = object.getOffsetDateTime("canceled_at", null); | ||||||
|
|
||||||
|
|
||||||
| List<Long> mappedSkuIds = mapDataArrayToLongList(skuIDs); | ||||||
| List<Long> mappedEntitlementsIds = mapDataArrayToLongList(entitlementsIDs); | ||||||
| List<Long> mappedRenewalSkuIds = Optional.ofNullable(renewalSkuIDs) | ||||||
| .map(this::mapDataArrayToLongList) | ||||||
| .orElse(null); | ||||||
|
|
||||||
|
|
||||||
| return new Subscription( | ||||||
| getJDA(), | ||||||
| object.getUnsignedLong("id"), | ||||||
| object.getUnsignedLong("user_id", 0), | ||||||
|
||||||
| object.getUnsignedLong("user_id", 0), | |
| object.getUnsignedLong("user_id"), |
Outdated
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.
| public List<Long> mapDataArrayToLongList(DataArray dataArray) | |
| private List<Long> mapDataArrayToLongList(DataArray dataArray) |
Maybe rename to mapToLongList
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.
Implement
ISnowflake