Skip to content

Commit

Permalink
Add PrimaryEntryPointInteractionEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 committed Oct 15, 2024
1 parent ed6feae commit 6459495
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 8 deletions.
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 @@ -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
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent;
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.*;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
Expand All @@ -33,10 +30,7 @@
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.JDAImpl;
import net.dv8tion.jda.internal.interactions.InteractionImpl;
import net.dv8tion.jda.internal.interactions.command.CommandAutoCompleteInteractionImpl;
import net.dv8tion.jda.internal.interactions.command.MessageContextInteractionImpl;
import net.dv8tion.jda.internal.interactions.command.SlashCommandInteractionImpl;
import net.dv8tion.jda.internal.interactions.command.UserContextInteractionImpl;
import net.dv8tion.jda.internal.interactions.command.*;
import net.dv8tion.jda.internal.interactions.component.ButtonInteractionImpl;
import net.dv8tion.jda.internal.interactions.component.EntitySelectInteractionImpl;
import net.dv8tion.jda.internal.interactions.component.StringSelectInteractionImpl;
Expand Down Expand Up @@ -123,6 +117,11 @@ private void handleCommand(DataObject content)
new UserContextInteractionEvent(api, responseNumber,
new UserContextInteractionImpl(api, content)));
break;
case PRIMARY_ENTRY_POINT:
api.handleEvent(
new PrimaryEntryPointInteractionEvent(api, responseNumber,
new PrimaryEntryPointInteractionImpl(api, content)));
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.internal.interactions.command;

import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.interactions.commands.PrimaryEntryPointInteraction;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.JDAImpl;

import javax.annotation.Nonnull;

public class PrimaryEntryPointInteractionImpl extends CommandInteractionImpl implements PrimaryEntryPointInteraction
{
public PrimaryEntryPointInteractionImpl(JDAImpl jda, DataObject data)
{
super(jda, data);
}

@Nonnull
@Override
@SuppressWarnings("ConstantConditions")
public MessageChannelUnion getChannel()
{
return (MessageChannelUnion) super.getChannel();
}
}

0 comments on commit 6459495

Please sign in to comment.