Search in sources :

Example 1 with InteractiveMenuBuilder

use of com.freya02.botcommands.api.pagination.interactive.InteractiveMenuBuilder 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)1 GuildSlashEvent (com.freya02.botcommands.api.application.slash.GuildSlashEvent)1 JDASlashCommand (com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand)1 Components (com.freya02.botcommands.api.components.Components)1 InteractionConstraints (com.freya02.botcommands.api.components.InteractionConstraints)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 TimeUnit (java.util.concurrent.TimeUnit)1 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1 Emoji (net.dv8tion.jda.api.entities.Emoji)1