Skip to content

Commit

Permalink
Add EntryPointCommandData#setHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 committed Oct 14, 2024
1 parent 1a7d494 commit aadc37c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,52 @@ public interface EntryPointCommandData
extends IDescribedCommandData, INamedCommandData, IScopedCommandData, IRestrictedCommandData,
IAgeRestrictedCommandData, SerializableData
{
//TODO docs
enum Handler
{
UNKNOWN(-1),
/**
* Lets this app handle the activity start via an interaction.
*/
APP_HANDLER(1),
/**
* Lets Discord handle the activity start,
* and sends a follow-up message without coordinating with this app.
*/
DISCORD_LAUNCH_ACTIVITY(2);

private final int value;

Handler(int value)
{
this.value = value;
}

public int getValue()
{
return value;
}

/**
* Converts the value to the corresponding handler.
*
* @param value
* The value of the handler
*
* @return {@link Handler}
*/
@Nonnull
public static Handler fromValue(long value)
{
for (Handler handler : values())
{
if (handler.value == value)
return handler;
}
return UNKNOWN;
}
}

@Nonnull
@Override
EntryPointCommandData setLocalizationFunction(@Nonnull LocalizationFunction localizationFunction);
Expand Down Expand Up @@ -77,6 +123,10 @@ public interface EntryPointCommandData
@Override
EntryPointCommandData setNSFW(boolean nsfw);

//TODO docs
@Nonnull
EntryPointCommandData setHandler(Handler handler);

//TODO docs
@Nonnull
static EntryPointCommandData fromCommand(@Nonnull Command command)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class EntryPointCommandDataImpl implements EntryPointCommandData, IDescri
private boolean guildOnly = false;
private boolean nsfw = false;
private DefaultMemberPermissions defaultMemberPermissions = DefaultMemberPermissions.ENABLED;
private Handler handler;

public EntryPointCommandDataImpl(@Nonnull String name, @Nonnull String description)
{
Expand All @@ -56,6 +57,7 @@ public DataObject toData()

return DataObject.empty()
.put("type", getType().getId())
.put("handler", handler.getValue())
.put("name", name)
.put("description", description)
.put("description_localizations", descriptionLocalizations)
Expand Down Expand Up @@ -179,6 +181,14 @@ public EntryPointCommandDataImpl setDescriptionLocalizations(@Nonnull Map<Discor
return this;
}

@Nonnull
@Override
public EntryPointCommandData setHandler(Handler handler)
{
this.handler = handler;
return this;
}

@Nonnull
@Override
public String getName()
Expand Down

0 comments on commit aadc37c

Please sign in to comment.