All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.freya022.botcommands.internal.commands.application.ApplicationCommandDataMap.kt Maven / Gradle / Ivy

Go to download

A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.

There is a newer version: 3.0.0-alpha.18
Show newest version
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() }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy