Skip to content

Commit

Permalink
Improve voice state event selection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuente committed Sep 25, 2024
1 parent 71cd4c8 commit 9f601cc
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions handlers/voice_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,25 @@ func gatewayHandlerVoiceStateUpdate(client bot.Client, sequenceNumber int, shard
OldVoiceState: oldVoiceState,
})

if oldOk && oldVoiceState.ChannelID != nil && event.ChannelID != nil {
leave := oldOk && oldVoiceState.ChannelID != nil
join := event.ChannelID != nil

switch {
case leave && join:
client.EventManager().DispatchEvent(&events.GuildVoiceMove{
GenericGuildVoiceState: genericGuildVoiceEvent,
OldVoiceState: oldVoiceState,
})
} else if (oldOk || oldVoiceState.ChannelID == nil) && event.ChannelID != nil {
client.EventManager().DispatchEvent(&events.GuildVoiceJoin{
GenericGuildVoiceState: genericGuildVoiceEvent,
})
} else if event.ChannelID == nil {
case leave:
client.EventManager().DispatchEvent(&events.GuildVoiceLeave{
GenericGuildVoiceState: genericGuildVoiceEvent,
OldVoiceState: oldVoiceState,
})
} else {
case join:
client.EventManager().DispatchEvent(&events.GuildVoiceJoin{
GenericGuildVoiceState: genericGuildVoiceEvent,
})
default:
client.Logger().Warn("could not decide which GuildVoice to fire")
}
}
Expand Down

0 comments on commit 9f601cc

Please sign in to comment.