All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.freya022.botcommands.api.modals.ModalBuilder Maven / Gradle / Ivy

Go to download

A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.

There is a newer version: 3.0.0-alpha.18
Show newest version
package io.github.freya022.botcommands.api.modals;

import io.github.freya022.botcommands.api.modals.annotations.ModalData;
import io.github.freya022.botcommands.api.modals.annotations.ModalHandler;
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

public abstract class ModalBuilder extends net.dv8tion.jda.api.interactions.modals.Modal.Builder implements IModalBuilder {
	protected ModalBuilder(@NotNull String customId, @NotNull String title) {
		super(customId, title);
	}

	/**
	 * Binds the following handler (defined by {@link ModalHandler}) with its arguments
	 *
	 * 
This step is optional if you do not wish to use methods for that * * @param handlerName The name of the modal handler, must be the same as your {@link ModalHandler} * @param userData The optional user data to be passed to the modal handler via {@link ModalData} * * @return This builder for chaining convenience */ @NotNull public abstract ModalBuilder bindTo(@NotNull String handlerName, @NotNull List<@Nullable Object> userData); /** * Binds the following handler (defined by {@link ModalHandler}) with its arguments * *
This step is optional if you do not wish to use methods for that * * @param handlerName The name of the modal handler, must be the same as your {@link ModalHandler} * @param userData The optional user data to be passed to the modal handler via {@link ModalData} * * @return This builder for chaining convenience */ @NotNull public final ModalBuilder bindTo(@NotNull String handlerName, @Nullable Object @NotNull ... userData) { return bindTo(handlerName, Arrays.asList(userData)); } /** * Binds the following handler to this modal * *
This step is optional if you do not wish to use handlers for that * * @param handler The modal handler to run when the modal is used * * @return This builder for chaining convenience */ @NotNull public abstract ModalBuilder bindTo(@NotNull Consumer handler); /** * Sets the timeout for this modal, the modal will not be recognized after the timeout has passed *
The timeout will start when the modal is built * *

It is extremely recommended to put a timeout on your modals, if your user dismisses the modal, so, never uses it, the data of the modal could stay in your RAM indefinitely * * @param timeout The amount of time in the supplied time unit before the modal is removed * @param unit The time unit of the timeout * @param onTimeout The function to run when the timeout has been reached * * @return This builder for chaining convenience */ @NotNull public final ModalBuilder setTimeout(long timeout, @NotNull TimeUnit unit, @NotNull Runnable onTimeout) { return setTimeout(Duration.of(timeout, unit.toChronoUnit()), onTimeout); } /** * Sets the timeout for this modal, the modal will not be recognized after the timeout has passed *
The timeout will start when the modal is built * *

It is extremely recommended to put a timeout on your modals, if your user dismisses the modal, so, never uses it, the data of the modal could stay in your RAM indefinitely * * @param timeout The amount of time before the modal is removed * @param onTimeout The function to run when the timeout has been reached * * @return This builder for chaining convenience */ @NotNull public abstract ModalBuilder setTimeout(@NotNull Duration timeout, @NotNull Runnable onTimeout); /** * {@inheritDoc} * *

You can still set a custom ID on this ModalBuilder, this is an optional step * *
This could be useful if this modal gets closed by the user by mistake, as Discord caches the inputs by its modal ID (and input IDs), * keeping the same ID might help the user not having to type things again * *

Pay attention, if the ID is the same then it means that modals associated to that ID will be overwritten, * so you should do something like appending the interacting user's ID at the end of the modal ID */ @NotNull public ModalBuilder setId(@NotNull String customId) { super.setId(customId); return this; } @NotNull protected final net.dv8tion.jda.api.interactions.modals.Modal jdaBuild() { return super.build(); } @NotNull public abstract Modal build(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy