refactor(MusicManager): load track before connecting to voice channel
This commit is contained in:
1 parent
5baa69ffe9
commit
8be0f94b3e
3 files changed
+28
-5
No files matched your search
@@ -157,11 +157,11 @@ public class MusicManager {
|
||||
SourceFinder.AudioSourceType type = SourceFinder.getSource(query);
|
||||
String identifier = SourceFinder.getIdentifier(query);
|
||||
if (identifier == null) {
|
||||
context.reply("No source found for provided query");
|
||||
context.reply("No source found to play the given url");
|
||||
return;
|
||||
}
|
||||
|
||||
if (MusicUtils.connect(context)) {
|
||||
if (MusicUtils.canConnect(context)) {
|
||||
TrackLoadingHandler loadingHandler = new TrackLoadingHandler(context, this, identifier, type, silent);
|
||||
playerManager.loadItemOrdered(this, identifier, loadingHandler);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||
import me.bobert.netneutrality.tasks.music.LoadPlaylistTask;
|
||||
import me.bobert.netneutrality.utils.MessageFunction;
|
||||
import me.bobert.netneutrality.utils.MusicUtils;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -43,10 +44,13 @@ public class TrackLoadingHandler implements AudioLoadResultHandler {
|
||||
context.deleteMessage();
|
||||
|
||||
logger.debug("Guild {}: track loaded: {}", guild.getId(), audioTrack.getIdentifier());
|
||||
scheduler.getQueueManager().queue(audioTrack, context.getGuildUser());
|
||||
|
||||
if (!silent) {
|
||||
context.reply(MessageFunction.buildAddingTrackMessage(audioTrack, context.getGuildUser(), type));
|
||||
if (MusicUtils.connect(context)) {
|
||||
scheduler.getQueueManager().queue(audioTrack, context.getGuildUser());
|
||||
|
||||
if (!silent) {
|
||||
context.reply(MessageFunction.buildAddingTrackMessage(audioTrack, context.getGuildUser(), type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,25 @@ public class MusicUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean canConnect(Context context) {
|
||||
return canConnect(context, false);
|
||||
}
|
||||
|
||||
public static boolean canConnect(Context context, boolean skipChecks) {
|
||||
MusicManager manager = MusicManager.get(context.getGuild());
|
||||
Member member = context.getGuildUser();
|
||||
if (member == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AudioChannel audioChannel = getVoiceChannel(context);
|
||||
if (audioChannel == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return skipChecks || isUserDj(member) || (!manager.isConnected() || !manager.isNotConnectedTo(audioChannel));
|
||||
}
|
||||
|
||||
public static boolean checkIfConnected(Context context) {
|
||||
MusicManager manager = MusicManager.get(context.getGuild());
|
||||
|
||||
|
||||
Reference in new issue
Block a user