Search in sources :

Example 1 with ButtonImpl

use of net.dv8tion.jda.internal.interactions.component.ButtonImpl 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)

Aggregations

SlashCommandInteractionEvent (net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent)1 InteractionHook (net.dv8tion.jda.api.interactions.InteractionHook)1 ActionRow (net.dv8tion.jda.api.interactions.components.ActionRow)1 ItemComponent (net.dv8tion.jda.api.interactions.components.ItemComponent)1 ButtonImpl (net.dv8tion.jda.internal.interactions.component.ButtonImpl)1