Gateway: Fix repeat joins on same channel from stalling (#47)

Joining a channel returns a future which fires on receipt of two messages from discord (by locally storing a channel). However, joining this same channel again after a success returns only *one* such message, causing the command to hang until another join fires or the channel is left. This alters internal behaviour to correctly cancel an in-progress connection attempt, or return success with known data if such a connection is present.

This introduces a breaking change on `Call::update_state` to include the target `ChannelId`. The reason for this is that although the `ChannelId` of a target channel was being stored, server admins may move or kick a bot from its voice channel. This changes the true channel, and may accidentally trigger a "double join" elsewhere.

This fix was tested by using an example to have a bot join its channel twice, to do so in a channel it had been moved to, and to move from a channel it had been moved to.
This commit is contained in:
Kyle Simpson
2021-03-23 10:36:23 +00:00
parent ebff98e873
commit e59c546503
3 changed files with 152 additions and 35 deletions

View File

@@ -351,7 +351,10 @@ impl Songbird {
if let Some(call) = call {
let mut handler = call.lock().await;
handler.update_state(v.0.session_id.clone());
handler.update_state(
v.0.session_id.clone(),
v.0.channel_id.clone().map(Into::into),
);
}
},
_ => {},
@@ -390,7 +393,10 @@ impl VoiceGatewayManager for Songbird {
if let Some(call) = self.get(guild_id) {
let mut handler = call.lock().await;
handler.update_state(voice_state.session_id.clone());
handler.update_state(
voice_state.session_id.clone(),
voice_state.channel_id.clone().map(Into::into),
);
}
}
}