DurationConverter

class DurationConverter(val longHelp: Boolean = true, val positiveOnly: Boolean = true, var validator: Validator<DateTimePeriod> = null) : SingleConverter<DateTimePeriod>

Argument converter for Kotlin DateTimePeriod arguments. You can apply these to an Instant using plus and a timezone. Also accepts discord-formatted timestamps, in which case the DateTimePeriod will be the time until the timestamp.

Parameters

longHelp

Whether to send the user a long help message with specific information on how to specify durations.

positiveOnly

Whether a positive duration is required - true by default.

Constructors

Link copied to clipboard
constructor(longHelp: Boolean = true, positiveOnly: Boolean = true, validator: Validator<DateTimePeriod> = 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
open lateinit var builder: ConverterBuilder<DateTimePeriod>

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 longHelp: Boolean = true
Link copied to clipboard
open lateinit override var parsed: DateTimePeriod

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
val positiveOnly: Boolean = true
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
open override 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<DateTimePeriod>

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<*>): DateTimePeriod

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): DateTimePeriod

Call the mutator lambda, if one was provided.

Link copied to clipboard
open suspend override fun parse(parser: StringParser?, context: CommandContext, named: String?): Boolean

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

Link copied to clipboard
open suspend override 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
open fun toDefaulting(defaultValue: DateTimePeriod, outputError: Boolean = false, signatureType: Key? = null, showTypeInSignature: Boolean? = null, errorType: Key? = null, nestedValidator: Validator<DateTimePeriod> = null): DefaultingConverter<DateTimePeriod>

Wrap this single converter with a SingleToDefaultingConverter, which is a special converter that will act like a DefaultingConverter using the same logic of this converter.

Link copied to clipboard
open fun toList(required: Boolean = true, signatureType: Key? = null, showTypeInSignature: Boolean? = null, errorType: Key? = null, nestedValidator: Validator<List<DateTimePeriod>> = null): ListConverter<DateTimePeriod>

Wrap this single converter with a SingleToListConverter, which is a special converter that will act like a ListConverter using the same logic of this converter.

Link copied to clipboard
open fun toOptional(signatureType: Key? = null, showTypeInSignature: Boolean? = null, errorType: Key? = null, outputError: Boolean = false, nestedValidator: Validator<DateTimePeriod?> = null): OptionalConverter<DateTimePeriod>

Wrap this single converter with a SingleToOptionalConverter, which is a special converter that will act like an OptionalConverter using the same logic of this converter.

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

Call the validator lambda, if one was provided.