From 37a4e0059478525c22a4ac6412f66b69c5720b9a Mon Sep 17 00:00:00 2001 From: BartArys Date: Thu, 20 Aug 2020 16:50:11 +0200 Subject: [PATCH] Save voice state under proper guild id --- CHANGELOG.md | 1 + .../main/kotlin/com/gitlab/kordlib/core/cache/data/GuildData.kt | 2 +- .../kotlin/com/gitlab/kordlib/core/cache/data/VoiceStateData.kt | 2 +- .../gitlab/kordlib/core/gateway/handler/GuildEventHandler.kt | 2 +- .../gitlab/kordlib/core/gateway/handler/VoiceEventHandler.kt | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcd22babc28..d9d1040a7b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Fixed an issue where Invite events would not fire if the invited user didn't have an avatar. * Fixed some outdated docs on the `KordBuilder`. +* Fixed an issue where voice states from guild creates were not getting cached. ## Additions diff --git a/core/src/main/kotlin/com/gitlab/kordlib/core/cache/data/GuildData.kt b/core/src/main/kotlin/com/gitlab/kordlib/core/cache/data/GuildData.kt index b662326916b..d3959e090c7 100644 --- a/core/src/main/kotlin/com/gitlab/kordlib/core/cache/data/GuildData.kt +++ b/core/src/main/kotlin/com/gitlab/kordlib/core/cache/data/GuildData.kt @@ -100,7 +100,7 @@ data class GuildData( joinedAt, large, memberCount, - voiceStates.orEmpty().map { VoiceStateData.from(it) }, + voiceStates.orEmpty().map { VoiceStateData.from(id, it) }, members.orEmpty().map { MemberData.from(userId = it.user!!.id, guildId = id, entity = it) }, channels.orEmpty().map { it.id.toLong() }, presences.orEmpty().map { PresenceData.from(id, it) }, diff --git a/core/src/main/kotlin/com/gitlab/kordlib/core/cache/data/VoiceStateData.kt b/core/src/main/kotlin/com/gitlab/kordlib/core/cache/data/VoiceStateData.kt index d420c80827f..50b2538ed03 100644 --- a/core/src/main/kotlin/com/gitlab/kordlib/core/cache/data/VoiceStateData.kt +++ b/core/src/main/kotlin/com/gitlab/kordlib/core/cache/data/VoiceStateData.kt @@ -23,7 +23,7 @@ data class VoiceStateData( companion object { val description = description(VoiceStateData::id) - fun from(entity: DiscordVoiceState) = with(entity) { + fun from(guildId: String?, entity: DiscordVoiceState) = with(entity) { VoiceStateData( guildId?.toLong(), channelId?.toLong(), diff --git a/core/src/main/kotlin/com/gitlab/kordlib/core/gateway/handler/GuildEventHandler.kt b/core/src/main/kotlin/com/gitlab/kordlib/core/gateway/handler/GuildEventHandler.kt index 839da2d1e80..1219fe9e566 100644 --- a/core/src/main/kotlin/com/gitlab/kordlib/core/gateway/handler/GuildEventHandler.kt +++ b/core/src/main/kotlin/com/gitlab/kordlib/core/gateway/handler/GuildEventHandler.kt @@ -73,7 +73,7 @@ internal class GuildEventHandler( } for (voiceState in voiceStates.orEmpty()) { - cache.put(VoiceStateData.from(voiceState)) + cache.put(VoiceStateData.from(id, voiceState)) } for (emoji in emojis) { cache.put(EmojiData.from(id, emoji.id!!, emoji)) diff --git a/core/src/main/kotlin/com/gitlab/kordlib/core/gateway/handler/VoiceEventHandler.kt b/core/src/main/kotlin/com/gitlab/kordlib/core/gateway/handler/VoiceEventHandler.kt index 737712c6101..40e22a46f82 100644 --- a/core/src/main/kotlin/com/gitlab/kordlib/core/gateway/handler/VoiceEventHandler.kt +++ b/core/src/main/kotlin/com/gitlab/kordlib/core/gateway/handler/VoiceEventHandler.kt @@ -34,7 +34,7 @@ internal class VoiceEventHandler( } private suspend fun handle(event: VoiceStateUpdate, shard: Int) { - val data = VoiceStateData.from(event.voiceState) + val data = VoiceStateData.from(event.voiceState.guildId, event.voiceState) val old = cache.query { VoiceStateData::id eq data.id } .asFlow().map { VoiceState(it, kord) }.singleOrNull()