Skip to content

Commit

Permalink
Save voice state under proper guild id
Browse files Browse the repository at this point in the history
  • Loading branch information
BartArys committed Aug 20, 2020
1 parent 4803b88 commit 37a4e00
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> { VoiceStateData::id eq data.id }
.asFlow().map { VoiceState(it, kord) }.singleOrNull()
Expand Down

0 comments on commit 37a4e00

Please sign in to comment.