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

io.github.freya022.botcommands.internal.components.builder.PersistentTimeoutableComponentImpl.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.22
Show newest version
package io.github.freya022.botcommands.internal.components.builder

import io.github.freya022.botcommands.api.components.Components
import io.github.freya022.botcommands.api.components.builder.IPersistentTimeoutableComponent
import io.github.freya022.botcommands.internal.components.data.PersistentTimeout
import io.github.freya022.botcommands.internal.utils.throwUser
import io.github.freya022.botcommands.internal.utils.toTimestampIfFinite
import kotlin.time.Duration

internal class PersistentTimeoutableComponentImpl> internal constructor(
    override val instanceRetriever: InstanceRetriever
) : BuilderInstanceHolderImpl(),
    IPersistentTimeoutableComponent {

    override var timeout: PersistentTimeout? = Components.defaultTimeout.toTimestampIfFinite()?.let { PersistentTimeout.create(it) }
        private set

    override fun noTimeout(): T = instance.also {
        timeout = null
    }

    override fun timeout(timeout: Duration): T = instance.also {
        val expirationTimestamp = timeout.toTimestampIfFinite() ?: throwUser("Timeout must be positive and finite")
        this.timeout = PersistentTimeout.create(expirationTimestamp)
    }

    override fun timeout(timeout: Duration, handlerName: String, vararg data: Any?): T = instance.also {
        val expirationTimestamp = timeout.toTimestampIfFinite() ?: throwUser("Timeout must be positive and finite")
        this.timeout = PersistentTimeout.create(expirationTimestamp, handlerName, data.toList())
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy