fix: delete broken local JDAVoiceUpdateListener, use library version with proper voice state handling
This commit is contained in:
parent
0918bb5c38
commit
328845aa75
2 changed files with 3 additions and 55 deletions
|
|
@ -97,6 +97,9 @@ public class RadioManager {
|
||||||
"Radio: bot has CONNECT permission: {}",
|
"Radio: bot has CONNECT permission: {}",
|
||||||
self.hasPermission(vc, net.dv8tion.jda.api.Permission.VOICE_CONNECT));
|
self.hasPermission(vc, net.dv8tion.jda.api.Permission.VOICE_CONNECT));
|
||||||
guild.getJDA().getDirectAudioController().connect(vc);
|
guild.getJDA().getDirectAudioController().connect(vc);
|
||||||
|
if (!guild.getAudioManager().isConnected()) {
|
||||||
|
guild.getAudioManager().openAudioConnection(vc);
|
||||||
|
}
|
||||||
if (!VoiceHelper.waitForCondition(
|
if (!VoiceHelper.waitForCondition(
|
||||||
() -> self.getVoiceState().inAudioChannel(), VOICE_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
|
() -> self.getVoiceState().inAudioChannel(), VOICE_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
|
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
package dev.arbjerg.lavalink.libraries.jda;
|
|
||||||
|
|
||||||
import dev.arbjerg.lavalink.client.LavalinkClient;
|
|
||||||
import dev.arbjerg.lavalink.client.loadbalancing.VoiceRegion;
|
|
||||||
import dev.arbjerg.lavalink.protocol.v4.VoiceState;
|
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
|
|
||||||
import net.dv8tion.jda.api.hooks.VoiceDispatchInterceptor;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class JDAVoiceUpdateListener implements VoiceDispatchInterceptor {
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger("JDAVoiceUpdateListener");
|
|
||||||
private final LavalinkClient lavalink;
|
|
||||||
|
|
||||||
public JDAVoiceUpdateListener(LavalinkClient lavalink) {
|
|
||||||
this.lavalink = lavalink;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onVoiceServerUpdate(@NotNull VoiceServerUpdate update) {
|
|
||||||
String token = update.getToken();
|
|
||||||
String endpoint = update.getEndpoint();
|
|
||||||
String sessionId = update.getSessionId();
|
|
||||||
Guild guild = update.getGuild();
|
|
||||||
|
|
||||||
Member selfMember = guild.getMember(guild.getJDA().getSelfUser());
|
|
||||||
if (selfMember == null) {
|
|
||||||
logger.warn("onVoiceServerUpdate: selfMember is null for guild {}", update.getGuildIdLong());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioChannel channel = selfMember.getVoiceState().getChannel();
|
|
||||||
String channelId = channel != null ? String.valueOf(channel.getId()) : null;
|
|
||||||
logger.info(
|
|
||||||
"onVoiceServerUpdate: guild={} endpoint={} channelId={} sessionId={}",
|
|
||||||
update.getGuildIdLong(), endpoint, channelId, sessionId);
|
|
||||||
|
|
||||||
VoiceState state = new VoiceState(token, endpoint, sessionId, channelId);
|
|
||||||
VoiceRegion region = VoiceRegion.Companion.fromEndpoint(endpoint);
|
|
||||||
lavalink.getOrCreateLink(update.getGuildIdLong(), region).onVoiceServerUpdate(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onVoiceStateUpdate(@NotNull VoiceStateUpdate update) {
|
|
||||||
Long channelId = update.getChannel() != null ? update.getChannel().getIdLong() : null;
|
|
||||||
logger.info(
|
|
||||||
"onVoiceStateUpdate: guild={} channelId={}",
|
|
||||||
update.getGuildIdLong(), channelId);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue