io.github.freya022.botcommands.internal.commands.application.ApplicationCommandDataMap.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.application
import io.github.freya022.botcommands.api.commands.CommandPath
import io.github.freya022.botcommands.api.core.utils.enumMapOf
import net.dv8tion.jda.api.interactions.commands.build.CommandData
import java.util.function.Function
import net.dv8tion.jda.api.interactions.commands.Command.Type as CommandType
internal class ApplicationCommandDataMap {
//The String is CommandPath's base name
private val typeMap: MutableMap> = enumMapOf()
val allCommandData: Collection
get() = typeMap
.values
.flatMap { it.values }
fun computeIfAbsent(type: CommandType, path: CommandPath, mappingFunction: Function): CommandData {
return this[type].computeIfAbsent(path.name, mappingFunction)
}
operator fun set(type: CommandType, name: String, value: CommandData) {
this[type][name] = value
}
private operator fun get(type: CommandType) = typeMap.computeIfAbsent(type) { hashMapOf() }
}