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

Add support for premium app subscriptions #2583

Merged
merged 76 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
a6106ef
feat: premium app subscription entitlement implementation
Giuliopime Nov 13, 2023
9f6d5e6
fix: missing nullable on user id
Giuliopime Nov 13, 2023
9611721
fix: missing null default values
Giuliopime Nov 13, 2023
cc24f9f
feat: interaction response type for "Premium required" interaction re…
Giuliopime Nov 13, 2023
2634fbf
feat: entitlements property for interaction
Giuliopime Nov 13, 2023
8282d45
chore: docs
Giuliopime Nov 14, 2023
9ba0d71
fix: missing listener adapter methods
Giuliopime Nov 14, 2023
020f464
fix: copyright
Giuliopime Nov 14, 2023
4751083
chore: javax annotations, streams instead of for loops, entity builde…
Giuliopime Nov 14, 2023
3094a35
Update src/main/java/net/dv8tion/jda/api/requests/restaction/interact…
Giuliopime Nov 17, 2023
1412043
Update src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Giuliopime Nov 17, 2023
4b4110b
Update src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Giuliopime Nov 17, 2023
4320979
Update src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Giuliopime Nov 17, 2023
43b48a8
Update src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Giuliopime Nov 17, 2023
eae8276
Update src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Giuliopime Nov 17, 2023
ce74c11
Update src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Giuliopime Nov 17, 2023
5e8549e
Update src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Giuliopime Nov 17, 2023
f87421e
fix: enum instead of int for EntitlementType
Giuliopime Nov 17, 2023
ccbb6a0
Update src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Giuliopime Nov 18, 2023
8dde5cd
fix: default implementations for String ids
Giuliopime Nov 18, 2023
97ce68c
Update src/main/java/net/dv8tion/jda/internal/handle/EntitlementUpdat…
Giuliopime Nov 21, 2023
7d8788f
Update src/main/java/net/dv8tion/jda/internal/interactions/Interactio…
Giuliopime Nov 21, 2023
80d14a8
Update src/main/java/net/dv8tion/jda/internal/interactions/command/Co…
Giuliopime Nov 21, 2023
4deb50c
Update src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Giuliopime Nov 21, 2023
d7a2dd6
Update src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Giuliopime Nov 21, 2023
380cc72
Update src/main/java/net/dv8tion/jda/api/events/entitlement/Entitleme…
Giuliopime Nov 21, 2023
627c012
feat: Create the ability to retrieve Entitlements from Discord
MartinItsLinda Dec 3, 2023
1b4f664
chore: Alter method documentation for EntitlementPaginationAction#guild
MartinItsLinda Dec 3, 2023
af22114
fix: Misleading and incorrect documentation on EntitlementPaginationA…
MartinItsLinda Dec 3, 2023
583c198
fix: Typo
MartinItsLinda Dec 3, 2023
5035e38
Merge pull request #1 from Tempo-Bot-Ltd/feat/premium-app-subscriptions
Giuliopime Dec 3, 2023
202f143
fix: Incorrect Nonnull annotations, should be javax not jetbrains
MartinItsLinda Dec 3, 2023
0ee89be
fix: change to use of primitive types instead, use a List instead of …
MartinItsLinda Dec 3, 2023
cc105cb
fix: should be primitive type not boxed type
MartinItsLinda Dec 3, 2023
521eb57
fix: change method signatures from getStartsAt/EndsAt to getTimeStart…
MartinItsLinda Dec 3, 2023
d48f3fd
fix: package-info, documentation wording and make GenericEntitlementE…
MartinItsLinda Dec 3, 2023
649dc7a
fix: remove retrieveEntitlements() from ShardManager
MartinItsLinda Dec 3, 2023
bbe6dc0
fix: spacing and ensure non-nullability of entitlements received thro…
MartinItsLinda Dec 3, 2023
55d5fee
chore: add documentation for IPremiumRequiredReplyCallback to Interac…
MartinItsLinda Dec 3, 2023
ccf47eb
fix: skuIds list should be cleared whenever it is updated
MartinItsLinda Dec 3, 2023
1f23ee6
Merge pull request #2 from Tempo-Bot-Ltd/feat/premium-app-subscriptions
Giuliopime Dec 3, 2023
82695dd
chore: import and docs for entitlement delete event
Giuliopime Dec 3, 2023
4b9df54
fix: delete entitlement event description to match update one
Giuliopime Dec 3, 2023
3ffc819
chore: better docs for entitlement delete event
Giuliopime Dec 5, 2023
e200e35
fix: primitives cannot be null
MartinItsLinda Dec 9, 2023
14fe8d5
fix: remove unnecessary override
MartinItsLinda Dec 9, 2023
2294820
fix: remove unused import
MartinItsLinda Dec 9, 2023
bd5b848
fix: formatting error
MartinItsLinda Dec 9, 2023
93e3bed
feat: add overloads to support passing a String guildID and guild obj…
MartinItsLinda Dec 9, 2023
05232f3
fix: only update skuIds if all skuIds to add are valid snowflakes
MartinItsLinda Dec 9, 2023
a20ead5
chore: improve documentation for EntitlementPaginationAction and add …
MartinItsLinda Dec 9, 2023
a7a9644
Merge pull request #3 from Tempo-Bot-Ltd/feat/premium-app-subscriptions
Giuliopime Dec 9, 2023
10826b7
chore: document throwable exceptions by #guild(Guild) and #guild(Stri…
MartinItsLinda Dec 11, 2023
7635deb
Merge pull request #4 from Tempo-Bot-Ltd/feat/premium-app-subscriptions
Giuliopime Dec 11, 2023
0fd8e01
fix: formatting
MartinItsLinda Dec 11, 2023
4152996
Merge pull request #5 from Tempo-Bot-Ltd/feat/premium-app-subscriptions
Giuliopime Dec 11, 2023
8257acd
fix: should return the delegate method
MartinItsLinda Dec 11, 2023
cd422e3
fix: remove implied exception
MartinItsLinda Dec 11, 2023
fff0d72
chore: add throws docs for skuIds and fix grammatical mistakes
MartinItsLinda Dec 11, 2023
c12275c
Merge pull request #6 from Tempo-Bot-Ltd/feat/premium-app-subscriptions
Giuliopime Dec 11, 2023
28299f7
fix: getUserId cannot return an empty value
MartinItsLinda Dec 12, 2023
abc97f4
fix: respect useCache value
MartinItsLinda Dec 13, 2023
3e534dc
Merge branch 'Giuliopime:feat/premium-app-subscriptions' into feat/pr…
MartinItsLinda Feb 8, 2024
8bd968f
fix: getUserId cannot be nullable so removed nullable annotation
MartinItsLinda Feb 8, 2024
6fb0340
fix: inifnite requests on pagination for entitlements
MartinItsLinda Feb 8, 2024
6d53626
Merge pull request #7 from Tempo-Bot-Ltd/feat/premium-app-subscriptions
Giuliopime Feb 8, 2024
5e63511
Merge remote-tracking branch 'origin/master' into feat/premium-app-su…
MinnDevelopment Mar 10, 2024
e49baa2
chore: amend documentation for Entitlement
MartinItsLinda Mar 20, 2024
ef8b8ba
fix: make entitlement builder return an unmodifiable list
MartinItsLinda Mar 20, 2024
65ce4e8
Add Collection<String> overload for skuIds in EntitlementPaginationAc…
MartinItsLinda Mar 20, 2024
8f1865c
fix: replace order with getSupportedOrders instead
MartinItsLinda Apr 2, 2024
43d8fa8
chore: change IPremiumRequiredReplyCallback documentation to mention …
MartinItsLinda Apr 2, 2024
871d83a
chore: make monetization link open in a new window
MartinItsLinda Apr 2, 2024
b0dfd92
Merge pull request #8 from Tempo-Bot-Ltd/feat/premium-app-subscriptions
Giuliopime Apr 2, 2024
5eaef9b
Merge pull request #9 from discord-jda/master
Giuliopime Apr 2, 2024
15c6a05
Remove closing tag
MinnDevelopment Apr 6, 2024
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
203 changes: 203 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.entities;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.time.OffsetDateTime;

/**
* Represents a Discord Entitlement for premium App subscriptions.
* <br>This should contain all information provided from Discord about an {@link Entitlement Entitlement}.
*/
public interface Entitlement extends ISnowflake
{
/**
* The id of the entitlement
*
* @return The id of the {@link Entitlement Entitlement}
*/
@Override
long getIdLong();

/**
* The id of the SKU related to this {@link Entitlement Entitlement}
*
* @return The id of the SKU related to this {@link Entitlement Entitlement}
*/
long getSkuIdLong();

/**
* The id of the SKU related to this {@link Entitlement Entitlement}
*
* @return The id of the SKU related to this {@link Entitlement Entitlement}
*/
@Nonnull
default String getSkuId()
{
return Long.toUnsignedString(getSkuIdLong());
}

/**
* The id of the parent application of this {@link Entitlement Entitlement}
*
* @return The id of the parent application of this {@link Entitlement Entitlement}
*/
long getApplicationIdLong();

/**
* The id of the parent application of this {@link Entitlement Entitlement}
*
* @return The id of the parent application of this {@link Entitlement Entitlement}
*/
@Nonnull
default String getApplicationId()
{
return Long.toUnsignedString(getApplicationIdLong());
}

/**
* The id of the user that purchased the {@link Entitlement Entitlement}
*
* @return The id of the user that purchased the {@link Entitlement Entitlement}
*/
@Nullable
Long getUserIdLong();

/**
* The id of the user that purchased the {@link Entitlement Entitlement}
*
* @return The id of the user that purchased the {@link Entitlement Entitlement}
*/
@Nullable
default String getUserId()
{
if (getUserIdLong() == null) {
return null;
}

return Long.toUnsignedString(getUserIdLong());
}

/**
* The guild id that is granted access to the {@link Entitlement Entitlement}'s SKU
*
* @return The id of the guild that is granted access to the {@link Entitlement Entitlement}'s SKU,
* or {@code null} if this entitlement is related to a subscription of type "User Subscription"
*/
@Nullable
Long getGuildIdLong();

/**
* The guild id that is granted access to the {@link Entitlement Entitlement}'s SKU
*
* @return The id of the guild that is granted access to the {@link Entitlement Entitlement}'s SKU,
* or {@code null} if this entitlement is related to a subscription of type "User Subscription"
*/
@Nullable
default String getGuildId()
{
if (getGuildIdLong() == null) {
return null;
}

return Long.toUnsignedString(getGuildIdLong());
}

/**
* The type of the Entitlement
* <br>The only possible type of Entitlement currently is {@link EntitlementType#APPLICATION_SUBSCRIPTION}
* <br>Discord doesn't currently support other types for entitlements.
*
* @return the {@link Entitlement Entitlement} type
*/
@Nonnull
EntitlementType getType();

/**
* Whether the {@link Entitlement Entitlement} has been deleted or not.
*
* @return True if the {@link Entitlement Entitlement} was deleted, False otherwise
*
* @see net.dv8tion.jda.api.events.entitlement.EntitlementDeleteEvent
*/
boolean isDeleted();

/**
* The start date at which the {@link Entitlement Entitlement} is valid.
*
* @return Start date at which the {@link Entitlement Entitlement} is valid. Not present when using test entitlements.
*/
@Nullable
OffsetDateTime getStartsAt();

/**
* Date at which the {@link Entitlement Entitlement} is no longer valid.
*
* @return Date at which the {@link Entitlement Entitlement} is no longer valid. Not present when using test entitlements.
*/
@Nullable
OffsetDateTime getEndsAt();

/**
* Represents the type of this Entitlement
*/
enum EntitlementType {
APPLICATION_SUBSCRIPTION(8),
/**
* Placeholder for unsupported types.
*/
UNKNOWN(-1);

private final int key;

EntitlementType(int key)
{
this.key = key;
}

/**
* The Discord defined id key for this EntitlementType.
*
* @return the id key.
*/
public int getKey()
{
return key;
}

/**
* Gets the EntitlementType related to the provided key.
* <br>If an unknown key is provided, this returns {@link #UNKNOWN}
*
* @param key
* The Discord key referencing a EntitlementType.
*
* @return The EntitlementType that has the key provided, or {@link #UNKNOWN} for unknown key.
*/
@Nonnull
public static EntitlementType fromKey(int key)
{
for (EntitlementType type : values())
{
if (type.getKey() == key)
return type;
}
return UNKNOWN;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.events.entitlement;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Entitlement;

import javax.annotation.Nonnull;

/**
* Indicates that a user subscribed to a SKU.
*
* @see #getEntitlement()
*/
public class EntitlementCreateEvent extends GenericEntitlementEvent
{
public EntitlementCreateEvent(@Nonnull JDA api, long responseNumber, @Nonnull Entitlement entitlement)
{
super(api, responseNumber, entitlement);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.events.entitlement;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Entitlement;

import javax.annotation.Nonnull;

/**
* Indicates a user's entitlement is deleted. Entitlement deletions are infrequent, and occur when:
* <ul>
* <li>Discord issues a refund for a subscription</li>
* <li>Discord removes an entitlement from a user via internal tooling</li>
* </ul>
* <p><b>Notice</b><br>
* Entitlements are not deleted when they expire.
* <br>
* If a user's subscription is cancelled, you will not receive an {@link EntitlementDeleteEvent EntitlementDeleteEvent}.
* <br>Instead, you will simply not receive an {@link EntitlementUpdateEvent EntitlementUpdateEvent} with a new {@link Entitlement#getEndsAt() endsAt} date at the end of the billing period.
*
* @see #getEntitlement()
* @see EntitlementUpdateEvent
*/
public class EntitlementDeleteEvent extends GenericEntitlementEvent
{
public EntitlementDeleteEvent(@Nonnull JDA api, long responseNumber, @Nonnull Entitlement entitlement)
{
super(api, responseNumber, entitlement);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.events.entitlement;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Entitlement;

import javax.annotation.Nonnull;

/**
* Indicates a user's subscription has renewed for the next billing period.
* The {@link Entitlement#getEndsAt() endsAt} field will have an updated value with the new expiration date.
*
* <p><b>Notice</b><br>
* If a user's subscription is cancelled, you will not receive an {@link EntitlementDeleteEvent EntitlementDeleteEvent}.
* <br>Instead, you will simply not receive an {@link EntitlementUpdateEvent EntitlementUpdateEvent} with a new {@link Entitlement#getEndsAt() endsAt} date at the end of the billing period.
*
* @see #getEntitlement()
*/
public class EntitlementUpdateEvent extends GenericEntitlementEvent
{
public EntitlementUpdateEvent(@Nonnull JDA api, long responseNumber, @Nonnull Entitlement entitlement)
{
super(api, responseNumber, entitlement);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.events.entitlement;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Entitlement;
import net.dv8tion.jda.api.events.Event;

import javax.annotation.Nonnull;

/**
* Indicates that an {@link Entitlement Entitlement} was either created, updated or deleted
*
* @see EntitlementCreateEvent
* @see EntitlementUpdateEvent
* @see EntitlementDeleteEvent
*/
public abstract class GenericEntitlementEvent extends Event
{
protected final Entitlement entitlement;

GenericEntitlementEvent(@Nonnull JDA api, long responseNumber, @Nonnull Entitlement entitlement) {
super(api, responseNumber);
this.entitlement = entitlement;
}

@Nonnull
public Entitlement getEntitlement()
{
return entitlement;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Events that indicate that a {@link net.dv8tion.jda.api.entities.Entitlement Entitlement}
* is either created, updated or deleted.
*/
package net.dv8tion.jda.api.events.entitlement;
Loading