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 basic support for activities #2751

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
6 changes: 4 additions & 2 deletions src/main/java/net/dv8tion/jda/api/JDA.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.EntryPointCommandData;
import net.dv8tion.jda.api.managers.AudioManager;
import net.dv8tion.jda.api.managers.DirectAudioController;
import net.dv8tion.jda.api.managers.Presence;
Expand Down Expand Up @@ -775,6 +776,7 @@ default CommandCreateAction upsertCommand(@Nonnull String name, @Nonnull String
/**
* Configures the complete list of global commands.
* <br>This will replace the existing command list for this bot. You should only use this once on startup!
* <br>If your bot has activities enabled, you <b>must</b> {@link GlobalCommandListUpdateAction#setEntryPointCommand(EntryPointCommandData) set your entry point command}.
*
* <p>This operation is idempotent.
* Commands will persist between restarts of your bot, you only have to create a command once.
Expand All @@ -799,13 +801,13 @@ default CommandCreateAction upsertCommand(@Nonnull String name, @Nonnull String
* jda.updateCommands().queue();
* }</pre>
*
* @return {@link CommandListUpdateAction}
* @return {@link GlobalCommandListUpdateAction}
*
* @see Guild#updateCommands()
*/
@Nonnull
@CheckReturnValue
CommandListUpdateAction updateCommands();
GlobalCommandListUpdateAction updateCommands();

/**
* Edit an existing global command by id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ enum Flag
GATEWAY_GUILD_MEMBERS_LIMITED(1 << 15),
/** Indicates unusual growth of an app that prevents verification */
VERIFICATION_PENDING_GUILD_LIMIT(1 << 16),
/** Indicates if an app is embedded within the Discord client (currently unavailable publicly) */
/** Indicates if an app is embedded within the Discord client, or is an app with an Activity */
EMBEDDED(1 << 17),
/** Bot can use {@link net.dv8tion.jda.api.requests.GatewayIntent#MESSAGE_CONTENT GatewayIntent.MESSAGE_CONTENT} in 100 or more guilds */
GATEWAY_MESSAGE_CONTENT(1 << 18),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.dv8tion.jda.api.interactions.modals.Modal;
import net.dv8tion.jda.api.interactions.modals.ModalInteraction;
import net.dv8tion.jda.api.interactions.modals.ModalMapping;
import net.dv8tion.jda.api.requests.restaction.interactions.LaunchActivityCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.MessageEditCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;

Expand Down Expand Up @@ -101,6 +102,14 @@ public MessageEditCallbackAction deferEdit()
return interaction.deferEdit();
}

@Nonnull
@Override
@CheckReturnValue
public LaunchActivityCallbackAction replyWithLaunchedActivity()
{
return interaction.replyWithLaunchedActivity();
}

@Nonnull
@Override
public MessageChannelUnion getChannel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.dv8tion.jda.api.interactions.commands.CommandInteraction;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.modals.Modal;
import net.dv8tion.jda.api.requests.restaction.interactions.LaunchActivityCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.ModalCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.PremiumRequiredCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
Expand Down Expand Up @@ -131,4 +132,12 @@ public PremiumRequiredCallbackAction replyWithPremiumRequired()
{
return getInteraction().replyWithPremiumRequired();
}

@Nonnull
@Override
@CheckReturnValue
public LaunchActivityCallbackAction replyWithLaunchedActivity()
{
return getInteraction().replyWithLaunchedActivity();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.interaction.command;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.interactions.commands.PrimaryEntryPointInteraction;
import net.dv8tion.jda.api.interactions.commands.build.EntryPointCommandData;
import net.dv8tion.jda.api.requests.restaction.GlobalCommandListUpdateAction;

import javax.annotation.Nonnull;

/**
* Indicates that an activity entry point was used in a {@link MessageChannel}.

* <br>This interaction requires <a href="https://discord.com/developers/docs/activities/overview" target="_blank">activities</a> to be enabled,
* and an {@link GlobalCommandListUpdateAction#setEntryPointCommand(EntryPointCommandData) entry point}
* with its {@link EntryPointCommandData#setHandler(EntryPointCommandData.Handler) handler}
* set to {@link EntryPointCommandData.Handler#APP_HANDLER APP_HANDLER} to be configured.
*
* <p><b>Requirements</b><br>
* To receive these events, you must unset the <b>Interactions Endpoint URL</b> in your application dashboard.
* You can simply remove the URL for this endpoint in your settings at the <a href="https://discord.com/developers/applications" target="_blank">Discord Developers Portal</a>.
*
* @see PrimaryEntryPointInteraction
*/
public class PrimaryEntryPointInteractionEvent extends GenericCommandInteractionEvent implements PrimaryEntryPointInteraction
{
private final PrimaryEntryPointInteraction interaction;

public PrimaryEntryPointInteractionEvent(@Nonnull JDA api, long responseNumber, @Nonnull PrimaryEntryPointInteraction interaction)
{
super(api, responseNumber, interaction);
this.interaction = interaction;
}

@Nonnull
@Override
public PrimaryEntryPointInteraction getInteraction()
{
return interaction;
}

@Nonnull
@Override
public MessageChannelUnion getChannel()
{
return interaction.getChannel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
import net.dv8tion.jda.api.interactions.components.Component;
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
import net.dv8tion.jda.api.interactions.modals.Modal;
import net.dv8tion.jda.api.requests.restaction.interactions.MessageEditCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.ModalCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.PremiumRequiredCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
import net.dv8tion.jda.api.requests.restaction.interactions.*;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -138,4 +135,12 @@ public PremiumRequiredCallbackAction replyWithPremiumRequired()
{
return interaction.replyWithPremiumRequired();
}

@Nonnull
@Override
@CheckReturnValue
public LaunchActivityCallbackAction replyWithLaunchedActivity()
{
return interaction.replyWithLaunchedActivity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public void onException(@Nonnull ExceptionEvent event) {}
public void onSlashCommandInteraction(@Nonnull SlashCommandInteractionEvent event) {}
public void onUserContextInteraction(@Nonnull UserContextInteractionEvent event) {}
public void onMessageContextInteraction(@Nonnull MessageContextInteractionEvent event) {}
public void onPrimaryEntryPointInteraction(@Nonnull PrimaryEntryPointInteractionEvent event) {}
public void onButtonInteraction(@Nonnull ButtonInteractionEvent event) {}
public void onCommandAutoCompleteInteraction(@Nonnull CommandAutoCompleteInteractionEvent event) {}
public void onModalInteraction(@Nonnull ModalInteractionEvent event) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
* <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 ILaunchActivityReplyCallback}
* <br>Which will launch the app's activity</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
@@ -0,0 +1,41 @@
/*
* 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.interactions.callbacks;

import net.dv8tion.jda.api.requests.restaction.interactions.LaunchActivityCallbackAction;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;

/**
* Callback which launches this app's activity.
*
* <p>Replying with {@link #replyWithLaunchedActivity()} will automatically acknowledge this interaction.
*
* <p><b>Note:</b>This interaction requires <a href="https://discord.com/developers/docs/activities/overview" target="_blank">activities</a> to be enabled.
*/
public interface ILaunchActivityReplyCallback extends IDeferrableCallback
{
/**
* Launches this app's activity and acknowledges this interaction.
*
* @return {@link LaunchActivityCallbackAction}
*/
@Nonnull
@CheckReturnValue
LaunchActivityCallbackAction replyWithLaunchedActivity();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.interactions.DiscordLocale;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.EntryPointCommandData;
import net.dv8tion.jda.api.interactions.commands.localization.LocalizationMap;
import net.dv8tion.jda.api.interactions.commands.privileges.IntegrationPrivilege;
import net.dv8tion.jda.api.requests.RestAction;
Expand Down Expand Up @@ -146,6 +147,14 @@ public interface Command extends ISnowflake, ICommandReference
@Nonnull
LocalizationMap getDescriptionLocalizations();

/**
* The handler, if this is an {@link EntryPointCommandData entry point command}.
*
* @return The entry point handler
*/
@Nullable
EntryPointCommandData.Handler getHandler();

/**
* The {@link Option Options} of this command.
*
Expand Down Expand Up @@ -249,7 +258,8 @@ enum Type
UNKNOWN(-1),
SLASH(1),
USER(2),
MESSAGE(3);
MESSAGE(3),
PRIMARY_ENTRY_POINT(4);

private final int id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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

import net.dv8tion.jda.api.interactions.callbacks.ILaunchActivityReplyCallback;
import net.dv8tion.jda.api.interactions.callbacks.IModalCallback;
import net.dv8tion.jda.api.interactions.callbacks.IPremiumRequiredReplyCallback;
import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback;
Expand All @@ -29,6 +30,6 @@
* @see ContextInteraction
* @see SlashCommandInteraction
*/
public interface CommandInteraction extends IReplyCallback, CommandInteractionPayload, IModalCallback, IPremiumRequiredReplyCallback
public interface CommandInteraction extends IReplyCallback, CommandInteractionPayload, IModalCallback, IPremiumRequiredReplyCallback, ILaunchActivityReplyCallback
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.interactions.commands;

import net.dv8tion.jda.api.entities.channel.unions.GuildMessageChannelUnion;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.interactions.commands.build.EntryPointCommandData;
import net.dv8tion.jda.api.requests.restaction.GlobalCommandListUpdateAction;

import javax.annotation.Nonnull;

/**
* Interaction to launch your app's activity.
*
* <p><b>Note:</b> This interaction requires <a href="https://discord.com/developers/docs/activities/overview" target="_blank">activities</a> to be enabled,
* and an {@link GlobalCommandListUpdateAction#setEntryPointCommand(EntryPointCommandData) entry point}
* with its {@link EntryPointCommandData#setHandler(EntryPointCommandData.Handler) handler}
* set to {@link EntryPointCommandData.Handler#APP_HANDLER APP_HANDLER} to be configured.
*/
public interface PrimaryEntryPointInteraction extends CommandInteraction
{
/**
* The respective {@link MessageChannelUnion} for this interaction.
*
* @return The {@link MessageChannelUnion}
*/
@Nonnull
@Override
MessageChannelUnion getChannel();

@Nonnull
@Override
default GuildMessageChannelUnion getGuildChannel()
{
return (GuildMessageChannelUnion) CommandInteraction.super.getGuildChannel();
}
}
Loading