diff --git a/core/api/core.api b/core/api/core.api index 983cc33c83a..a5cc99f4ea5 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -407,6 +407,8 @@ public final class dev/kord/core/behavior/GuildBehaviorKt { public static final fun createScheduledEvent (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Ldev/kord/common/entity/GuildScheduledEventPrivacyLevel;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/ScheduledEntityType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun createSpamAutoModerationRule (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun createSpamAutoModerationRule$default (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun createStageChannel (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun createStageChannel$default (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun createTextChannel (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun createTextChannel$default (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun createUserCommand (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -1057,6 +1059,8 @@ public final class dev/kord/core/behavior/channel/CategoryBehaviorKt { public static synthetic fun CategoryBehavior$default (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplyStrategy;ILjava/lang/Object;)Ldev/kord/core/behavior/channel/CategoryBehavior; public static final fun createNewsChannel (Ldev/kord/core/behavior/channel/CategoryBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun createNewsChannel$default (Ldev/kord/core/behavior/channel/CategoryBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun createStageChannel (Ldev/kord/core/behavior/channel/CategoryBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun createStageChannel$default (Ldev/kord/core/behavior/channel/CategoryBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun createTextChannel (Ldev/kord/core/behavior/channel/CategoryBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun createTextChannel$default (Ldev/kord/core/behavior/channel/CategoryBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun createVoiceChannel (Ldev/kord/core/behavior/channel/CategoryBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; diff --git a/core/src/commonMain/kotlin/behavior/GuildBehavior.kt b/core/src/commonMain/kotlin/behavior/GuildBehavior.kt index d2253141705..242f2424059 100644 --- a/core/src/commonMain/kotlin/behavior/GuildBehavior.kt +++ b/core/src/commonMain/kotlin/behavior/GuildBehavior.kt @@ -824,6 +824,26 @@ public suspend inline fun GuildBehavior.createNewsChannel( return Channel.from(data, kord) as NewsChannel } +/** + * Requests to create a new stage channel. + * + * @return The created [StageChannel]. + * + * @throws [RestRequestException] if something went wrong during the request. + */ +public suspend inline fun GuildBehavior.createStageChannel( + name: String, + builder: StageChannelCreateBuilder.() -> Unit = {} +): StageChannel { + contract { + callsInPlace(builder, EXACTLY_ONCE) + } + val response = kord.rest.guild.createStageChannel(id, name, builder) + val data = ChannelData.from(response) + + return Channel.from(data, kord) as StageChannel +} + /** * Requests to create a new category. diff --git a/core/src/commonMain/kotlin/behavior/channel/CategoryBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/CategoryBehavior.kt index e7057d60a8b..b492f5a6a01 100644 --- a/core/src/commonMain/kotlin/behavior/channel/CategoryBehavior.kt +++ b/core/src/commonMain/kotlin/behavior/channel/CategoryBehavior.kt @@ -6,23 +6,17 @@ import dev.kord.core.Kord import dev.kord.core.cache.data.ChannelData import dev.kord.core.entity.channel.* import dev.kord.core.exception.EntityNotFoundException +import dev.kord.core.hash import dev.kord.core.supplier.EntitySupplier import dev.kord.core.supplier.EntitySupplyStrategy import dev.kord.core.supplier.getChannelOf import dev.kord.core.supplier.getChannelOfOrNull -import dev.kord.rest.builder.channel.CategoryModifyBuilder -import dev.kord.rest.builder.channel.NewsChannelCreateBuilder -import dev.kord.rest.builder.channel.TextChannelCreateBuilder -import dev.kord.rest.builder.channel.VoiceChannelCreateBuilder +import dev.kord.rest.builder.channel.* import dev.kord.rest.request.RestRequestException -import dev.kord.rest.service.createNewsChannel -import dev.kord.rest.service.createTextChannel -import dev.kord.rest.service.createVoiceChannel -import dev.kord.rest.service.patchCategory +import dev.kord.rest.service.* import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterIsInstance -import dev.kord.core.hash import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -198,3 +192,26 @@ public suspend inline fun CategoryBehavior.createNewsChannel( return Channel.from(data, kord) as NewsChannel } + +/** + * Requests to create a new stage channel with this category as parent. + * + * @return The created [StageChannel]. + * + * @throws [RestRequestException] if something went wrong during the request. + */ +public suspend inline fun CategoryBehavior.createStageChannel( + name: String, + builder: StageChannelCreateBuilder.() -> Unit = {} +): StageChannel { + contract { + callsInPlace(builder, InvocationKind.EXACTLY_ONCE) + } + val response = kord.rest.guild.createStageChannel(guildId, name) { + builder() + parentId = id + } + val data = ChannelData.from(response) + + return Channel.from(data, kord) as StageChannel +} diff --git a/rest/api/rest.api b/rest/api/rest.api index 4278c640586..0b4a20cd253 100644 --- a/rest/api/rest.api +++ b/rest/api/rest.api @@ -678,6 +678,31 @@ public final class dev/kord/rest/builder/channel/PermissionOverwritesModifyBuild public static fun addOverwrite (Ldev/kord/rest/builder/channel/PermissionOverwritesModifyBuilder;Ldev/kord/common/entity/Overwrite;)V } +public final class dev/kord/rest/builder/channel/StageChannelCreateBuilder : dev/kord/rest/builder/AuditRequestBuilder, dev/kord/rest/builder/channel/PermissionOverwritesCreateBuilder { + public fun (Ljava/lang/String;)V + public fun addOverwrite (Ldev/kord/common/entity/Overwrite;)V + public final fun getBitrate ()Ljava/lang/Integer; + public final fun getName ()Ljava/lang/String; + public final fun getNsfw ()Ljava/lang/Boolean; + public final fun getParentId ()Ldev/kord/common/entity/Snowflake; + public fun getPermissionOverwrites ()Ljava/util/Set; + public final fun getPosition ()Ljava/lang/Integer; + public final fun getRateLimitPerUser-FghU774 ()Lkotlin/time/Duration; + public fun getReason ()Ljava/lang/String; + public final fun getUserLimit ()Ljava/lang/Integer; + public final fun setBitrate (Ljava/lang/Integer;)V + public final fun setName (Ljava/lang/String;)V + public final fun setNsfw (Ljava/lang/Boolean;)V + public final fun setParentId (Ldev/kord/common/entity/Snowflake;)V + public fun setPermissionOverwrites (Ljava/util/Set;)V + public final fun setPosition (Ljava/lang/Integer;)V + public final fun setRateLimitPerUser-BwNAW2A (Lkotlin/time/Duration;)V + public fun setReason (Ljava/lang/String;)V + public final fun setUserLimit (Ljava/lang/Integer;)V + public fun toRequest ()Ldev/kord/rest/json/request/GuildChannelCreateRequest; + public synthetic fun toRequest ()Ljava/lang/Object; +} + public final class dev/kord/rest/builder/channel/StageVoiceChannelModifyBuilder : dev/kord/rest/builder/AuditRequestBuilder, dev/kord/rest/builder/channel/PermissionOverwritesModifyBuilder { public fun ()V public fun addOverwrite (Ldev/kord/common/entity/Overwrite;)V @@ -7263,6 +7288,7 @@ public final class dev/kord/rest/service/GuildServiceKt { public static final fun createNewsChannel (Ldev/kord/rest/service/GuildService;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun createScheduledEvent (Ldev/kord/rest/service/GuildService;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/GuildScheduledEventPrivacyLevel;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/ScheduledEntityType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun createScheduledEvent$default (Ldev/kord/rest/service/GuildService;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/GuildScheduledEventPrivacyLevel;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/ScheduledEntityType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun createStageChannel (Ldev/kord/rest/service/GuildService;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun createTextChannel (Ldev/kord/rest/service/GuildService;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun createVoiceChannel (Ldev/kord/rest/service/GuildService;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun modifyCurrentVoiceState (Ldev/kord/rest/service/GuildService;Ldev/kord/common/entity/Snowflake;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; diff --git a/rest/src/commonMain/kotlin/builder/channel/StageChannelCreateBuilder.kt b/rest/src/commonMain/kotlin/builder/channel/StageChannelCreateBuilder.kt new file mode 100644 index 00000000000..afd25c4155b --- /dev/null +++ b/rest/src/commonMain/kotlin/builder/channel/StageChannelCreateBuilder.kt @@ -0,0 +1,53 @@ +package dev.kord.rest.builder.channel + +import dev.kord.common.annotation.KordDsl +import dev.kord.common.entity.ChannelType +import dev.kord.common.entity.Overwrite +import dev.kord.common.entity.Snowflake +import dev.kord.common.entity.optional.Optional +import dev.kord.common.entity.optional.OptionalBoolean +import dev.kord.common.entity.optional.OptionalInt +import dev.kord.common.entity.optional.OptionalSnowflake +import dev.kord.common.entity.optional.delegate.delegate +import dev.kord.rest.builder.AuditRequestBuilder +import dev.kord.rest.json.request.GuildChannelCreateRequest +import kotlin.time.Duration + +@KordDsl +public class StageChannelCreateBuilder(public var name: String) : + PermissionOverwritesCreateBuilder, + AuditRequestBuilder { + override var reason: String? = null + + private var _bitrate: OptionalInt = OptionalInt.Missing + public var bitrate: Int? by ::_bitrate.delegate() + + private var _userLimit: OptionalInt = OptionalInt.Missing + public var userLimit: Int? by ::_userLimit.delegate() + + private var _rateLimitPerUser: Optional = Optional.Missing() + public var rateLimitPerUser: Duration? by ::_rateLimitPerUser.delegate() + + private var _position: OptionalInt = OptionalInt.Missing + public var position: Int? by ::_position.delegate() + + override var permissionOverwrites: MutableSet = mutableSetOf() + + private var _parentId: OptionalSnowflake = OptionalSnowflake.Missing + public var parentId: Snowflake? by ::_parentId.delegate() + + private var _nsfw: OptionalBoolean = OptionalBoolean.Missing + public var nsfw: Boolean? by ::_nsfw.delegate() + + override fun toRequest(): GuildChannelCreateRequest = GuildChannelCreateRequest( + name = name, + type = ChannelType.GuildStageVoice, + bitrate = _bitrate, + userLimit = _userLimit, + rateLimitPerUser = _rateLimitPerUser, + position = _position, + permissionOverwrite = Optional.missingOnEmpty(permissionOverwrites), + parentId = _parentId, + nsfw = _nsfw + ) +} diff --git a/rest/src/commonMain/kotlin/service/GuildService.kt b/rest/src/commonMain/kotlin/service/GuildService.kt index 53f0d0ddf25..f2f849adeff 100644 --- a/rest/src/commonMain/kotlin/service/GuildService.kt +++ b/rest/src/commonMain/kotlin/service/GuildService.kt @@ -574,6 +574,16 @@ public suspend inline fun GuildService.createVoiceChannel( return createGuildChannel(guildId, createBuilder.toRequest(), createBuilder.reason) } +public suspend inline fun GuildService.createStageChannel( + guildId: Snowflake, + name: String, + builder: StageChannelCreateBuilder.() -> Unit +): DiscordChannel { + contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } + val createBuilder = StageChannelCreateBuilder(name).apply(builder) + return createGuildChannel(guildId, createBuilder.toRequest(), createBuilder.reason) +} + public suspend inline fun GuildService.createCategory( guildId: Snowflake, name: String,