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

commonMain.builder.channel.thread.StartForumThreadBuilder.kt Maven / Gradle / Ivy

There is a newer version: 0.15.0
Show newest version
package dev.kord.rest.builder.channel.thread

import dev.kord.common.annotation.KordDsl
import dev.kord.common.entity.ArchiveDuration
import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.delegate.delegate
import dev.kord.rest.builder.AuditRequestBuilder
import dev.kord.rest.builder.message.create.ForumMessageCreateBuilder
import dev.kord.rest.json.request.MultipartStartThreadRequest
import dev.kord.rest.json.request.StartThreadRequest
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.time.Duration

@KordDsl
public class StartForumThreadBuilder(public var name: String) : AuditRequestBuilder {
    override var reason: String? = null

    private var _autoArchiveDuration: Optional = Optional.Missing()
    public var autoArchiveDuration: ArchiveDuration? by ::_autoArchiveDuration.delegate()

    private var _rateLimitPerUser: Optional = Optional.Missing()
    public var rateLimitPerUser: Duration? by ::_rateLimitPerUser.delegate()

    private var _appliedTags: Optional> = Optional.Missing()
    public var appliedTags: MutableList? by ::_appliedTags.delegate()

    public var message: ForumMessageCreateBuilder = ForumMessageCreateBuilder()

    public fun message(content: String) {
        message.content = content
    }

    public inline fun message(builder: ForumMessageCreateBuilder.() -> Unit) {
        contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
        message.apply(builder)
    }

    override fun toRequest(): MultipartStartThreadRequest {
        val messageRequest = message.toRequest()

        return MultipartStartThreadRequest(
            StartThreadRequest(
                name = name,
                autoArchiveDuration = _autoArchiveDuration,
                rateLimitPerUser = _rateLimitPerUser,
                message = Optional(messageRequest.request),
                appliedTags = _appliedTags
            ),
            files = messageRequest.files,
        )
    }
}

/** Add a [tagId] to [appliedTags][StartForumThreadBuilder.appliedTags]. */
public fun StartForumThreadBuilder.applyTag(tagId: Snowflake) {
    appliedTags?.add(tagId) ?: run { appliedTags = mutableListOf(tagId) }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy