io.github.freya022.botcommands.api.commands.text.TextCommand Maven / Gradle / Ivy
Show all versions of BotCommands Show documentation
package io.github.freya022.botcommands.api.commands.text;
import io.github.freya022.botcommands.api.commands.CommandPath;
import io.github.freya022.botcommands.api.commands.annotations.GeneratedOption;
import io.github.freya022.botcommands.api.commands.text.annotations.JDATextCommandVariation;
import io.github.freya022.botcommands.api.commands.text.builder.TextCommandBuilder;
import io.github.freya022.botcommands.api.commands.text.provider.TextCommandProvider;
import io.github.freya022.botcommands.api.core.reflect.ParameterType;
import net.dv8tion.jda.api.EmbedBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Consumer;
/**
* Base class for annotated text commands.
*
* You are not required to use this if you use {@link TextCommandProvider}
*
* @see JDATextCommandVariation @JDATextCommandVariation
*/
public abstract class TextCommand {
/**
*
Returns a detailed embed of what the command is, it is used by the internal {@code help} command
* The {@code help} command will automatically set the embed title to be {@code Command '[command_name]'} but can be overridden
* It will also set the embed's description to be the command's description, you can override with {@link EmbedBuilder#setDescription(CharSequence)}
*
* @return The EmbedBuilder to use as a detailed description
*
* @see TextCommandBuilder#setDetailedDescription(Consumer) DSL equivalent
*/
@Nullable
public Consumer getDetailedDescription() {
return null;
}
/**
* Returns the generated value supplier of an {@link GeneratedOption @GeneratedOption},
* if the method doesn't return a generated value supplier, the framework will throw.
*
This method is called only if your option is annotated with {@link GeneratedOption @GeneratedOption}
*
* This method will only be called once per command option per guild
*
* @param commandPath The path of the command, as set in {@link JDATextCommandVariation}
* @param optionName The name of the transformed command option, might not be equal to the parameter name
* @param parameterType The boxed type of the command option
*
* @return A {@link TextGeneratedValueSupplier} to generate the option on command execution
*/
@NotNull
public TextGeneratedValueSupplier getGeneratedValueSupplier(@NotNull CommandPath commandPath,
@NotNull String optionName,
@NotNull ParameterType parameterType) {
throw new IllegalArgumentException("Option '%s' in command path '%s' is a generated option but no generated value supplier has been given".formatted(optionName, commandPath.getFullPath()));
}
}