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

io.github.freya022.botcommands.internal.commands.prefixed.TextCommandInfo.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.prefixed

import io.github.freya022.botcommands.api.commands.prefixed.builder.TextCommandBuilder
import io.github.freya022.botcommands.internal.commands.AbstractCommandInfo
import io.github.freya022.botcommands.internal.commands.NSFWStrategy
import io.github.freya022.botcommands.internal.commands.mixins.INamedCommand
import io.github.freya022.botcommands.internal.utils.throwUser
import net.dv8tion.jda.api.EmbedBuilder
import java.util.function.Consumer

sealed class TextCommandInfo(
    builder: TextCommandBuilder,
    override val parentInstance: INamedCommand?
) : AbstractCommandInfo(builder) {
    val subcommands: Map

    val variations: List = builder.variations.map { it.build(this) }

    val aliases: List = builder.aliases

    val description: String? = builder.description

    val nsfwStrategy: NSFWStrategy? = builder.nsfwStrategy
    val isOwnerRequired: Boolean = builder.ownerRequired
    val hidden: Boolean = builder.hidden

    val detailedDescription: Consumer? = builder.detailedDescription

    init {
        subcommands = buildMap(builder.subcommands.size + builder.subcommands.sumOf { it.aliases.size }) {
            builder.subcommands.forEach { subcommandBuilder ->
                val textCommandInfo = subcommandBuilder.build(this@TextCommandInfo)
                (subcommandBuilder.aliases + subcommandBuilder.name).forEach { subcommandName ->
                    this.put(subcommandName, textCommandInfo)?.let { commandInfo ->
                        throwUser("Text subcommand with path '${commandInfo.path}' already exists")
                    }
                }
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy