Search in sources :

Example 1 with ItemComponent

use of net.dv8tion.jda.api.interactions.components.ItemComponent in project MMDBot by MinecraftModDevelopment.

the class PaginatedCommand method createScrollButtons.

/**
 * Create the row of Component interaction buttons.
 * <p>
 * Currently, this just creates a left and right arrow.
 * Left arrow scrolls back a page. Right arrow scrolls forward a page.
 *
 * @param start The quote number at the start of the current page.
 * @return A row of buttons to go back and forth by one page.
 */
private ItemComponent[] createScrollButtons(int start) {
    Button backward = Button.primary(listener.getButtonID() + "-" + start + "-prev", Emoji.fromUnicode("◀️")).asDisabled();
    Button forward = Button.primary(listener.getButtonID() + "-" + start + "-next", Emoji.fromUnicode("▶️")).asDisabled();
    if (start != 0) {
        backward = backward.asEnabled();
    }
    if (start + items_per_page < maximum) {
        forward = forward.asEnabled();
    }
    return new ItemComponent[] { backward, forward };
}
Also used : Button(net.dv8tion.jda.api.interactions.components.buttons.Button) ItemComponent(net.dv8tion.jda.api.interactions.components.ItemComponent)

Example 2 with ItemComponent

use of net.dv8tion.jda.api.interactions.components.ItemComponent in project JavaBot by Java-Discord.

the class HelpChannelManager method sendThanksButtonsMessage.

private void sendThanksButtonsMessage(List<Member> potentialHelpers, ChannelReservation reservation, Interaction interaction, TextChannel channel) {
    List<ItemComponent> thanksButtons = new ArrayList<>(25);
    for (var helper : potentialHelpers.subList(0, Math.min(potentialHelpers.size(), 20))) {
        thanksButtons.add(new ButtonImpl("help-thank:" + reservation.getId() + ":" + helper.getId(), helper.getEffectiveName(), ButtonStyle.SUCCESS, false, Emoji.fromUnicode("❤")));
    }
    ActionRow controlsRow = ActionRow.of(new ButtonImpl("help-thank:" + reservation.getId() + ":done", "Unreserve", ButtonStyle.PRIMARY, false, Emoji.fromUnicode("✅")), new ButtonImpl("help-thank:" + reservation.getId() + ":cancel", "Cancel", ButtonStyle.SECONDARY, false, Emoji.fromUnicode("❌")));
    InteractionHook hook;
    if (interaction.getType() == InteractionType.COMPONENT) {
        hook = ((ButtonInteractionEvent) interaction).getHook();
    } else if (interaction.getType() == InteractionType.COMMAND) {
        hook = ((SlashCommandInteractionEvent) interaction).getHook();
    } else {
        throw new IllegalStateException("Unable to obtain Interaction Hook!");
    }
    hook.sendMessage(THANK_MESSAGE_TEXT).setEphemeral(true).queue();
    List<ActionRow> rows = new ArrayList<>(5);
    rows.add(controlsRow);
    rows.addAll(MessageActionUtils.toActionRows(thanksButtons));
    channel.sendMessage(THANK_MESSAGE_TEXT).setActionRows(rows).queue();
}
Also used : InteractionHook(net.dv8tion.jda.api.interactions.InteractionHook) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) ItemComponent(net.dv8tion.jda.api.interactions.components.ItemComponent) ActionRow(net.dv8tion.jda.api.interactions.components.ActionRow) ButtonImpl(net.dv8tion.jda.internal.interactions.component.ButtonImpl)

Example 3 with ItemComponent

use of net.dv8tion.jda.api.interactions.components.ItemComponent in project dDiscordBot by DenizenScript.

the class DiscordMessageCommand method createRows.

public static List<ActionRow> createRows(ScriptEntry scriptEntry, ObjectTag rowsObj) {
    if (rowsObj == null) {
        return null;
    }
    Collection<ObjectTag> rows = CoreUtilities.objectToList(rowsObj, scriptEntry.getContext());
    List<ActionRow> actionRows = new ArrayList<>();
    for (ObjectTag row : rows) {
        List<ItemComponent> components = new ArrayList<>();
        for (ObjectTag component : CoreUtilities.objectToList(row, scriptEntry.getContext())) {
            if (component.canBeType(DiscordButtonTag.class)) {
                components.add(component.asType(DiscordButtonTag.class, scriptEntry.getContext()).build());
            } else if (component.canBeType(DiscordSelectionTag.class)) {
                components.add(component.asType(DiscordSelectionTag.class, scriptEntry.getContext()).build(scriptEntry.getContext()).build());
            } else {
                Debug.echoError("Unrecognized component list entry '" + component + "'");
            }
        }
        actionRows.add(ActionRow.of(components));
    }
    return actionRows;
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ItemComponent(net.dv8tion.jda.api.interactions.components.ItemComponent) ActionRow(net.dv8tion.jda.api.interactions.components.ActionRow) ArrayList(java.util.ArrayList)

Example 4 with ItemComponent

use of net.dv8tion.jda.api.interactions.components.ItemComponent in project MMDBot by MinecraftModDevelopment.

the class CmdDictionary method createScrollButtons.

private static ItemComponent[] createScrollButtons(int start, String word, int maximum) {
    Button backward = Button.primary(ButtonListener.BUTTON_ID + "-" + start + "-prev-" + word + "-" + maximum, Emoji.fromUnicode("◀️")).asDisabled();
    Button forward = Button.primary(ButtonListener.BUTTON_ID + "-" + start + "-next-" + word + "-" + maximum, Emoji.fromUnicode("▶️")).asDisabled();
    if (start != 0) {
        backward = backward.asEnabled();
    }
    if (start + 1 < maximum) {
        forward = forward.asEnabled();
    }
    return new ItemComponent[] { backward, forward };
}
Also used : Button(net.dv8tion.jda.api.interactions.components.buttons.Button) ItemComponent(net.dv8tion.jda.api.interactions.components.ItemComponent)

Aggregations

ItemComponent (net.dv8tion.jda.api.interactions.components.ItemComponent)4 ActionRow (net.dv8tion.jda.api.interactions.components.ActionRow)2 Button (net.dv8tion.jda.api.interactions.components.buttons.Button)2 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)1 ArrayList (java.util.ArrayList)1 SlashCommandInteractionEvent (net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent)1 InteractionHook (net.dv8tion.jda.api.interactions.InteractionHook)1 ButtonImpl (net.dv8tion.jda.internal.interactions.component.ButtonImpl)1