-
Notifications
You must be signed in to change notification settings - Fork 0
Command Arguments
Written for HalpBot-Core-1.0.1
In HalpBot, method parameters are automatically assumed to be command arguments except in the following 3 situations:
-
The parameter type extends
GenericEvent(E.g:MessageReceivedEvent). Instead, it'll pass theMessageReceivedEventthat JDA received when the command was called. -
The parameter type extends
AbstractCommandAdapter(E.g:TokenCommandAdapter). Instead, it'll pass theTokenCommandAdapterthat the command is registered to. -
The parameter is annotated with
@Source. This tells HalpBot that the parameter is meant to be extracted from theMessageReceivedEvent(Just so that you don't have to).
HalpBot comes with built-in parsers that handle the most commonly used types.
| Type | Notes |
|---|---|
| Byte/byte | |
| Short/short | |
| Integer/int | |
| Long/long | |
| Float/float | |
| Double/double | |
| Character/char | |
| Boolean/bool |
true is considered to be any of: true, yes, t, y (Not case-sensitive). Anything else will be false
|
| String | By default this only captures a single word |
| Enums | Not case-sensitive |
| List | Returns ArrayList. By default, you need to surround the elements with [...]
|
| Set | Returns HashSet. By default, you need to surround the elements with [...]
|
| Arrays | By default, you need to surround the elements with [...] |
| TextChannel | A text channel specified by #channel-name. Note: For performance reasons, if you just need the id use a long annotated with @Id(TextChannel.class)
|
| User | The user specified by @username. Note: For performance reasons, if you just need the id use a long annotated with @Id(User.class)
|
| Member | The member specified by @username. Note: For performance reasons, if you just need the id use a long annotated with @Id(Member.class)
|
| Default Object Parser | See this for more information |
Supported Types: String
Returns the rest of the arguments as a single String.
private final Map<String, String> definitions = new HashMap<>();
@Command(alias = "define", description = "Adds a description for a word to the dictionary")
public String define(String word, @Remaining String definition) {
word = word.toLowerCase(Locale.ROOT);
if (this.definitions.containsKey(word))
return "That word is already defined in the dictionary as: " + this.definitions.get(word);
else {
this.definitions.put(word, definition);
return "Added the word '" + word + "' to the dictionary";
}
}Supported Types: All Marks a parameter as optional. If that parameter is not present, you can specify a default value as a string, this will then be parsed just as though it had been an argument used in the invocation of the command. This default value is null unless specified.
- Built-in Commands
- @Command Parameters
- Arguments
- Annotations
- Custom Objects
- Custom TypeParsers
- Slash Commands - W.I.P.
- Pagination - W.I.P