Skip to content

Commit 8ccfc56

Browse files
authored
Add premium buttons (#2752)
Deprecates replyWithPremiumRequired
1 parent e46bacb commit 8ccfc56

File tree

15 files changed

+546
-91
lines changed

15 files changed

+546
-91
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.dv8tion.jda.api.entities;
18+
19+
import net.dv8tion.jda.api.utils.MiscUtil;
20+
import net.dv8tion.jda.internal.entities.SkuSnowflakeImpl;
21+
22+
import javax.annotation.Nonnull;
23+
24+
/**
25+
* Represents an abstract SKU reference by only the SKU ID.
26+
*
27+
* <p>This is used for methods which only need a SKU ID to function, you cannot use this for getting any properties.
28+
*/
29+
public interface SkuSnowflake extends ISnowflake
30+
{
31+
/**
32+
* Creates a SKU instance which only wraps an ID.
33+
*
34+
* @param id
35+
* The SKU id
36+
*
37+
* @return A SKU snowflake instance
38+
*/
39+
@Nonnull
40+
static SkuSnowflake fromId(long id)
41+
{
42+
return new SkuSnowflakeImpl(id);
43+
}
44+
45+
/**
46+
* Creates a SKU instance which only wraps an ID.
47+
*
48+
* @param id
49+
* The SKU id
50+
*
51+
* @throws IllegalArgumentException
52+
* If the provided ID is not a valid snowflake
53+
*
54+
* @return A SKU snowflake instance
55+
*/
56+
@Nonnull
57+
static SkuSnowflake fromId(@Nonnull String id)
58+
{
59+
return fromId(MiscUtil.parseSnowflake(id));
60+
}
61+
}

src/main/java/net/dv8tion/jda/api/events/interaction/command/GenericCommandInteractionEvent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public ModalCallbackAction replyModal(@Nonnull Modal modal)
125125

126126
@Nonnull
127127
@Override
128+
@Deprecated
128129
@CheckReturnValue
129130
public PremiumRequiredCallbackAction replyWithPremiumRequired()
130131
{

src/main/java/net/dv8tion/jda/api/events/interaction/component/GenericComponentInteractionCreateEvent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public ModalCallbackAction replyModal(@Nonnull Modal modal)
132132

133133
@Nonnull
134134
@Override
135+
@Deprecated
135136
@CheckReturnValue
136137
public PremiumRequiredCallbackAction replyWithPremiumRequired()
137138
{

src/main/java/net/dv8tion/jda/api/interactions/Interaction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
* <br>Which supports choice suggestions for auto-complete interactions via {@link IAutoCompleteCallback#replyChoices(Command.Choice...)}</li>
4949
* <li>{@link IModalCallback}
5050
* <br>Which supports replying using a {@link Modal} via {@link IModalCallback#replyModal(Modal)}</li>
51-
* <li>{@link IPremiumRequiredReplyCallback}
52-
* <br>Which will reply stating that an {@link Entitlement Entitlement} is required</li>
5351
* </ul>
5452
*
5553
* <p>Once the interaction is acknowledged, you can not reply with these methods again. If the interaction is a {@link IDeferrableCallback deferrable},

src/main/java/net/dv8tion/jda/api/interactions/callbacks/IPremiumRequiredReplyCallback.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
package net.dv8tion.jda.api.interactions.callbacks;
1818

19-
import net.dv8tion.jda.api.requests.restaction.interactions.PremiumRequiredCallbackAction;
2019
import net.dv8tion.jda.api.entities.Entitlement;
20+
import net.dv8tion.jda.api.entities.SkuSnowflake;
21+
import net.dv8tion.jda.api.interactions.components.buttons.Button;
22+
import net.dv8tion.jda.api.requests.restaction.interactions.PremiumRequiredCallbackAction;
2123

2224
import javax.annotation.CheckReturnValue;
2325
import javax.annotation.Nonnull;
@@ -28,10 +30,19 @@
2830
* <p>Replying with {@link #replyWithPremiumRequired()} will automatically acknowledge this interaction.
2931
*
3032
* <p><b>Note:</b>This interaction requires <a href="https://discord.com/developers/docs/monetization/overview" target="_blank">monetization</a> to be enabled.
33+
*
34+
* @deprecated Replaced with {@link Button#premium(SkuSnowflake)},
35+
* see the <a href="https://discord.com/developers/docs/change-log#premium-apps-new-premium-button-style-deep-linking-url-schemes" target="_blank">Discord change logs</a> for more details.
3136
*/
37+
@Deprecated
3238
public interface IPremiumRequiredReplyCallback extends IDeferrableCallback
3339
{
40+
/**
41+
* @deprecated Replaced with {@link Button#premium(SkuSnowflake)},
42+
* see the <a href="https://discord.com/developers/docs/change-log#premium-apps-new-premium-button-style-deep-linking-url-schemes" target="_blank">Discord change logs</a> for more details.
43+
*/
3444
@Nonnull
45+
@Deprecated
3546
@CheckReturnValue
3647
PremiumRequiredCallbackAction replyWithPremiumRequired();
3748
}

src/main/java/net/dv8tion/jda/api/interactions/components/LayoutComponent.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
2121
import net.dv8tion.jda.api.utils.data.SerializableData;
2222
import net.dv8tion.jda.internal.utils.Checks;
23+
import net.dv8tion.jda.internal.utils.ComponentsUtil;
2324
import net.dv8tion.jda.internal.utils.Helpers;
2425
import org.jetbrains.annotations.Unmodifiable;
2526

@@ -207,7 +208,8 @@ default boolean isValid()
207208
* <br>This will locate and replace the existing component with the specified ID. If you provide null it will be removed instead.
208209
*
209210
* @param id
210-
* The custom id of this component, can also be a URL for a {@link Button} with {@link ButtonStyle#LINK}
211+
* The custom id of this component, can also be a URL for a {@link Button} with {@link ButtonStyle#LINK},
212+
* or an SKU id for {@link ButtonStyle#PREMIUM}
211213
* @param newComponent
212214
* The new component or null to remove it
213215
*
@@ -227,7 +229,7 @@ default ItemComponent updateComponent(@Nonnull String id, @Nullable ItemComponen
227229
if (!(component instanceof ActionComponent))
228230
continue;
229231
ActionComponent action = (ActionComponent) component;
230-
if (id.equals(action.getId()) || (action instanceof Button && id.equals(((Button) action).getUrl())))
232+
if (ComponentsUtil.isSameIdentifier(action, id))
231233
{
232234
if (newComponent == null)
233235
it.remove();

0 commit comments

Comments
 (0)