me.jakejmattson.kutils.api.arguments.DoubleArg.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.
package me.jakejmattson.kutils.api.arguments
import me.jakejmattson.kutils.api.dsl.arguments.*
import me.jakejmattson.kutils.api.dsl.command.CommandEvent
import kotlin.random.Random
open class DoubleArg(override val name: String = "Decimal") : ArgumentType() {
companion object : DoubleArg()
override fun convert(arg: String, args: List, event: CommandEvent<*>): ArgumentResult {
val double = arg.toDoubleOrNull()
?: return ArgumentResult.Error("Couldn't parse $name from $arg.")
return ArgumentResult.Success(double)
}
override fun generateExamples(event: CommandEvent<*>) = listOf(
"%.2f".format(Random.nextDouble(0.00, 9.99))
)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy