Search in sources :

Example 6 with BContext

use of com.freya02.botcommands.api.BContext in project BotCommands by freya022.

the class BasicPagination method cleanup.

/**
 * Cleans up the button IDs used in this paginator
 * <br>This will remove every stored button IDs, even then buttons you included yourself
 *
 * @param context The {@link BContext} of this bot
 */
public void cleanup(BContext context) {
    final ComponentManager manager = Utils.getComponentManager(context);
    final int deletedIds = manager.deleteIds(usedIds);
    LOGGER.trace("Cleaned up {} component IDs out of {}", deletedIds, usedIds.size());
    usedIds.clear();
}
Also used : ComponentManager(com.freya02.botcommands.api.components.ComponentManager)

Example 7 with BContext

use of com.freya02.botcommands.api.BContext in project BotCommands by freya022.

the class AnnotationUtils method getEffectiveTestGuildIds.

public static TLongSet getEffectiveTestGuildIds(BContext context, Method method) {
    TLongSet testIds = new TLongHashSet(context.getTestGuildIds());
    final List<Test> effectiveAnnotations = getEffectiveAnnotations(method, Test.class);
    for (Test test : effectiveAnnotations) {
        final long[] ids = test.guildIds();
        final AppendMode mode = test.mode();
        if (mode == AppendMode.SET) {
            testIds.clear();
            testIds.addAll(ids);
            return testIds;
        } else if (mode == AppendMode.ADD) {
            testIds.addAll(ids);
        }
    }
    return testIds;
}
Also used : Test(com.freya02.botcommands.api.application.annotations.Test) TLongSet(gnu.trove.set.TLongSet) TLongHashSet(gnu.trove.set.hash.TLongHashSet)

Example 8 with BContext

use of com.freya02.botcommands.api.BContext in project BotCommands by freya022.

the class SlashPaginator method replyPaginator.

private void replyPaginator(GuildSlashEvent event, BContext context, InteractionConstraints constraints) {
    final PaginatorBuilder builder = new PaginatorBuilder().setConstraints(constraints).useDeleteButton(true).setTimeout(5, TimeUnit.SECONDS, (paginator, message) -> {
        paginator.cleanup(context);
        // Remove components on timeout
        event.getHook().editOriginalComponents().queue();
    // Disable all components on timeout, more expensive
    // event.getHook()
    // .retrieveOriginal()
    // .flatMap(m -> m.editMessageComponents(m.getActionRows().stream().map(ActionRow::asDisabled).toList()))
    // .queue();
    }).setMaxPages(5).setFirstContent(ButtonContent.withString("←")).setPaginatorSupplier((paginator, messageBuilder, components, page) -> {
        components.addComponents(1, Components.primaryButton(btnEvt -> {
            // Pages starts at 0
            paginator.setPage(2);
            btnEvt.editMessage(paginator.get()).queue();
        }).build(ButtonContent.withEmoji("Go to page 3", EmojiUtils.resolveJDAEmoji("page_facing_up"))));
        components.addComponents(1, Components.primaryButton(btnEvt -> {
            // Pages starts at 0
            paginator.setPage(4);
            btnEvt.editMessage(paginator.get()).queue();
        }).build(ButtonContent.withEmoji("Go to page 5", EmojiUtils.resolveJDAEmoji("page_facing_up"))));
        return new EmbedBuilder().setTitle(// Pages starts at 0
        "Page #" + (page + 1)).build();
    });
    final Paginator paginator = builder.build();
    event.reply(paginator.get()).setEphemeral(false).queue();
}
Also used : Components(com.freya02.botcommands.api.components.Components) InteractionConstraints(com.freya02.botcommands.api.components.InteractionConstraints) ButtonContent(com.freya02.botcommands.api.utils.ButtonContent) Permission(net.dv8tion.jda.api.Permission) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Paginator(com.freya02.botcommands.api.pagination.paginator.Paginator) TimeUnit(java.util.concurrent.TimeUnit) AppOption(com.freya02.botcommands.api.application.annotations.AppOption) Role(net.dv8tion.jda.api.entities.Role) ApplicationCommand(com.freya02.botcommands.api.application.ApplicationCommand) JDASlashCommand(com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand) GuildSlashEvent(com.freya02.botcommands.api.application.slash.GuildSlashEvent) BContext(com.freya02.botcommands.api.BContext) PaginatorBuilder(com.freya02.botcommands.api.pagination.paginator.PaginatorBuilder) EmojiUtils(com.freya02.botcommands.api.utils.EmojiUtils) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Paginator(com.freya02.botcommands.api.pagination.paginator.Paginator) PaginatorBuilder(com.freya02.botcommands.api.pagination.paginator.PaginatorBuilder)

Aggregations

CommandPath (com.freya02.botcommands.api.application.CommandPath)2 GuildSlashEvent (com.freya02.botcommands.api.application.slash.GuildSlashEvent)2 ApplicationOptionData (com.freya02.botcommands.internal.ApplicationOptionData)2 SlashCommandInfo (com.freya02.botcommands.internal.application.slash.SlashCommandInfo)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Command (net.dv8tion.jda.api.interactions.commands.Command)2 BContext (com.freya02.botcommands.api.BContext)1 ApplicationCommand (com.freya02.botcommands.api.application.ApplicationCommand)1 AppOption (com.freya02.botcommands.api.application.annotations.AppOption)1 Test (com.freya02.botcommands.api.application.annotations.Test)1 GlobalMessageEvent (com.freya02.botcommands.api.application.context.message.GlobalMessageEvent)1 GuildMessageEvent (com.freya02.botcommands.api.application.context.message.GuildMessageEvent)1 GlobalUserEvent (com.freya02.botcommands.api.application.context.user.GlobalUserEvent)1 GuildUserEvent (com.freya02.botcommands.api.application.context.user.GuildUserEvent)1 JDASlashCommand (com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand)1 ComponentManager (com.freya02.botcommands.api.components.ComponentManager)1 Components (com.freya02.botcommands.api.components.Components)1 InteractionConstraints (com.freya02.botcommands.api.components.InteractionConstraints)1 Paginator (com.freya02.botcommands.api.pagination.paginator.Paginator)1