-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
191 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
core/src/main/kotlin/behavior/VoiceStageChannelBehavior.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package dev.kord.core.behavior | ||
|
||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.core.Kord | ||
import dev.kord.core.cache.data.ChannelData | ||
import dev.kord.core.entity.channel.CategorizableChannel | ||
import dev.kord.core.supplier.EntitySupplier | ||
import dev.kord.core.supplier.EntitySupplyStrategy | ||
import dev.kord.rest.builder.guild.CurrentVoiceStateModifyBuilder | ||
import dev.kord.rest.builder.guild.VoiceStateModifyBuilder | ||
import dev.kord.rest.service.modifyCurrentVoiceState | ||
import dev.kord.rest.service.modifyVoiceState | ||
import kotlin.contracts.ExperimentalContracts | ||
import kotlin.contracts.InvocationKind | ||
import kotlin.contracts.contract | ||
|
||
interface VoiceStageChannelBehavior : CategorizableChannel { | ||
|
||
override fun withStrategy(strategy: EntitySupplyStrategy<*>): VoiceStageChannelBehavior { | ||
return VoiceStageChannelBehavior(data, kord, strategy.supply(kord)) | ||
} | ||
|
||
fun VoiceStageChannelBehavior( | ||
data: ChannelData, | ||
kord: Kord, | ||
supplier: EntitySupplier = kord.defaultSupplier | ||
): VoiceStageChannelBehavior = object : VoiceStageChannelBehavior { | ||
override val data: ChannelData = data | ||
override val kord = kord | ||
override val supplier = supplier | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalContracts::class) | ||
suspend inline fun VoiceStageChannelBehavior.editCurrentVoiceState(builder: CurrentVoiceStateModifyBuilder.() -> Unit) { | ||
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } | ||
kord.rest.guild.modifyCurrentVoiceState(guildId, id, builder) | ||
} | ||
|
||
@OptIn(ExperimentalContracts::class) | ||
suspend inline fun VoiceStageChannelBehavior.editVoiceState(userId: Snowflake, builder: VoiceStateModifyBuilder.() -> Unit) { | ||
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } | ||
kord.rest.guild.modifyVoiceState(guildId, userId, builder) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package dev.kord.core.entity.channel | ||
|
||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.common.entity.optional.getOrThrow | ||
import dev.kord.core.Kord | ||
import dev.kord.core.behavior.VoiceStageChannelBehavior | ||
import dev.kord.core.cache.data.ChannelData | ||
import dev.kord.core.supplier.EntitySupplier | ||
import dev.kord.core.supplier.EntitySupplyStrategy | ||
|
||
class VoiceStageChannel( | ||
override val data: ChannelData, | ||
override val kord: Kord, | ||
override val supplier: EntitySupplier = kord.defaultSupplier | ||
) : VoiceStageChannelBehavior { | ||
|
||
override val id: Snowflake get() = data.id | ||
|
||
override val guildId: Snowflake get() = data.guildId.value!! | ||
override fun withStrategy(strategy: EntitySupplyStrategy<*>): VoiceStageChannelBehavior { | ||
return VoiceStageChannelBehavior(data, kord, strategy.supply(kord)) | ||
} | ||
|
||
|
||
/** | ||
* The bitrate (in bits) of this channel. | ||
*/ | ||
val bitrate: Int get() = data.bitrate.getOrThrow() | ||
|
||
/** | ||
* The user limit of the voice channel. | ||
*/ | ||
val userLimit: Int get() = data.userLimit.getOrThrow() | ||
|
||
val topic: String get() = data.topic.value!! | ||
} |
38 changes: 38 additions & 0 deletions
38
rest/src/main/kotlin/builder/guild/VoiceStatePatchBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package dev.kord.rest.builder.guild | ||
|
||
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.delegate.delegate | ||
import dev.kord.rest.builder.RequestBuilder | ||
import dev.kord.rest.json.request.CurrentVoiceStateModifyRequest | ||
import dev.kord.rest.json.request.VoiceStateModifyRequest | ||
|
||
class CurrentVoiceStateModifyBuilder(val channelId: Snowflake) : RequestBuilder<CurrentVoiceStateModifyRequest> { | ||
|
||
private var _requestToSpeakTimestamp: Optional<String> = Optional.Missing() | ||
|
||
private var _suppress: OptionalBoolean = OptionalBoolean.Missing | ||
|
||
var requestToSpeakTimestamp: String? by ::_requestToSpeakTimestamp.delegate() | ||
|
||
var suppress: Boolean? by ::_suppress.delegate() | ||
|
||
|
||
override fun toRequest(): CurrentVoiceStateModifyRequest { | ||
return CurrentVoiceStateModifyRequest(channelId, _suppress, _requestToSpeakTimestamp) | ||
} | ||
} | ||
|
||
|
||
class VoiceStateModifyBuilder(val channelId: Snowflake) : RequestBuilder<VoiceStateModifyRequest> { | ||
|
||
private var _suppress: OptionalBoolean = OptionalBoolean.Missing | ||
|
||
var suppress: Boolean? by ::_suppress.delegate() | ||
|
||
override fun toRequest(): VoiceStateModifyRequest { | ||
return VoiceStateModifyRequest(channelId, _suppress) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dev.kord.rest.json.request | ||
|
||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.common.entity.optional.Optional | ||
import dev.kord.common.entity.optional.OptionalBoolean | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class CurrentVoiceStateModifyRequest( | ||
@SerialName("channel_id") | ||
val channelId: Snowflake, | ||
val suppress: OptionalBoolean = OptionalBoolean.Missing, | ||
@SerialName("request_to_speak_timestamp") | ||
val requestToSpeakTimeStamp: Optional<String> = Optional.Missing() | ||
) | ||
|
||
|
||
@Serializable | ||
data class VoiceStateModifyRequest( | ||
@SerialName("channel_id") | ||
val channelId: Snowflake, | ||
val suppress: OptionalBoolean = OptionalBoolean.Missing | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters