A
- Self argument object that implements IArgument.T
- result object after parsing the argument.public interface IArgument<A extends IArgument,T>
An argument refers to any text entered by the user after the command name, which will be used to make a command function perform certain functions based on these arguments.
The goal of the implementation is to manage the validation and conversion of the parameter to a specific object, to simplify the development of the command.
ICommand
Modifier and Type | Method and Description |
---|---|
A |
addValidValues(T... validValues)
Add valid values to the argument.
|
A |
clone()
An argument clone is required to prevent a value traveling through different Command calls.
|
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.
|
ArgumentTypes |
getType()
Gets the argument's type.
|
List<T> |
getValidValues()
return a list of valid values set for this argument.
|
T |
getValue()
Get the current value of the argument.
|
boolean |
isRequired()
Checks if the argument requires a value to be set.
|
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.
|
T |
parse(net.dv8tion.jda.api.events.message.MessageReceivedEvent event,
String arg)
To be called if all validations passed.
|
T |
parse(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event,
String arg)
To be called if all validations passed.
|
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 |
validate(net.dv8tion.jda.api.events.message.MessageReceivedEvent event,
String arg)
Validates if the argument input by the user is a valid value.
|
String |
validate(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event,
String arg)
Validates if the argument input by the user is a valid value.
|
String |
validateNull(String arg,
net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
Checks if the argument accepts null values.
|
boolean isRequired()
getValue()
Double getMax()
Double getMin()
String getName()
String getPrompt()
String getPrompt(net.dv8tion.jda.api.events.Event event)
event
- Discord event that triggered this function call.String validateNull(String arg, net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
arg
- argument input by the user.event
- Discord event that triggered this function call.String oneOf(T object, net.dv8tion.jda.api.events.Event event, Function<T,String> mapper, String errorMessageKey)
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.String validate(net.dv8tion.jda.api.events.message.MessageReceivedEvent event, String arg)
event
- Discord event that triggered this function call.arg
- argument input by the user.String validate(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event, String arg)
event
- Discord event that triggered this function call.arg
- argument input by the user.T getDefaultValue()
T getValue()
A setValue(T value)
value
- final value after parsing.T parse(net.dv8tion.jda.api.events.message.MessageReceivedEvent event, String arg) throws Exception
event
- Discord event that triggered this function call.arg
- argument input by the user.Exception
- The method should NEVER throw an exception, any possible exceptions
should be checked in the validate method.validate(MessageReceivedEvent, String)
T parse(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event, String arg) throws Exception
event
- Discord event that triggered this function call.arg
- argument input by the user.Exception
- The method should NEVER throw an exception, any possible exceptions
should be checked in the validate method.validate(MessageReceivedEvent, String)
ArgumentTypes getType()
A setSlashValue(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event, Object value) throws Exception
List<T> getValidValues()
A addValidValues(T... validValues)
validValues
- list of valid values for the argument.A clone()