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

Changes of latest docs commits #561

Merged
merged 8 commits into from
Mar 11, 2022
14 changes: 8 additions & 6 deletions common/src/main/kotlin/entity/DiscordGuild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 kotlinx.datetime.Instant
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -364,23 +365,24 @@ public data class DiscordWebhooksUpdateData(
* A representation of the [Discord Voice State structure](https://discord.com/developers/docs/resources/voice#voice-state-object).
* Used to represent a user's voice connection status.
*
* @param guildId the guild id this voice state is for.
* @param channelId the channel id this user is connection to.
* @param guildId The guild id this voice state is for.
* @param channelId The channel id this user is connected to.
* @param userId The user id this voice state is for.
* @param member the guild member this voice state is for.
* @param member The guild member this voice state is for.
* @param sessionId The session id for this voice state.
* @param deaf Whether this user is deafened by the server.
* @param mute Whether this user is muted by the server.
* @param selfDeaf Whether this user is locally deafened.
* @param selfMute Whether this is locally muted
* @param selfMute Whether this user is locally muted.
* @param selfStream Whether this user is stream using "Go Live".
* @param selfVideo Whether this user's camera is enabled.
* @param suppress Whether this user is muted by the current user.
* @param requestToSpeakTimestamp The time at which the user requested to speak.
*/
@Serializable
public data class DiscordVoiceState(
@SerialName("guild_id") val guildId: OptionalSnowflake = OptionalSnowflake.Missing,
@SerialName("channel_id") val channelId: Snowflake?,
@SerialName("channel_id") val channelId: OptionalSnowflake = OptionalSnowflake.Missing,
@SerialName("user_id") val userId: Snowflake,
@SerialName("guild_member") val member: Optional<DiscordGuildMember> = Optional.Missing(),
@SerialName("session_id") val sessionId: String,
Expand All @@ -391,7 +393,7 @@ public data class DiscordVoiceState(
@SerialName("self_video") val selfVideo: Boolean,
@SerialName("self_stream") val selfStream: OptionalBoolean = OptionalBoolean.Missing,
val suppress: Boolean,
@SerialName("request_to_speak_timestamp") val requestToSpeakTimestamp: String?
@SerialName("request_to_speak_timestamp") val requestToSpeakTimestamp: Optional<Instant> = Optional.Missing(),
)

/**
Expand Down
37 changes: 21 additions & 16 deletions common/src/main/kotlin/entity/DiscordGuildScheduledEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,27 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

/**
* Representation of a [Guild Scheduled Event Structure](ADD LINK).
* Representation of a
* [Guild Scheduled Event Structure](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-structure).
*
* @property id the id of the event
* @property guildId the id of the guild the event is on
* @property channelId the id of the channel the event is in
* @property creatorId the id of the user that created the scheduled event
* @property name the name of the event
* @property description the description of the event
* @property scheduledStartTime the [Instant] in which the event will start
* @property scheduledEndTime the [Instant] in which the event wil stop, if any
* @property privacyLevel the [event privacy level][GuildScheduledEventPrivacyLevel]
* @property status the [event status][GuildScheduledEventStatus]
* @property entityType the [ScheduledEntityType] of the event
* @property entityId entity id
* @property entityMetadata [metadata][GuildScheduledEventEntityMetadata] for the event
* @property creator the [user][DiscordUser] that created the scheduled event
* @property userCount users subscribed to the event
* @property id The id of the scheduled event.
* @property guildId The guild id which the scheduled event belongs to.
* @property channelId The channel id in which the scheduled event will be hosted, or `null` if [entityType] is
* [External][ScheduledEntityType.External].
* @property creatorId The id of the user that created the scheduled event.
* @property name The name of the scheduled event.
* @property description The description of the scheduled event.
* @property scheduledStartTime The [Instant] in which the scheduled event will start.
* @property scheduledEndTime The [Instant] in which the scheduled event will end, if any.
* @property privacyLevel The [privacy level][GuildScheduledEventPrivacyLevel] of the scheduled event.
* @property status The [status][GuildScheduledEventStatus] of the scheduled event.
* @property entityType The [type][ScheduledEntityType] of the scheduled event.
* @property entityId The id of an entity associated with a guild scheduled event.
* @property entityMetadata Additional [metadata][GuildScheduledEventEntityMetadata] for the guild scheduled event.
* @property creator The [user][DiscordUser] that created the scheduled event.
* @property userCount The number of users subscribed to the scheduled event.
* @property image The [cover image hash](https://discord.com/developers/docs/reference#image-formatting) of the
* scheduled event.
*/
@Serializable
public data class DiscordGuildScheduledEvent(
Expand Down Expand Up @@ -59,6 +63,7 @@ public data class DiscordGuildScheduledEvent(
val creator: Optional<DiscordUser> = Optional.Missing(),
@SerialName("user_count")
val userCount: OptionalInt = OptionalInt.Missing,
val image: Optional<String?> = Optional.Missing(),
)

/** Privacy level of a [DiscordGuildScheduledEvent]. */
Expand Down
20 changes: 12 additions & 8 deletions common/src/main/kotlin/entity/DiscordStageInstance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import kotlinx.serialization.encoding.Encoder


/**
* A _Stage Instance_ holds information about a live stage.
* A [_Stage Instance_](https://discord.com/developers/docs/resources/stage-instance) holds information about a live
* stage.
*
* @property id The id of this Stage instance
* @property guildId The guild id of the associated Stage channel
* @property channelId The id of the associated Stage channel
* @property topic The topic of the Stage instance (1-120 characters)
* @property privacyLevel The [privacy level][StageInstancePrivacyLevel] of the Stage instance
* @property discoverableDisabled Whether or not Stage Discovery is disabled
* @property id The id of this Stage instance.
* @property guildId The guild id of the associated Stage channel.
* @property channelId The id of the associated Stage channel.
* @property topic The topic of the Stage instance.
* @property privacyLevel The [privacy level][StageInstancePrivacyLevel] of the Stage instance.
* @property discoverableDisabled Whether or not Stage Discovery is disabled.
* @property guildScheduledEventId The id of the scheduled event for this Stage instance.
*/
@Serializable
public data class DiscordStageInstance(
Expand All @@ -32,7 +34,9 @@ public data class DiscordStageInstance(
val privacyLevel: StageInstancePrivacyLevel,
@Deprecated("Stages are no longer discoverable")
@SerialName("discoverable_disabled")
val discoverableDisabled: Boolean
val discoverableDisabled: Boolean,
@SerialName("guild_scheduled_event_id")
val guildScheduledEventId: Snowflake?,
)

/**
Expand Down
9 changes: 5 additions & 4 deletions common/src/test/kotlin/json/VoiceStateTest.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
package json

import dev.kord.common.entity.DiscordVoiceState
import kotlinx.datetime.Instant
import kotlinx.serialization.json.Json
import org.junit.jupiter.api.Test
import kotlin.test.Ignore

private fun file(name: String): String {
val loader = ChannelTest::class.java.classLoader
return loader.getResource("json/voice/$name.json").readText()
return loader.getResource("json/voice/$name.json")!!.readText()
}

class VoiceStateTest {

@Test
@Ignore("official documentation example is incorrect")
fun `VoiceState serialization`() {
val state = Json.decodeFromString(DiscordVoiceState.serializer(), file("voicestate"))

with(state) {
channelId!!.toString() shouldBe "157733188964188161"
channelId.value.toString() shouldBe "157733188964188161"
userId.toString() shouldBe "80351110224678912"
sessionId shouldBe "90326bd25d71d39b9ef95b299e3872ff"
deaf shouldBe false
mute shouldBe false
selfDeaf shouldBe false
selfVideo shouldBe true
selfMute shouldBe true
suppress shouldBe false
requestToSpeakTimestamp shouldBe Instant.parse("2021-03-31T18:45:31.297561+00:00")
}

}
Expand Down
4 changes: 3 additions & 1 deletion common/src/test/resources/json/voice/voicestate.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"deaf": false,
"mute": false,
"self_deaf": false,
"self_video": true,
"self_mute": true,
"suppress": false
"suppress": false,
"request_to_speak_timestamp": "2021-03-31T18:45:31.297561+00:00"
}
9 changes: 6 additions & 3 deletions core/src/main/kotlin/behavior/StageInstanceBehavior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import dev.kord.core.cache.data.StageInstanceData
import dev.kord.core.entity.KordEntity
import dev.kord.core.entity.StageInstance
import dev.kord.core.entity.Strategizable
import dev.kord.core.entity.channel.StageChannel
import dev.kord.core.exception.EntityNotFoundException
import dev.kord.core.supplier.EntitySupplier
import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.rest.json.request.StageInstanceUpdateRequest

public interface StageInstanceBehavior : KordEntity, Strategizable {

/** The id of the associated [StageChannel]. */
public val channelId: Snowflake

public suspend fun delete(reason: String? = null): Unit = kord.rest.stageInstance.deleteStageInstance(channelId, reason)
Expand All @@ -25,16 +28,16 @@ public interface StageInstanceBehavior : KordEntity, Strategizable {
}

/**
* Requests to get the this behavior as a [StageInstance] if it's not an instance of a [StageInstance].
* Requests to get this behavior as a [StageInstance] if it's not an instance of a [StageInstance].
*
* @throws [RequestException] if anything went wrong during the request.
* @throws [EntityNotFoundException] if the user wasn't present.
*/
public suspend fun asStageInstance(): StageInstance = supplier.getStageInstance(channelId)

/**
* Requests to get this behavior as a [StageInstance] if its not an instance of a [StageInstance],
* returns null if the user isn't present.
* Requests to get this behavior as a [StageInstance] if it's not an instance of a [StageInstance],
* returns null if the stage instance isn't present.
*
* @throws [RequestException] if anything went wrong during the request.
*/
Expand Down
38 changes: 21 additions & 17 deletions core/src/main/kotlin/cache/data/GuildScheduledEventData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,28 @@ public data class GuildScheduledEventData(
val entityMetadata: GuildScheduledEventEntityMetadata?,
val creator: Optional<UserData> = Optional.Missing(),
val userCount: OptionalInt = OptionalInt.Missing,
val image: Optional<String?> = Optional.Missing(),
) {
public companion object {
public fun from(event: DiscordGuildScheduledEvent): GuildScheduledEventData = GuildScheduledEventData(
event.id,
event.guildId,
event.channelId,
event.creatorId,
event.name,
event.description,
event.scheduledStartTime,
event.scheduledEndTime,
event.privacyLevel,
event.status,
event.entityId,
event.entityType,
event.entityMetadata,
event.creator.map { UserData.from(it) },
event.userCount
)
public fun from(event: DiscordGuildScheduledEvent): GuildScheduledEventData = with(event) {
GuildScheduledEventData(
id = id,
guildId = guildId,
channelId = channelId,
creatorId = creatorId,
name = name,
description = description,
scheduledStartTime = scheduledStartTime,
scheduledEndTime = scheduledEndTime,
privacyLevel = privacyLevel,
status = status,
entityId = entityId,
entityType = entityType,
entityMetadata = entityMetadata,
creator = creator.map { UserData.from(it) },
userCount = userCount,
image = image,
)
}
}
}
14 changes: 12 additions & 2 deletions core/src/main/kotlin/cache/data/StageInstanceData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@ package dev.kord.core.cache.data

import dev.kord.common.entity.DiscordStageInstance
import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.StageInstancePrivacyLevel
import kotlinx.serialization.Serializable

@Serializable
public data class StageInstanceData(
val id: Snowflake,
val guildId: Snowflake,
val channelId: Snowflake,
val topic: String
val topic: String,
val privacyLevel: StageInstancePrivacyLevel,
val guildScheduledEventId: Snowflake?,
) {
public companion object {
public fun from(stageInstance: DiscordStageInstance): StageInstanceData = with(stageInstance) {
StageInstanceData(id, guildId, channelId, topic)
StageInstanceData(
id = id,
guildId = guildId,
channelId = channelId,
topic = topic,
privacyLevel = privacyLevel,
guildScheduledEventId = guildScheduledEventId,
)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/kotlin/cache/data/VoiceStateData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import dev.kord.cache.api.data.DataDescription
import dev.kord.cache.api.data.description
import dev.kord.common.entity.DiscordVoiceState
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.OptionalSnowflake
import dev.kord.common.entity.optional.mapSnowflake
import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable

public val VoiceStateData.id: String
Expand All @@ -20,7 +22,7 @@ public data class VoiceStateData(
(And not just because this code would break).
*/
val guildId: Snowflake,
val channelId: Snowflake? = null,
val channelId: OptionalSnowflake = OptionalSnowflake.Missing,
val userId: Snowflake,
val memberId: OptionalSnowflake = OptionalSnowflake.Missing,
val sessionId: String,
Expand All @@ -31,7 +33,7 @@ public data class VoiceStateData(
val suppress: Boolean,
val selfVideo: Boolean,
val selfStream: OptionalBoolean = OptionalBoolean.Missing,
val requestToSpeakTimestamp: String?
val requestToSpeakTimestamp: Optional<Instant> = Optional.Missing(),
) {
public companion object {
public val description: DataDescription<VoiceStateData, String> = description(VoiceStateData::id)
Expand Down
Loading