me.jakejmattson.kutils.api.arguments.SplitterArg.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
open class SplitterArg(override val name: String = "TextWithSplitter", private val splitter: String = "|") : ArgumentType>() {
companion object : SplitterArg()
override fun convert(arg: String, args: List, event: CommandEvent<*>): ArgumentResult> {
val joined = args.joinToString(" ")
if (!joined.contains(splitter))
return ArgumentResult.Error("$name requires the character `$splitter` to split input.")
return ArgumentResult.Success(joined.split(splitter).toList(), args.size)
}
override fun generateExamples(event: CommandEvent<*>) = listOf("A${splitter}B${splitter}C")
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy