Skip to content

Commit 87fa081

Browse files
committed
hotfix(DynamicVoiceChat): delay deleting channelLeft on history fetch
By letting the JDA asynchornously retrieve the voice channel history and figure out if we are going to delete the channel in question without making sure one finishes before the other gets executed, we receive this: RestAction queue returned failure: [ErrorResponseException] 10003: Unknown Channel net.dv8tion.jda.api.exceptions.ContextException at net.dv8tion.jda.api.exceptions.ContextException.here(ContextException.java:54) at net.dv8tion.jda.api.requests.Request.<init>(Request.java:78) at net.dv8tion.jda.internal.requests.RestActionImpl.queue(RestActionImpl.java:203) at net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:577) at org.togetherjava.tjbot.features.voicechat.DynamicVoiceChat.handleVoiceChannelLeave(DynamicVoiceChat.java:84) at org.togetherjava.tjbot.features.voicechat.DynamicVoiceChat.onVoiceUpdate(DynamicVoiceChat.java:68) at org.togetherjava.tjbot.features.system.BotCore.lambda$onGuildVoiceUpdate$1(BotCore.java:306) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:186) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214) Delay deleting `channelLeft` channel by 500ms and use `RestAction#onSuccess` to make sure that the channel history request is done _first_ and completely, before we move on to deleting the channel. Signed-off-by: Chris Sdogkos <work@chris-sdogkos.com>
1 parent 0309044 commit 87fa081

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

application/src/main/java/org/togetherjava/tjbot/features/voicechat/DynamicVoiceChat.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.togetherjava.tjbot.features.VoiceReceiverAdapter;
2121

2222
import java.util.Optional;
23+
import java.util.concurrent.TimeUnit;
2324

2425
/**
2526
* Handles dynamic voice channel creation and deletion based on user activity.
@@ -30,6 +31,7 @@
3031
*/
3132
public final class DynamicVoiceChat extends VoiceReceiverAdapter {
3233
private static final Logger logger = LoggerFactory.getLogger(DynamicVoiceChat.class);
34+
private static final long DELETE_VOICE_CHANNEL_ACTION_DELAY_MS = 500L;
3335

3436
private final VoiceChatCleanupStrategy voiceChatCleanupStrategy;
3537
private final DynamicVoiceChatConfig dynamicVoiceChannelConfig;
@@ -87,13 +89,14 @@ private void handleVoiceChannelLeave(AudioChannelUnion channelLeft) {
8789
return;
8890
}
8991

90-
channelLeft.asVoiceChannel().getHistory().retrievePast(2).queue(messages -> {
92+
channelLeft.asVoiceChannel().getHistory().retrievePast(2).onSuccess(messages -> {
9193
if (messages.size() > 1) {
9294
archiveDynamicVoiceChannel(channelLeft);
9395
} else {
94-
channelLeft.delete().queue();
96+
channelLeft.delete()
97+
.queueAfter(DELETE_VOICE_CHANNEL_ACTION_DELAY_MS, TimeUnit.MILLISECONDS);
9598
}
96-
});
99+
}).queue();
97100
}
98101
}
99102

0 commit comments

Comments
 (0)