Search in sources :

Example 1 with JDASlashCommand

use of com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand in project BotCommands by freya022.

the class PaginatorCommand method run.

@JDASlashCommand(name = "paginator")
public void run(GuildSlashEvent event) {
    final List<EmbedBuilder> embedBuilders = new ArrayList<>();
    // Let's suppose you generated embeds like in JDA-U, so you'd have a collection of embeds to present
    for (int i = 0; i < 5; i++) {
        embedBuilders.add(new EmbedBuilder().setTitle("Page #" + (i + 1)));
    }
    final Paginator paginator = new PaginatorBuilder().setConstraints(InteractionConstraints.ofUsers(event.getUser())).useDeleteButton(false).setMaxPages(5).setPaginatorSupplier((instance, messageBuilder, components, page) -> embedBuilders.get(page).build()).build();
    // You must send the paginator as a message
    event.reply(paginator.get()).setEphemeral(true).queue();
}
Also used : List(java.util.List) ApplicationCommand(com.freya02.botcommands.api.application.ApplicationCommand) InteractionConstraints(com.freya02.botcommands.api.components.InteractionConstraints) JDASlashCommand(com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Paginator(com.freya02.botcommands.api.pagination.paginator.Paginator) CommandMarker(com.freya02.botcommands.api.annotations.CommandMarker) GuildSlashEvent(com.freya02.botcommands.api.application.slash.GuildSlashEvent) PaginatorBuilder(com.freya02.botcommands.api.pagination.paginator.PaginatorBuilder) ArrayList(java.util.ArrayList) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) ArrayList(java.util.ArrayList) Paginator(com.freya02.botcommands.api.pagination.paginator.Paginator) PaginatorBuilder(com.freya02.botcommands.api.pagination.paginator.PaginatorBuilder) JDASlashCommand(com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand)

Example 2 with JDASlashCommand

use of com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand in project BotCommands by freya022.

the class SlashInteractiveMenu method interactiveMenu.

@JDASlashCommand(name = "interactive")
public void interactiveMenu(GuildSlashEvent event) {
    final InteractiveMenu menu = new InteractiveMenuBuilder().addMenu(SelectContent.of("Joy", "This sparks joy", Emoji.fromMarkdown("\uD83D\uDE02")), (interactiveMenu, messageBuilder, components) -> {
        components.addComponents(1, Components.dangerButton(buttonEvent -> {
            event.getHook().deleteOriginal().queue();
            interactiveMenu.cancelTimeout();
            interactiveMenu.cleanup(event.getContext());
        }).build("Delete"), Components.secondaryButton(buttonEvent -> {
            interactiveMenu.setSelectedItem("Grin");
            buttonEvent.editMessage(interactiveMenu.get()).queue();
        }).build("Go to 'Grin'"));
        return new EmbedBuilder().setTitle("This sparks joy").build();
    }).addMenu(SelectContent.of("Grin", "This does not spark joy", Emoji.fromMarkdown("\uD83D\uDE00")), (interactiveMenu, messageBuilder, components) -> {
        components.addComponents(1, Components.dangerButton(buttonEvent -> {
            event.getHook().deleteOriginal().queue();
            interactiveMenu.cancelTimeout();
            interactiveMenu.cleanup(event.getContext());
        }).build("Delete"), Components.secondaryButton(buttonEvent -> {
            interactiveMenu.setSelectedItem(0);
            buttonEvent.editMessage(interactiveMenu.get()).queue();
        }).build("Go to 'Joy'"));
        return new EmbedBuilder().setTitle("This does not spark joy").build();
    }).setConstraints(InteractionConstraints.ofUsers(event.getUser())).setTimeout(5, TimeUnit.SECONDS, (interactiveMenu, msg) -> {
        System.out.println("bru");
        interactiveMenu.cleanup(event.getContext());
    }).build();
    event.reply(menu.get()).setEphemeral(false).queue();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) InteractiveMenuBuilder(com.freya02.botcommands.api.pagination.interactive.InteractiveMenuBuilder) ApplicationCommand(com.freya02.botcommands.api.application.ApplicationCommand) Components(com.freya02.botcommands.api.components.Components) InteractionConstraints(com.freya02.botcommands.api.components.InteractionConstraints) JDASlashCommand(com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) InteractiveMenu(com.freya02.botcommands.api.pagination.interactive.InteractiveMenu) Emoji(net.dv8tion.jda.api.entities.Emoji) GuildSlashEvent(com.freya02.botcommands.api.application.slash.GuildSlashEvent) SelectContent(com.freya02.botcommands.api.pagination.interactive.SelectContent) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) InteractiveMenu(com.freya02.botcommands.api.pagination.interactive.InteractiveMenu) InteractiveMenuBuilder(com.freya02.botcommands.api.pagination.interactive.InteractiveMenuBuilder) JDASlashCommand(com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand)

Aggregations

ApplicationCommand (com.freya02.botcommands.api.application.ApplicationCommand)2 GuildSlashEvent (com.freya02.botcommands.api.application.slash.GuildSlashEvent)2 JDASlashCommand (com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand)2 InteractionConstraints (com.freya02.botcommands.api.components.InteractionConstraints)2 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)2 CommandMarker (com.freya02.botcommands.api.annotations.CommandMarker)1 Components (com.freya02.botcommands.api.components.Components)1 InteractiveMenu (com.freya02.botcommands.api.pagination.interactive.InteractiveMenu)1 InteractiveMenuBuilder (com.freya02.botcommands.api.pagination.interactive.InteractiveMenuBuilder)1 SelectContent (com.freya02.botcommands.api.pagination.interactive.SelectContent)1 Paginator (com.freya02.botcommands.api.pagination.paginator.Paginator)1 PaginatorBuilder (com.freya02.botcommands.api.pagination.paginator.PaginatorBuilder)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Emoji (net.dv8tion.jda.api.entities.Emoji)1