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

io.github.freya022.botcommands.api.components.ComponentGroup.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.api.components

import io.github.freya022.botcommands.internal.components.controller.ComponentController
import kotlinx.coroutines.TimeoutCancellationException
import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent

class ComponentGroup internal constructor(
    private val componentController: ComponentController,
    override val internalId: Int
) : IdentifiableComponent, AwaitableComponent {
    @JvmSynthetic
    override suspend fun await(): GenericComponentInteractionCreateEvent = componentController.continuationManager.awaitComponent(this)
}

/**
 * Suspends until the component is used and all checks passed, and returns the event.
 *
 * @throws TimeoutCancellationException If the timeout set in the component builder has been reached
 * @throws ClassCastException If the received event cannot be cast to the requested type
 */
@JvmSynthetic
@Suppress("UNCHECKED_CAST")
suspend fun  ComponentGroup.awaitAny(): T = await() as T

/**
 * Suspends until the component is used and all checks passed, and returns the event,
 * or `null` if the timeout has been reached.
 *
 * @throws ClassCastException If the received event cannot be cast to the requested type
 */
@JvmSynthetic
@Suppress("UNCHECKED_CAST")
suspend fun  ComponentGroup.awaitAnyOrNull(): T? = awaitOrNull() as T?




© 2015 - 2024 Weber Informatics LLC | Privacy Policy