Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stage channel create functions #856

Merged
merged 4 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -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/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/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;
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions core/src/commonMain/kotlin/behavior/GuildBehavior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.unwrap
import dev.kord.common.exception.RequestException
import dev.kord.core.Kord
import dev.kord.core.behavior.channel.CategoryBehavior
import dev.kord.core.cache.data.*
import dev.kord.core.cache.idEq
import dev.kord.core.catchDiscordError
Expand Down Expand Up @@ -824,6 +825,29 @@ 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 CategoryBehavior.createStageChannel(
NoComment1105 marked this conversation as resolved.
Show resolved Hide resolved
name: String,
builder: StageChannelCreateBuilder.() -> Unit = {}
): StageChannel {
contract {
callsInPlace(builder, 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
}


/**
* Requests to create a new category.
Expand Down
34 changes: 25 additions & 9 deletions core/src/commonMain/kotlin/behavior/channel/CategoryBehavior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -198,3 +192,25 @@ 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
}
26 changes: 26 additions & 0 deletions rest/api/rest.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (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 <init> ()V
public fun addOverwrite (Ldev/kord/common/entity/Overwrite;)V
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.common.serialization.DurationInSeconds
import dev.kord.rest.builder.AuditRequestBuilder
import dev.kord.rest.json.request.GuildChannelCreateRequest

@KordDsl
public class StageChannelCreateBuilder(public var name: String) :
PermissionOverwritesCreateBuilder,
AuditRequestBuilder<GuildChannelCreateRequest> {
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<DurationInSeconds> = Optional.Missing()
public var rateLimitPerUser: DurationInSeconds? by ::_rateLimitPerUser.delegate()
lukellmann marked this conversation as resolved.
Show resolved Hide resolved

private var _position: OptionalInt = OptionalInt.Missing
public var position: Int? by ::_position.delegate()

override var permissionOverwrites: MutableSet<Overwrite> = 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
)
}
10 changes: 10 additions & 0 deletions rest/src/commonMain/kotlin/service/GuildService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down