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

io.github.freya022.botcommands.internal.components.builder.group.AbstractComponentGroupBuilder.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.components.builder.group

import io.github.freya022.botcommands.api.components.ComponentGroup
import io.github.freya022.botcommands.api.components.IGroupHolder
import io.github.freya022.botcommands.api.components.builder.group.ComponentGroupBuilder
import io.github.freya022.botcommands.internal.components.ComponentType
import io.github.freya022.botcommands.internal.components.IGroupHolderMixin
import io.github.freya022.botcommands.internal.components.builder.mixin.IComponentBuilderMixin
import io.github.freya022.botcommands.internal.components.builder.mixin.ITimeoutableComponentMixin
import io.github.freya022.botcommands.internal.components.controller.ComponentController
import kotlinx.coroutines.runBlocking

@PublishedApi
internal sealed class AbstractComponentGroupBuilder>(
    private val componentController: ComponentController,
    private val components: Array,
) : ComponentGroupBuilder,
    IComponentBuilderMixin,
    ITimeoutableComponentMixin {

    init {
        components.forEach {
            check(it.group == null) {
                "Component already has a group assigned: $it"
            }
        }
    }

    override val componentType: ComponentType = ComponentType.GROUP

    internal val componentIds = components.map { it.internalId }

    override fun build(): ComponentGroup = runBlocking { buildSuspend() }

    @PublishedApi
    internal suspend fun buildSuspend(): ComponentGroup {
        return componentController.createGroup(this).also { group ->
            components.forEach {
                (it as IGroupHolderMixin).group = group
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy