Skip to content

Commit

Permalink
add common interface for interactions with a custom ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaktushose committed Dec 19, 2024
1 parent 53131b7 commit 09f68fb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.dv8tion.jda.api.interactions;

import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
import net.dv8tion.jda.api.interactions.modals.ModalInteraction;

import javax.annotation.Nonnull;

/**
* Interactions which have a custom ID, namely {@link ComponentInteraction} and {@link ModalInteraction}.
*
* <br>This id does not have to be numerical.
*
*/
public interface CustomIdInteraction
{
/**
* The custom ID provided to the component or modal when it was originally created.
* <br>This value should be used to determine what action to take in regard to this interaction.
*
* <br>This id does not have to be numerical.
*
* @return The custom ID
*
* @see ComponentInteraction#getComponentId()
* @see ModalInteraction#getModalId()
*/
@Nonnull
String getCustomId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.unions.GuildMessageChannelUnion;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.interactions.CustomIdInteraction;
import net.dv8tion.jda.api.interactions.callbacks.IMessageEditCallback;
import net.dv8tion.jda.api.interactions.callbacks.IModalCallback;
import net.dv8tion.jda.api.interactions.callbacks.IPremiumRequiredReplyCallback;
Expand All @@ -32,8 +33,16 @@
* <p>Instead of {@link #deferReply()} and {@link #reply(String)} you can use {@link #deferEdit()} and {@link #editMessage(String)} with these interactions!
* <b>You can only acknowledge an interaction once!</b>
*/
public interface ComponentInteraction extends IReplyCallback, IMessageEditCallback, IModalCallback, IPremiumRequiredReplyCallback
public interface ComponentInteraction extends IReplyCallback, IMessageEditCallback, IModalCallback, IPremiumRequiredReplyCallback, CustomIdInteraction
{

@Override
@Nonnull
default String getCustomId()
{
return getComponentId();
}

/**
* The custom component ID provided to the component when it was originally created.
* <br>This value should be used to determine what action to take in regard to this interaction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.unions.GuildMessageChannelUnion;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.interactions.CustomIdInteraction;
import net.dv8tion.jda.api.interactions.callbacks.IMessageEditCallback;
import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback;
import net.dv8tion.jda.internal.utils.Checks;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;

import javax.annotation.Nonnull;
Expand All @@ -36,8 +38,16 @@
*
* @see net.dv8tion.jda.api.events.interaction.ModalInteractionEvent
*/
public interface ModalInteraction extends IReplyCallback, IMessageEditCallback
public interface ModalInteraction extends IReplyCallback, IMessageEditCallback, CustomIdInteraction
{

@Override
@NotNull
default String getCustomId()
{
return getModalId();
}

/**
* Returns the custom id of the Modal in question
*
Expand Down

0 comments on commit 09f68fb

Please sign in to comment.