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();
}
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));
}
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)));
}
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();
}
Aggregations