ChatCommandParser

Class in charge of handling argument parsing for commands.

Argument parsing is a tricky beast. This class employs multiple strategies in order to try to keep argument parsing as intuitive as possible, without breaking expectations too much. It supports both positional and keyword arguments, plus optional and required arguments and comprehensive error handling.

Please note: The order of arguments in your Arguments subclass matters. Converters are always run in the order they're defined, and positional arguments are also parsed following this order. This means that converters that take lambdas as constructor parameters are able to rely on the values provided by previously parsed arguments.

We recommend reading over the source code if you'd like to get to grips with how this all works.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
open val bot: ExtensibleBot

Current instance of the bot.

Functions

Link copied to clipboard
open suspend fun checkResult(arguments: Arguments, argument: Argument<*>, parser: StringParser, context: ChatCommandContext<*>, kwArgs: MutableList<String>?, result: Any)
Link copied to clipboard
open suspend fun doParse(arguments: Arguments, argument: Argument<*>, parser: StringParser, context: ChatCommandContext<*>, kwArgs: MutableList<String>?): Any
Link copied to clipboard
open override fun getKoin(): Koin

Get the associated Koin instance.

Link copied to clipboard
open suspend fun handleThrowable(arguments: Arguments, argument: Argument<*>, parser: StringParser, context: ChatCommandContext<*>, kwArgs: MutableList<String>?, throwable: Throwable)
Link copied to clipboard
open suspend fun <T : Arguments> parse(builder: () -> T, context: ChatCommandContext<*>): T

Given a builder returning an Arguments subclass and CommandContext, parse the command's arguments into the Arguments subclass and return it.

Link copied to clipboard
open fun signature(builder: () -> Arguments, locale: Locale): String

Generate a command signature based on an Arguments subclass.

Link copied to clipboard
suspend fun throwInvalidValue(arguments: Arguments, argument: Argument<*>, parser: StringParser, context: ChatCommandContext<*>): Nothing
Link copied to clipboard
suspend fun throwNotAllValid(arguments: Arguments, argument: Argument<*>, parser: StringParser, context: ChatCommandContext<*>, numArgs: Int, numParsed: Int): Nothing