Skip to content

Commit

Permalink
Add previous value to GuildUpdateEvent (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
BartArys authored Sep 23, 2021
1 parent 75bd98a commit a059a59
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/kotlin/event/guild/GuildUpdateEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dev.kord.core.Kord
import dev.kord.core.entity.Guild
import dev.kord.core.event.Event

class GuildUpdateEvent(val guild: Guild, override val shard: Int) : Event {
class GuildUpdateEvent(val guild: Guild, val old: Guild?, override val shard: Int) : Event {
override val kord: Kord get() = guild.kord
override fun toString(): String {
return "GuildUpdateEvent(guild=$guild, shard=$shard)"
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/kotlin/gateway/handler/GuildEventHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ internal class GuildEventHandler(

private suspend fun handle(event: GuildUpdate, shard: Int) {
val data = GuildData.from(event.guild)
val old = cache.query<GuildData> { idEq(GuildData::id, event.guild.id) }.singleOrNull()
cache.put(data)
event.guild.cache()

coreFlow.emit(GuildUpdateEvent(Guild(data, kord), shard))
coreFlow.emit(GuildUpdateEvent(Guild(data, kord), old?.let { Guild(it, kord) }, shard))
}

private suspend fun handle(event: GuildDelete, shard: Int) = with(event.guild) {
Expand Down

0 comments on commit a059a59

Please sign in to comment.