OptionalCoalescingConverter

abstract class OptionalCoalescingConverter<T : Any>(val outputError: Boolean = false, var validator: Validator<T?> = null) : MultiNamedInputConverter<List<T>, T?, Int> , SlashCommandConverter

Abstract base class for an optional coalescing converter.

Coalescing converters take a list of multiple arguments, and consumes as many arguments as it can, combining those arguments into a single value. Upon reaching an argument that can't be consumed, the converter stores its final result and tells the parser how many arguments it managed to consume. The parser will continue processing the unused arguments, passing them to the remaining converters.

An optional coalescing converter has a nullable type - you'll get null from it if nothing could be parsed.

You can create an optional coalescing converter of your own by extending this class.

Inheritors

Constructors

Link copied to clipboard
constructor(outputError: Boolean = false, validator: Validator<T?> = null)

Properties

Link copied to clipboard
open lateinit var argumentObj: Argument<*>

Argument object containing this converter and its metadata.

Link copied to clipboard
open val bot: ExtensibleBot

Current instance of the bot.

Link copied to clipboard

Access to the converter builder, perhaps a bit more hacky than it should be but whatever.

Link copied to clipboard
open val errorType: Key?

If the signatureType isn't sufficient, you can optionally provide a translation key pointing to a longer type string to use for error messages.

Link copied to clipboard
val kord: Kord

Kord instance, backing the ExtensibleBot.

Link copied to clipboard
val outputError: Boolean = false

Whether the argument parser should output parsing errors on invalid arguments.

Link copied to clipboard
open override var parsed: T?

The parsed value.

Link copied to clipboard

This will be set to true by the argument parser if the conversion succeeded.

Link copied to clipboard
open override val required: Boolean
Link copied to clipboard

For commands with generated signatures, set whether the type string should be shown in the signature.

Link copied to clipboard
abstract val signatureType: Key

Translation key pointing to a short string describing the type of data this converter handles. Should be very short.

Link copied to clipboard
open override var validator: Validator<T?>

Validation lambda, which may throw a DiscordRelayedException if required.

Functions

Link copied to clipboard
open suspend fun getErrorKey(): Key

Return a Key representing a pre-translated error string.

Link copied to clipboard
open suspend fun getErrorString(context: CommandContext): String

Return a translated, formatted error string.

Link copied to clipboard
open override fun getKoin(): Koin

Get the associated Koin instance.

Link copied to clipboard
operator fun getValue(thisRef: Arguments, property: KProperty<*>): T?

For delegation, retrieve the parsed value if it's been set, or null if it hasn't.

Link copied to clipboard
open suspend fun handleError(t: Throwable, context: CommandContext): Key

Given a Throwable encountered during the parse function, return a human-readable string to display on Discord.

Link copied to clipboard
open suspend fun mutate(context: CommandContext): T?

Call the mutator lambda, if one was provided.

Link copied to clipboard
abstract suspend fun parse(parser: StringParser?, context: CommandContext, named: List<String>? = null): Int

Process the string in the given parser, converting it into a new value.

Link copied to clipboard
abstract suspend fun parseOption(context: CommandContext, option: OptionValue<*>): Boolean

Use the given option taken straight from the slash command invocation to fill the converter.

Link copied to clipboard
abstract suspend fun toSlashOption(arg: Argument<*>): OptionWrapper<*>
Link copied to clipboard
open suspend fun validate(context: CommandContext)

Call the validator lambda, if one was provided.