Skip to content

Commit

Permalink
Fix voice moves causing invalid session if done in quick succession
Browse files Browse the repository at this point in the history
  • Loading branch information
quanticc committed Aug 16, 2023
1 parent d8bae24 commit 884a981
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,22 @@ default Function<VoiceChannel, Mono<VoiceConnection>> asRequest() {

final VoiceDisconnectTask disconnectTask = id -> voiceChannel.sendDisconnectVoiceState()
.then(gateway.getVoiceConnectionRegistry().disconnect(id));
//noinspection ConstantConditions
final VoiceServerUpdateTask serverUpdateTask = id -> onVoiceServerUpdate(gateway, id)
.map(vsu -> new VoiceServerOptions(vsu.getToken(), vsu.getEndpoint()));
final VoiceServerUpdateTask serverUpdateTask = new VoiceServerUpdateTask() {

@Override
public Flux<VoiceServerOptions> onVoiceServerUpdates(Snowflake guildId) {
//noinspection DataFlowIssue
return gateway.getEventDispatcher()
.on(VoiceServerUpdateEvent.class)
.filter(vsu -> vsu.getGuildId().equals(guildId) && vsu.getEndpoint() != null)
.map(vsu -> new VoiceServerOptions(vsu.getToken(), vsu.getEndpoint()));
}

@Override
public Mono<VoiceServerOptions> onVoiceServerUpdate(Snowflake guildId) {
return onVoiceServerUpdates(guildId).next();
}
};
final VoiceStateUpdateTask stateUpdateTask = id -> onVoiceStateUpdates(gateway, id)
.map(stateUpdateEvent -> stateUpdateEvent.getCurrent().getSessionId());
final VoiceChannelRetrieveTask channelRetrieveTask = () -> gateway
Expand Down Expand Up @@ -218,4 +231,4 @@ public void subscribe(CoreSubscriber<? super VoiceConnection> actual) {

@Override
public abstract String toString();
}
}

0 comments on commit 884a981

Please sign in to comment.