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 premium buttons #2752

Merged
merged 22 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 20 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
61 changes: 61 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/SkuSnowflake.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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 net.dv8tion.jda.api.utils.MiscUtil;
import net.dv8tion.jda.internal.entities.SkuSnowflakeImpl;

import javax.annotation.Nonnull;

/**
* Represents an abstract SKU reference by only the SKU ID.
*
* <p>This is used for methods which only need a SKU ID to function, you cannot use this for getting any properties.
*/
public interface SkuSnowflake extends ISnowflake
{
/**
* Creates a SKU instance which only wraps an ID.
*
* @param id
* The SKU id
*
* @return A SKU snowflake instance
*/
@Nonnull
static SkuSnowflake fromId(long id)
{
return new SkuSnowflakeImpl(id);
}

/**
* Creates a SKU instance which only wraps an ID.
*
* @param id
* The SKU id
*
* @throws IllegalArgumentException
* If the provided ID is not a valid snowflake
*
* @return A SKU snowflake instance
*/
@Nonnull
static SkuSnowflake fromId(@Nonnull String id)
{
return fromId(MiscUtil.parseSnowflake(id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public ModalCallbackAction replyModal(@Nonnull Modal modal)

@Nonnull
@Override
@Deprecated
@CheckReturnValue
public PremiumRequiredCallbackAction replyWithPremiumRequired()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public ModalCallbackAction replyModal(@Nonnull Modal modal)

@Nonnull
@Override
@Deprecated
@CheckReturnValue
public PremiumRequiredCallbackAction replyWithPremiumRequired()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
* <br>Which supports choice suggestions for auto-complete interactions via {@link IAutoCompleteCallback#replyChoices(Command.Choice...)}</li>
* <li>{@link IModalCallback}
* <br>Which supports replying using a {@link Modal} via {@link IModalCallback#replyModal(Modal)}</li>
* <li>{@link IPremiumRequiredReplyCallback}
* <br>Which will reply stating that an {@link Entitlement Entitlement} is required</li>
* </ul>
*
* <p>Once the interaction is acknowledged, you can not reply with these methods again. If the interaction is a {@link IDeferrableCallback deferrable},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

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

import net.dv8tion.jda.api.requests.restaction.interactions.PremiumRequiredCallbackAction;
import net.dv8tion.jda.api.entities.Entitlement;
import net.dv8tion.jda.api.entities.SkuSnowflake;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.requests.restaction.interactions.PremiumRequiredCallbackAction;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
Expand All @@ -28,10 +30,19 @@
* <p>Replying with {@link #replyWithPremiumRequired()} will automatically acknowledge this interaction.
*
* <p><b>Note:</b>This interaction requires <a href="https://discord.com/developers/docs/monetization/overview" target="_blank">monetization</a> to be enabled.
*
* @deprecated Replaced with {@link Button#premium(SkuSnowflake)},
* 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.
*/
@Deprecated
public interface IPremiumRequiredReplyCallback extends IDeferrableCallback
{
/**
* @deprecated Replaced with {@link Button#premium(SkuSnowflake)},
* 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.
*/
@Nonnull
@Deprecated
@CheckReturnValue
PremiumRequiredCallbackAction replyWithPremiumRequired();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
import net.dv8tion.jda.api.utils.data.SerializableData;
import net.dv8tion.jda.internal.utils.Checks;
import net.dv8tion.jda.internal.utils.ComponentsUtil;
import net.dv8tion.jda.internal.utils.Helpers;
import org.jetbrains.annotations.Unmodifiable;

Expand Down Expand Up @@ -207,7 +208,8 @@ default boolean isValid()
* <br>This will locate and replace the existing component with the specified ID. If you provide null it will be removed instead.
*
* @param id
* The custom id of this component, can also be a URL for a {@link Button} with {@link ButtonStyle#LINK}
* The custom id of this component, can also be a URL for a {@link Button} with {@link ButtonStyle#LINK},
* or an SKU id for {@link ButtonStyle#PREMIUM}
* @param newComponent
* The new component or null to remove it
*
Expand All @@ -227,7 +229,7 @@ default ItemComponent updateComponent(@Nonnull String id, @Nullable ItemComponen
if (!(component instanceof ActionComponent))
continue;
ActionComponent action = (ActionComponent) component;
if (id.equals(action.getId()) || (action instanceof Button && id.equals(((Button) action).getUrl())))
if (ComponentsUtil.isSameIdentifier(action, id))
{
if (newComponent == null)
it.remove();
Expand Down
Loading