me.jakejmattson.kutils.api.dsl.arguments.CommandArguments.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of KUtils Show documentation
Show all versions of KUtils Show documentation
A Discord bot framework for Kotlin.
@file:Suppress("unused")
package me.jakejmattson.kutils.api.dsl.arguments
import me.jakejmattson.kutils.api.dsl.command.CommandEvent
sealed class ArgumentResult {
data class Success(val result: T, val consumed: Int = 1) : ArgumentResult()
data class Error(val error: String) : ArgumentResult()
}
abstract class ArgumentType : Cloneable {
abstract val name: String
var isOptional: Boolean = false
private set
var defaultValue: ((CommandEvent<*>) -> T)? = null
private set
private fun cloneToOptional() = (clone() as ArgumentType).apply { isOptional = true }
fun makeOptional(default: T) = cloneToOptional().apply { defaultValue = { default } }
fun makeOptional(default: (CommandEvent<*>) -> T) = cloneToOptional().apply { defaultValue = default }
fun makeNullableOptional(default: T? = null) = cloneToOptional().apply { defaultValue = { default } }
fun makeNullableOptional(default: (CommandEvent<*>) -> T?) = cloneToOptional().apply { defaultValue = default }
abstract fun convert(arg: String, args: List, event: CommandEvent<*>): ArgumentResult
abstract fun generateExamples(event: CommandEvent<*>): List
override fun toString() = this::class.toString().substringAfterLast(".").substringBefore("$")
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy