Search in sources :

Example 1 with SelectionMenu

use of net.dv8tion.jda.api.interactions.components.selections.SelectionMenu in project Robertify-Bot by bombies.

the class SearchResultLoader method playlistLoaded.

@Override
public void playlistLoaded(AudioPlaylist playlist) {
    if (!playlist.isSearchResult())
        throw new UnsupportedOperationException("This operation is not supported in the search result loader");
    final var tracks = playlist.getTracks();
    SelectionMenuBuilder selectionMenuBuilder = new SelectionMenuBuilder().setName("searchresult:" + searcher.getId() + ":" + query.toLowerCase().replaceAll(" ", "%SPACE%")).setPlaceHolder("Choose a result!").setRange(1, 1);
    final StringBuilder embedDescription = new StringBuilder();
    for (int i = 0; i < Math.min(10, tracks.size()); i++) {
        AudioTrackInfo info = tracks.get(i).getInfo();
        selectionMenuBuilder.addOption(info.title, info.identifier, null);
        embedDescription.append("**").append(i + 1).append(".** - ").append(info.title).append(" by ").append(info.author).append(" [").append(GeneralUtils.formatTime(info.length)).append("]").append("\n");
    }
    SelectionMenu selectionMenu = selectionMenuBuilder.build();
    if (botMsg != null)
        botMsg.editMessageEmbeds(RobertifyEmbedUtils.embedMessage(guild, embedDescription.toString()).setAuthor("Search results for: " + query.replaceFirst("ytsearch:", ""), null, new ThemesConfig().getTheme(guild.getIdLong()).getTransparent()).setFooter("Select a result from the selection menu below").build()).setActionRows(ActionRow.of(selectionMenu), ActionRow.of(Button.of(ButtonStyle.DANGER, "searchresult:end:" + searcher.getId(), "End Interaction"))).queue();
    else
        interactionBotMsg.sendMessageEmbeds(RobertifyEmbedUtils.embedMessage(guild, embedDescription.toString()).setAuthor("Search results for: " + query.replaceFirst("ytsearch:", ""), null, new ThemesConfig().getTheme(guild.getIdLong()).getTransparent()).setFooter("Select a result from the selection menu below").build()).addActionRows(ActionRow.of(selectionMenu), ActionRow.of(Button.of(ButtonStyle.DANGER, "searchresult:end:" + searcher.getId(), "End Interaction"))).setEphemeral(false).queue();
}
Also used : SelectionMenuBuilder(main.utils.component.interactions.selectionmenu.SelectionMenuBuilder) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) SelectionMenu(net.dv8tion.jda.api.interactions.components.selections.SelectionMenu) ThemesConfig(main.utils.json.themes.ThemesConfig)

Example 2 with SelectionMenu

use of net.dv8tion.jda.api.interactions.components.selections.SelectionMenu in project Robertify-Bot by bombies.

the class Pages method paginateMenu.

@SneakyThrows
public static void paginateMenu(User user, Message msg, List<SelectionMenuOption> options) {
    List<MenuPage> menuPages = menuLogic(msg.getId(), options);
    final var firstPage = menuPages.get(0);
    SelectionMenu menu = SelectionMenuBuilder.of("menupage:" + user.getId(), "Select an option", Pair.of(1, 1), firstPage.getOptions().subList(0, Math.min(options.size(), InteractionLimits.SELECTION_MENU))).build();
    msg.editMessageComponents(ActionRow.of(menu)).queue(success -> menuMessages.put(msg.getIdLong(), menuPages));
}
Also used : SelectionMenu(net.dv8tion.jda.api.interactions.components.selections.SelectionMenu) SneakyThrows(lombok.SneakyThrows)

Example 3 with SelectionMenu

use of net.dv8tion.jda.api.interactions.components.selections.SelectionMenu in project Robertify-Bot by bombies.

the class Pages method paginateMenu.

@SneakyThrows
public static void paginateMenu(User user, ReplyAction msg, List<SelectionMenuOption> options) {
    List<MenuPage> menuPages = menuLogic("null", options);
    final var firstPage = menuPages.get(0);
    SelectionMenu menu = SelectionMenuBuilder.of("menupage:" + user.getId(), "Select an option", Pair.of(1, 1), firstPage.getOptions().subList(0, Math.min(options.size(), InteractionLimits.SELECTION_MENU))).build();
    msg.addActionRow(menu).setEphemeral(false).queue(success -> success.retrieveOriginal().queue(og -> menuMessages.put(og.getIdLong(), menuPages)));
}
Also used : net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) SneakyThrows(lombok.SneakyThrows) SelectionMenuBuilder(main.utils.component.interactions.selectionmenu.SelectionMenuBuilder) WebhookMessageAction(net.dv8tion.jda.api.requests.restaction.WebhookMessageAction) HashMap(java.util.HashMap) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) SelectionMenuOption(main.utils.component.interactions.selectionmenu.SelectionMenuOption) SelectionMenu(net.dv8tion.jda.api.interactions.components.selections.SelectionMenu) ArrayList(java.util.ArrayList) SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) Pair(net.dv8tion.jda.internal.utils.tuple.Pair) List(java.util.List) RobertifyEmbedUtils(main.utils.RobertifyEmbedUtils) ActionRow(net.dv8tion.jda.api.interactions.components.ActionRow) ReplyAction(net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction) InteractionLimits(main.constants.InteractionLimits) SelectionMenu(net.dv8tion.jda.api.interactions.components.selections.SelectionMenu) SneakyThrows(lombok.SneakyThrows)

Example 4 with SelectionMenu

use of net.dv8tion.jda.api.interactions.components.selections.SelectionMenu in project Robertify-Bot by bombies.

the class SelectionMenuBuilder method build.

@SneakyThrows
public SelectionMenu build() {
    if (name == null)
        throw new InteractionBuilderException("The name of the menu can't be null!");
    if (placeholder == null)
        throw new InteractionBuilderException("The placeholder for the menu can't be null!");
    if (range == null)
        throw new InteractionBuilderException("The range for the menu can't be null!");
    SelectionMenu.Builder builder = SelectionMenu.create(name).setPlaceholder(placeholder).setRequiredRange(range.getLeft(), range.getLeft());
    for (SelectionMenuOption val : options) if (val.getEmoji() == null)
        builder.addOption(val.getLabel(), val.getValue());
    else
        builder.addOption(val.getLabel(), val.getValue(), val.getEmoji());
    return builder.build();
}
Also used : InteractionBuilderException(main.utils.component.InteractionBuilderException) SelectionMenu(net.dv8tion.jda.api.interactions.components.selections.SelectionMenu) SneakyThrows(lombok.SneakyThrows)

Aggregations

SelectionMenu (net.dv8tion.jda.api.interactions.components.selections.SelectionMenu)4 SneakyThrows (lombok.SneakyThrows)3 SelectionMenuBuilder (main.utils.component.interactions.selectionmenu.SelectionMenuBuilder)2 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Supplier (java.util.function.Supplier)1 InteractionLimits (main.constants.InteractionLimits)1 RobertifyEmbedUtils (main.utils.RobertifyEmbedUtils)1 InteractionBuilderException (main.utils.component.InteractionBuilderException)1 SelectionMenuOption (main.utils.component.interactions.selectionmenu.SelectionMenuOption)1 ThemesConfig (main.utils.json.themes.ThemesConfig)1 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1 net.dv8tion.jda.api.entities (net.dv8tion.jda.api.entities)1 SlashCommandEvent (net.dv8tion.jda.api.events.interaction.SlashCommandEvent)1 ActionRow (net.dv8tion.jda.api.interactions.components.ActionRow)1 WebhookMessageAction (net.dv8tion.jda.api.requests.restaction.WebhookMessageAction)1 ReplyAction (net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction)1