All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.freya022.botcommands.api.pagination.menu.ChoiceMenuBuilder Maven / Gradle / Ivy

Go to download

A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.

There is a newer version: 3.0.0-alpha.18
Show newest version
package io.github.freya022.botcommands.api.pagination.menu;

import io.github.freya022.botcommands.api.components.Components;
import io.github.freya022.botcommands.api.pagination.ButtonContentSupplier;
import io.github.freya022.botcommands.api.utils.ButtonContent;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Builds a {@link ChoiceMenu}.
 * 
The callback and the button content supplier must be set ! * * @param Type of the entries */ public final class ChoiceMenuBuilder extends BasicMenuBuilder, ChoiceMenu> { private ChoiceCallback callback; private ButtonContentSupplier buttonContentSupplier; public ChoiceMenuBuilder(@NotNull Components componentsService, @NotNull List entries) { super(componentsService, entries); } /** * Sets the callback for this menu * * @param callback The {@link ChoiceCallback} to call when the user makes their choice * @return This builder for chaining convenience */ public ChoiceMenuBuilder setCallback(@NotNull ChoiceCallback callback) { this.callback = callback; return this; } /** * Sets the button content supplier for this menu, allowing you to use custom buttons (text / emoji) *
You get handed the object the button is bound to, as well as the object's index in the current page *
So if you have a maximum of 5 items per page, your index is between 0 (included) and 5 (excluded) * *
*
See limitations of buttons content at {@link Button#primary(String, String)} and {@link Button#primary(String, Emoji)} * * @param buttonContentSupplier The function which accepts an item of type T and an item index (local to the current page), and returns a {@link ButtonContent} * @return This builder for chaining convenience * @see ButtonContent#withString(String) * @see ButtonContent#withEmoji(Emoji) */ public ChoiceMenuBuilder setButtonContentSupplier(@NotNull ButtonContentSupplier buttonContentSupplier) { this.buttonContentSupplier = buttonContentSupplier; return this; } @Override @NotNull public ChoiceMenu build() { return new ChoiceMenu<>(componentsService, constraints, timeout, hasDeleteButton, firstContent, previousContent, nextContent, lastContent, deleteContent, entries, maxEntriesPerPage, transformer, rowPrefixSupplier, paginatorSupplier, buttonContentSupplier, callback); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy