![JAR search and dependency download from the Maven repository](/logo.png)
io.github.freya022.botcommands.internal.commands.text.TextCommandsContextImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of BotCommands Show documentation
Show all versions of BotCommands Show documentation
A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.
package io.github.freya022.botcommands.internal.commands.text
import io.github.freya022.botcommands.api.commands.text.TextCommandsContext
import io.github.freya022.botcommands.internal.utils.throwUser
internal class TextCommandsContextImpl internal constructor() : TextCommandsContext {
private val textCommandMap: MutableMap = hashMapOf()
override val rootCommands: Collection
get() = textCommandMap.values.toList()
internal fun addTextCommand(commandInfo: TopLevelTextCommandInfo) {
(commandInfo.aliases + commandInfo.name).forEach { name ->
textCommandMap.put(name, commandInfo)?.let {
throwUser(commandInfo.variations.first().function, "Text command with path '${commandInfo.path}' already exists")
}
}
}
override fun findTextCommand(words: List): TextCommandInfo? {
val initial: TextCommandInfo = textCommandMap[words.first()] ?: return null
return words
.drop(1) //First word is already resolved
.fold(initial) { info, subname ->
info.subcommands[subname] ?: return null
}
}
override fun findTextSubcommands(words: List): Collection {
val command = findTextCommand(words) ?: return emptyList()
return command.subcommands.values
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy