Skip to content

Commit

Permalink
merge: main -> feat/entitlements
Browse files Browse the repository at this point in the history
  • Loading branch information
viztea committed Apr 12, 2024
2 parents 0a96289 + 4180ad0 commit 3f9b1ff
Show file tree
Hide file tree
Showing 23 changed files with 35 additions and 322 deletions.
8 changes: 6 additions & 2 deletions core/src/commonMain/kotlin/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import kotlin.contracts.contract
import kotlin.reflect.KClass

internal inline fun <T> catchNotFound(block: () -> T): T? {
// block is called exactly once, but might not be executed fully, even if catchNotFound returns normally
// -> AT_MOST_ONCE, see https://youtrack.jetbrains.com/issue/KT-63414
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}
return try {
block()
Expand All @@ -41,8 +43,10 @@ internal inline fun <T> catchNotFound(block: () -> T): T? {
}

internal inline fun <T> catchDiscordError(vararg codes: JsonErrorCode, block: () -> T): T? {
// block is called exactly once, but might not be executed fully, even if catchDiscordError returns normally
// -> AT_MOST_ONCE, see https://youtrack.jetbrains.com/issue/KT-63414
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}
return try {
block()
Expand Down
3 changes: 0 additions & 3 deletions core/src/commonMain/kotlin/builder/kord/KordBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.serialization.json.Json
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

private val gatewayInfoJson = Json { ignoreUnknownKeys = true }

Expand Down Expand Up @@ -169,7 +167,6 @@ public abstract class BaseKordBuilder internal constructor(public val token: Str
* ```
*/
public fun cache(builder: KordCacheBuilder.(resources: ClientResources) -> Unit) {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
val old = cacheBuilder
cacheBuilder = { resources: ClientResources ->
old(resources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public data class ApplicationCommandData(
val version: Snowflake
) {
public companion object {
public val description: DataDescription<ApplicationCommandData, Snowflake> = description(ApplicationCommandData::id) {
link(ApplicationCommandData::guildId to GuildData::id)
}
public val description: DataDescription<ApplicationCommandData, Snowflake> =
description(ApplicationCommandData::id) {
link(ApplicationCommandData::id to GuildApplicationCommandPermissionsData::id)
}

public fun from(command: DiscordApplicationCommand): ApplicationCommandData {
return with(command) {
ApplicationCommandData(
Expand Down
7 changes: 6 additions & 1 deletion core/src/commonMain/kotlin/cache/data/ChannelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ public data class ChannelData(


public companion object {
public val description: DataDescription<ChannelData, Snowflake> = description(ChannelData::id)
public val description: DataDescription<ChannelData, Snowflake> = description(ChannelData::id) {
link(ChannelData::id to MessageData::channelId)
link(ChannelData::id to ThreadMemberData::id)
link(ChannelData::id to WebhookData::channelId)
link(ChannelData::id to VoiceStateData::channelId)
}

public fun from(entity: DiscordChannel): ChannelData = with(entity) {
ChannelData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ public data class GuildApplicationCommandPermissionsData(

public companion object {
public val description: DataDescription<GuildApplicationCommandPermissionsData, Snowflake> =
description(GuildApplicationCommandPermissionsData::id) {
link(GuildApplicationCommandPermissionsData::guildId to GuildData::id)
link(GuildApplicationCommandPermissionsData::id to ApplicationCommandData::id)
}
description(GuildApplicationCommandPermissionsData::id)

public fun from(permissions: DiscordGuildApplicationCommandPermissions): GuildApplicationCommandPermissionsData =
with(permissions) {
Expand Down
7 changes: 6 additions & 1 deletion core/src/commonMain/kotlin/cache/data/GuildData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import dev.kord.common.serialization.DurationInSeconds
import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable

private val ApplicationCommandData.nullableGuildId get() = guildId.value
private val EntitlementData.nullableGuildId get() = guildId.value
private val MessageData.nullableGuildId get() = guildId.value
private val ChannelData.nullableGuildId get() = guildId.value
private val WebhookData.nullableGuildId get() = guildId.value
private val StickerData.nullableGuildId get() = guildId.value

@Serializable
public data class GuildData(
Expand Down Expand Up @@ -72,14 +74,17 @@ public data class GuildData(
public companion object {

public val description: DataDescription<GuildData, Snowflake> = description(GuildData::id) {

link(GuildData::id to ApplicationCommandData::nullableGuildId)
link(GuildData::id to GuildApplicationCommandPermissionsData::guildId)
link(GuildData::id to RoleData::guildId)
link(GuildData::id to ChannelData::nullableGuildId)
link(GuildData::id to MemberData::guildId)
link(GuildData::id to MessageData::nullableGuildId)
link(GuildData::id to WebhookData::nullableGuildId)
link(GuildData::id to VoiceStateData::guildId)
link(GuildData::id to PresenceData::guildId)
link(GuildData::id to StickerData::nullableGuildId)
link(GuildData::id to EmojiData::guildId)
link(GuildData::id to AutoModerationRuleData::guildId)
link(GuildData::id to EntitlementData::nullableGuildId)

Expand Down
15 changes: 7 additions & 8 deletions core/src/commonMain/kotlin/cache/data/StickerData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ public data class StickerData(
) {
public companion object {

public val description: DataDescription<StickerData, Snowflake> = description(StickerData::id) {
link(StickerData::guildId to GuildData::id)
link(StickerData::packId to StickerPackData::id)
}

public val description: DataDescription<StickerData, Snowflake> = description(StickerData::id)

public fun from(entity: DiscordMessageSticker): StickerData = with(entity) {
StickerData(id, packId, name, description, tags, formatType, available, guildId, user.map { it.toData() }, sortValue)
Expand All @@ -49,6 +45,7 @@ public data class StickerItemData(
}
}

private val StickerData.nullablePackId get() = packId.value

public data class StickerPackData(
val id: Snowflake,
Expand All @@ -58,13 +55,15 @@ public data class StickerPackData(
val coverStickerId: OptionalSnowflake = OptionalSnowflake.Missing,
val description: String,
val bannerAssetId: Snowflake
) {
) {
public companion object {

public val description: DataDescription<StickerPackData, Snowflake> = description(StickerPackData::id)
public val description: DataDescription<StickerPackData, Snowflake> = description(StickerPackData::id) {
link(StickerPackData::id to StickerData::nullablePackId)
}

public fun from(entity: DiscordStickerPack): StickerPackData = with(entity) {
StickerPackData(id, stickers.map { StickerData.from(it) }, name, skuId, coverStickerId, description, bannerAssetId)
}
}
}
}
5 changes: 3 additions & 2 deletions core/src/commonMain/kotlin/cache/data/UserData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import dev.kord.common.entity.optional.OptionalBoolean
import kotlinx.serialization.Serializable

private val EntitlementData.nullableUserId get() = userId.value
private val WebhookData.nullableUserId get() = userId.value
private val ThreadMemberData.nullableUserId get() = userId.value

@Serializable
public data class UserData(
Expand All @@ -30,7 +30,7 @@ public data class UserData(

public val description: DataDescription<UserData, Snowflake> = description(UserData::id) {
link(UserData::id to MemberData::userId)
link(UserData::id to WebhookData::nullableUserId)
link(UserData::id to ThreadMemberData::nullableUserId)
link(UserData::id to VoiceStateData::userId)
link(UserData::id to PresenceData::userId)
link(UserData::id to EntitlementData::nullableUserId)
Expand All @@ -48,3 +48,4 @@ public data class UserData(
}

public fun DiscordUser.toData(): UserData = UserData.from(this)

Binary file removed core/src/jvmTest/resources/images/gitlab.png
Binary file not shown.
48 changes: 0 additions & 48 deletions core/src/jvmTest/resources/interaction/groupsubcommand.json

This file was deleted.

38 changes: 0 additions & 38 deletions core/src/jvmTest/resources/interaction/rootcommand.json

This file was deleted.

43 changes: 0 additions & 43 deletions core/src/jvmTest/resources/interaction/subcommand.json

This file was deleted.

18 changes: 0 additions & 18 deletions gateway/src/commonTest/resources/json/event/guildbanadd.json

This file was deleted.

18 changes: 0 additions & 18 deletions gateway/src/commonTest/resources/json/event/guildbanremove.json

This file was deleted.

30 changes: 0 additions & 30 deletions gateway/src/commonTest/resources/json/event/guildcreate.json

This file was deleted.

9 changes: 0 additions & 9 deletions gateway/src/commonTest/resources/json/event/guilddelete.json

This file was deleted.

Loading

0 comments on commit 3f9b1ff

Please sign in to comment.