A
- Self argument object that implements Argument.T
- result object after parsing the argument.public abstract class Argument<A extends Argument,T> extends Object implements IArgument<A,T>
IArgument
Modifier | Constructor and Description |
---|---|
protected |
Argument(@NotNull String name,
@NotNull String prompt,
@NotNull ArgumentTypes type)
Creates an instance of an Argument Object.
|
Modifier and Type | Method and Description |
---|---|
A |
addValidValues(T... validValues)
Add valid values to the argument.
|
abstract A |
clone()
An argument clone is required to prevent a value traveling through different Command calls.
|
protected A |
clone(A clone) |
T |
getDefaultValue()
Get the default value of the argument if the user does not input a value.
|
Double |
getMax()
Get the maximum value allowed for this argument.
|
Double |
getMin()
Get the minimum value allowed for this argument.
|
String |
getName()
Get the argument's name.
|
String |
getPrompt()
Get the argument's prompt.
|
String |
getPrompt(net.dv8tion.jda.api.events.Event event)
Get the argument's prompt.
|
String |
getPromptRaw()
Get the raw value of prompt property.
|
ArgumentTypes |
getType()
Gets the argument's type.
|
@NotNull List<T> |
getValidValues()
return a list of valid values set for this argument.
|
T |
getValue()
Get the current value of the argument.
|
protected com.ericramirezs.commando4j.arguments.RangeError |
inRange(double arg)
Checks if the value is between the expected range.
|
protected com.ericramirezs.commando4j.arguments.RangeError |
inRange(float arg)
Checks if the value is between the expected range.
|
protected com.ericramirezs.commando4j.arguments.RangeError |
inRange(int arg)
Checks if the value is between the expected range.
|
protected com.ericramirezs.commando4j.arguments.RangeError |
inRange(long arg)
Checks if the value is between the expected range.
|
protected com.ericramirezs.commando4j.arguments.RangeError |
inRange(Number arg)
Checks if the value is between the expected range.
|
protected com.ericramirezs.commando4j.arguments.RangeError |
inRange(@NotNull String arg)
Checks if the value is between the expected range.
|
boolean |
isRequired()
Checks if the argument requires a value to be set.
|
@Nullable String |
oneOf(T object,
net.dv8tion.jda.api.events.Event event,
Function<T,String> mapper,
String errorMessageKey)
Checks if the argument is one of the specified valid values.
|
A |
setDefaultValue(Supplier<T> defaultValueFunction)
Set a function to be called if the user did not input a value for this argument.
|
A |
setDefaultValue(T defaultValue)
Set the default value if the user did not input a value for this argument.
|
A |
setMax(Double max)
Set the maximum value allowed for this argument.
|
A |
setMax(float max)
Set the maximum value allowed for this argument.
|
A |
setMax(int max)
Set the maximum value allowed for this argument.
|
A |
setMax(long max)
Set the maximum value allowed for this argument.
|
A |
setMin(Double min)
Set the minimum value allowed for this argument.
|
A |
setMin(float min)
Set the minimum value allowed for this argument.
|
A |
setMin(int min)
Set the minimum value allowed for this argument.
|
A |
setMin(long min)
Set the minimum value allowed for this argument.
|
void |
setPromptParser(Function<net.dv8tion.jda.api.events.Event,String> f)
set a function to handle Argument's prompt.
|
A |
setRequired()
Set if the argument usage is mandatory for the user.
|
A |
setSlashValue(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event,
Object value)
Sets the value when the command is called via discord's slash command.
|
A |
setValue(T value)
Set the parsed value after validations, to be used into the command.
|
String |
validateNull(@Nullable String arg,
net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
Checks if the argument accepts null values.
|
protected Argument(@NotNull @NotNull String name, @NotNull @NotNull String prompt, @NotNull @NotNull ArgumentTypes type)
name
- Readable name to display to the finalprompt
- Hint to indicate the user the expected value to be passed to this argument.type
- Category of the argument implementation.public void setPromptParser(Function<net.dv8tion.jda.api.events.Event,String> f)
f
- function.public String getPromptRaw()
public A setDefaultValue(T defaultValue)
defaultValue
- Value to be used if no value was input by the user.public A setDefaultValue(Supplier<T> defaultValueFunction)
defaultValueFunction
- function to generate a default value.public A setRequired()
public A setMax(int max)
max
- maximum valuepublic A setMax(long max)
max
- maximum valuepublic A setMax(Double max)
max
- maximum valuepublic A setMax(float max)
max
- maximum valuepublic A setMin(int min)
min
- minimum valuepublic A setMin(long min)
min
- minimum valuepublic A setMin(Double min)
min
- minimum valuepublic A setMin(float min)
min
- minimum valueprotected com.ericramirezs.commando4j.arguments.RangeError inRange(Number arg)
arg
- value.RangeError
protected com.ericramirezs.commando4j.arguments.RangeError inRange(int arg)
arg
- value.RangeError
protected com.ericramirezs.commando4j.arguments.RangeError inRange(long arg)
arg
- value.RangeError
protected com.ericramirezs.commando4j.arguments.RangeError inRange(float arg)
arg
- value.RangeError
protected com.ericramirezs.commando4j.arguments.RangeError inRange(@NotNull @NotNull String arg)
arg
- value.RangeError
protected com.ericramirezs.commando4j.arguments.RangeError inRange(double arg)
arg
- value.RangeError
public boolean isRequired()
IArgument
isRequired
in interface IArgument<A extends Argument,T>
IArgument.getValue()
public T getValue()
IArgument
public A setValue(T value)
IArgument
public String getName()
IArgument
public String getPrompt()
IArgument
public String getPrompt(net.dv8tion.jda.api.events.Event event)
IArgument
public T getDefaultValue()
IArgument
getDefaultValue
in interface IArgument<A extends Argument,T>
@SafeVarargs public final A addValidValues(T... validValues)
IArgument
addValidValues
in interface IArgument<A extends Argument,T>
validValues
- list of valid values for the argument.public Double getMax()
IArgument
public Double getMin()
IArgument
@Contract(value=" -> new") @NotNull public @NotNull List<T> getValidValues()
IArgument
getValidValues
in interface IArgument<A extends Argument,T>
public ArgumentTypes getType()
IArgument
public final String validateNull(@Nullable @Nullable String arg, net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
IArgument
validateNull
in interface IArgument<A extends Argument,T>
arg
- argument input by the user.event
- Discord event that triggered this function call.@Nullable public @Nullable String oneOf(T object, net.dv8tion.jda.api.events.Event event, Function<T,String> mapper, String errorMessageKey)
IArgument
oneOf
in interface IArgument<A extends Argument,T>
object
- Value input by the user.event
- Discord event that triggered this function call.mapper
- Mapper to convert the Valid object into readable String for the final user.errorMessageKey
- Error message's key in resource bundle.public A setSlashValue(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event, Object value) throws Exception
IArgument
public abstract A clone()
If your Argument child doesn't have additional attribute, you may just do
return clone(new MyArgument(getName(), getPrompt()));