Skip to content

Commit

Permalink
Implement new select menus (#2287)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment authored Oct 23, 2022
1 parent 9741415 commit 9a07589
Show file tree
Hide file tree
Showing 21 changed files with 1,676 additions and 471 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ public boolean isThread()
}
}

/**
* All the channel types for a {@link net.dv8tion.jda.api.entities.Guild Guild}.
*
* @return {@link EnumSet} of {@link ChannelType}
*/
@Nonnull
public static EnumSet<ChannelType> guildTypes()
{
return EnumSet.complementOf(EnumSet.of(PRIVATE, GROUP, UNKNOWN));
}

/**
* Static accessor for retrieving a channel type based on its Discord id key.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.component;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.IMentionable;
import net.dv8tion.jda.api.entities.Mentions;
import net.dv8tion.jda.api.interactions.components.selections.EntitySelectInteraction;
import net.dv8tion.jda.api.interactions.components.selections.EntitySelectMenu;

import javax.annotation.Nonnull;

/**
* Indicates that a custom {@link EntitySelectMenu} on one of the bots messages was used by a user.
*
* <p>This fires when a user selects the options on one of the custom select menus attached to a bot or webhook message.
* Use {@link #getMentions()} or {@link #getValues()} to handle the selected entities.
*
* <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 StringSelectInteractionEvent
*/
public class EntitySelectInteractionEvent extends GenericSelectMenuInteractionEvent<IMentionable, EntitySelectMenu> implements EntitySelectInteraction
{
private final EntitySelectInteraction interaction;

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

@Nonnull
@Override
public EntitySelectInteraction getInteraction()
{
return this.interaction;
}

@Nonnull
@Override
public Mentions getMentions()
{
return interaction.getMentions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,39 @@
* <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>.
*
* @param <T>
* The select menu value type
* @param <S>
* The type of select menu
*/
public class SelectMenuInteractionEvent extends GenericComponentInteractionCreateEvent implements SelectMenuInteraction
public class GenericSelectMenuInteractionEvent<T, S extends SelectMenu> extends GenericComponentInteractionCreateEvent implements SelectMenuInteraction<T, S>
{
private final SelectMenuInteraction menuInteraction;
private final SelectMenuInteraction<T, S> menuInteraction;

public SelectMenuInteractionEvent(@Nonnull JDA api, long responseNumber, @Nonnull SelectMenuInteraction interaction)
public GenericSelectMenuInteractionEvent(@Nonnull JDA api, long responseNumber, @Nonnull SelectMenuInteraction<T, S> interaction)
{
super(api, responseNumber, interaction);
this.menuInteraction = interaction;
}

@Nonnull
@Override
public SelectMenuInteraction getInteraction()
public SelectMenuInteraction<T, S> getInteraction()
{
return menuInteraction;
}

@Nonnull
@Override
public SelectMenu getComponent()
public S getComponent()
{
return menuInteraction.getComponent();
}

@Nonnull
@Override
public List<String> getValues()
public List<T> getValues()
{
return menuInteraction.getValues();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.component;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.interactions.components.selections.StringSelectInteraction;
import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu;

import javax.annotation.Nonnull;

/**
* Indicates that a custom {@link StringSelectMenu} on one of the bots messages was used by a user.
*
* <p>This fires when a user selects the options on one of the custom select menus attached to a bot or webhook message.
* Use {@link #getValues()} or {@link #getSelectedOptions()} to handle the selected options.
*
* <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 EntitySelectInteractionEvent
*/
public class StringSelectInteractionEvent extends GenericSelectMenuInteractionEvent<String, StringSelectMenu> implements StringSelectInteraction
{
private final StringSelectInteraction interaction;

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

@Nonnull
@Override
public StringSelectInteraction getInteraction()
{
return interaction;
}
}
8 changes: 4 additions & 4 deletions src/main/java/net/dv8tion/jda/api/hooks/ListenerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@
import net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent;
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
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.GenericComponentInteractionCreateEvent;
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.*;
import net.dv8tion.jda.api.events.message.*;
import net.dv8tion.jda.api.events.message.react.*;
import net.dv8tion.jda.api.events.role.GenericRoleEvent;
Expand Down Expand Up @@ -147,9 +145,10 @@ public void onSlashCommandInteraction(@Nonnull SlashCommandInteractionEvent even
public void onUserContextInteraction(@Nonnull UserContextInteractionEvent event) {}
public void onMessageContextInteraction(@Nonnull MessageContextInteractionEvent event) {}
public void onButtonInteraction(@Nonnull ButtonInteractionEvent event) {}
public void onSelectMenuInteraction(@Nonnull SelectMenuInteractionEvent event) {}
public void onCommandAutoCompleteInteraction(@Nonnull CommandAutoCompleteInteractionEvent event) {}
public void onModalInteraction(@Nonnull ModalInteractionEvent event) {}
public void onStringSelectInteraction(@Nonnull StringSelectInteractionEvent event) {}
public void onEntitySelectInteraction(@Nonnull EntitySelectInteractionEvent event) {}

//User Events
public void onUserUpdateName(@Nonnull UserUpdateNameEvent event) {}
Expand Down Expand Up @@ -359,6 +358,7 @@ public void onGenericAutoCompleteInteraction(@Nonnull GenericAutoCompleteInterac
public void onGenericComponentInteractionCreate(@Nonnull GenericComponentInteractionCreateEvent event) {}
public void onGenericCommandInteraction(@Nonnull GenericCommandInteractionEvent event) {}
public void onGenericContextInteraction(@Nonnull GenericContextInteractionEvent<?> event) {}
public void onGenericSelectMenuInteraction(@Nonnull GenericSelectMenuInteractionEvent event) {}
public void onGenericMessage(@Nonnull GenericMessageEvent event) {}
public void onGenericMessageReaction(@Nonnull GenericMessageReactionEvent event) {}
public void onGenericUser(@Nonnull GenericUserEvent event) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import net.dv8tion.jda.api.utils.data.DataArray;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.interactions.component.ButtonImpl;
import net.dv8tion.jda.internal.interactions.component.SelectMenuImpl;
import net.dv8tion.jda.internal.interactions.component.EntitySelectMenuImpl;
import net.dv8tion.jda.internal.interactions.component.StringSelectMenuImpl;
import net.dv8tion.jda.internal.interactions.component.TextInputImpl;
import net.dv8tion.jda.internal.utils.Checks;
import net.dv8tion.jda.internal.utils.EntityString;
Expand Down Expand Up @@ -69,10 +70,15 @@ public static ActionRow fromData(@Nonnull DataObject data)
{
case BUTTON:
return new ButtonImpl(obj);
case SELECT_MENU:
return new SelectMenuImpl(obj);
case STRING_SELECT:
return new StringSelectMenuImpl(obj);
case TEXT_INPUT:
return new TextInputImpl(obj);
case USER_SELECT:
case ROLE_SELECT:
case CHANNEL_SELECT:
case MENTIONABLE_SELECT:
return new EntitySelectMenuImpl(obj);
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,18 @@ enum Type
ACTION_ROW(1, 0, true, true),
/** A button */
BUTTON(2, 5, true, false),
/** A select menu */
SELECT_MENU(3, 1, true, false),
/** A select menu of strings */
STRING_SELECT(3, 1, true, false),
/** A text input field */
TEXT_INPUT(4, 1, false, true)
TEXT_INPUT(4, 1, false, true),
/** A select menu of users */
USER_SELECT(5, 1, true, false),
/** A select menu of roles */
ROLE_SELECT(6, 1, true, false),
/** A select menu of users and roles */
MENTIONABLE_SELECT(7, 1, true, false),
/** A select menu of channels */
CHANNEL_SELECT(8, 1, true, false),
;

private final int key;
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.api.interactions.components.selections;

import net.dv8tion.jda.api.entities.IMentionable;
import net.dv8tion.jda.api.entities.Mentions;
import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent;

import javax.annotation.Nonnull;

/**
* Component Interaction for a {@link EntitySelectMenu}.
*
* @see EntitySelectInteractionEvent
*/
public interface EntitySelectInteraction extends SelectMenuInteraction<IMentionable, EntitySelectMenu>
{
/**
* The resolved {@link Mentions} for this selection.
* <br>This supports {@link Mentions#getRoles() roles}, {@link Mentions#getUsers() users}, and {@link Mentions#getChannels() channels}.
*
* @return The mentions
*/
@Nonnull
Mentions getMentions();
}
Loading

0 comments on commit 9a07589

Please sign in to comment.