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

com.freya02.botcommands.api.commands.application.slash.builder.SlashSubcommandGroupBuilder.kt Maven / Gradle / Ivy

package com.freya02.botcommands.api.commands.application.slash.builder

import com.freya02.botcommands.api.commands.CommandPath
import com.freya02.botcommands.api.commands.application.slash.builder.SlashCommandBuilder.Companion.DEFAULT_DESCRIPTION
import com.freya02.botcommands.internal.BContextImpl
import com.freya02.botcommands.internal.commands.CommandDSL
import com.freya02.botcommands.internal.commands.application.SimpleCommandMap
import com.freya02.botcommands.internal.commands.application.slash.SlashSubcommandGroupInfo
import com.freya02.botcommands.internal.commands.application.slash.TopLevelSlashCommandInfo
import com.freya02.botcommands.internal.commands.mixins.INamedCommand
import com.freya02.botcommands.internal.commands.mixins.INamedCommand.Companion.computePath
import net.dv8tion.jda.internal.utils.Checks
import kotlin.reflect.KFunction

@CommandDSL
class SlashSubcommandGroupBuilder(private val context: BContextImpl, override val name: String, private val topLevelBuilder: TopLevelSlashCommandBuilder) : INamedCommand {
    override val parentInstance: INamedCommand = topLevelBuilder
    override val path: CommandPath by lazy { computePath() }

    @get:JvmSynthetic
    internal val subcommands: SimpleCommandMap = SimpleCommandMap.ofBuilders()

    var description: String = DEFAULT_DESCRIPTION

    init {
        Checks.matches(name, Checks.ALPHANUMERIC_WITH_DASH, "Text command name")
    }

    @JvmSynthetic
    fun subcommand(name: String, function: KFunction, block: SlashSubcommandBuilder.() -> Unit = {}) {
        SlashSubcommandBuilder(context, name, function, topLevelBuilder, this).apply(block).also(subcommands::putNewCommand)
    }

    fun build(topLevelInstance: TopLevelSlashCommandInfo): SlashSubcommandGroupInfo {
        return SlashSubcommandGroupInfo(topLevelInstance, this)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy