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

Fix some cache links #934

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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,9 +8,11 @@ import dev.kord.common.serialization.DurationInSeconds
import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable

private val ApplicationCommandData.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 @@ -71,14 +73,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)
}

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)
}
}
}
}
4 changes: 2 additions & 2 deletions core/src/commonMain/kotlin/cache/data/UserData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.OptionalBoolean
import kotlinx.serialization.Serializable

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

@Serializable
public data class UserData(
Expand All @@ -29,7 +29,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)
}
Expand Down