Skip to content

Command Arguments

pumbas600 edited this page Aug 14, 2021 · 19 revisions

Written for HalpBot-Core-1.0.1

In HalpBot, method parameters are automatically assumed to be command arguments except in the following 3 situations:

  1. The parameter type extends GenericEvent (E.g: MessageReceivedEvent). Instead, it'll pass the MessageReceivedEvent that JDA received when the command was called.

  2. The parameter type extends AbstractCommandAdapter (E.g: TokenCommandAdapter). Instead, it'll pass the TokenCommandAdapter that the command is registered to.

  3. The parameter is annotated with @Source. This tells HalpBot that the parameter is meant to be extracted from the MessageReceivedEvent (Just so that you don't have to).

Supported Types

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

Built-In Annotations

Remaining

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";
    }
}

Unrequired

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.

Custom Objects

Reflections

Custom Type Parsers

Clone this wiki locally