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);
|
SourceFinder.AudioSourceType type = SourceFinder.getSource(query);
|
||||||
String identifier = SourceFinder.getIdentifier(query);
|
String identifier = SourceFinder.getIdentifier(query);
|
||||||
if (identifier == null) {
|
if (identifier == null) {
|
||||||
context.reply("No source found for provided query");
|
context.reply("No source found to play the given url");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MusicUtils.connect(context)) {
|
if (MusicUtils.canConnect(context)) {
|
||||||
TrackLoadingHandler loadingHandler = new TrackLoadingHandler(context, this, identifier, type, silent);
|
TrackLoadingHandler loadingHandler = new TrackLoadingHandler(context, this, identifier, type, silent);
|
||||||
playerManager.loadItemOrdered(this, identifier, loadingHandler);
|
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.core.tasks.TaskManager;
|
||||||
import me.bobert.netneutrality.tasks.music.LoadPlaylistTask;
|
import me.bobert.netneutrality.tasks.music.LoadPlaylistTask;
|
||||||
import me.bobert.netneutrality.utils.MessageFunction;
|
import me.bobert.netneutrality.utils.MessageFunction;
|
||||||
|
import me.bobert.netneutrality.utils.MusicUtils;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -43,10 +44,13 @@ public class TrackLoadingHandler implements AudioLoadResultHandler {
|
|||||||
context.deleteMessage();
|
context.deleteMessage();
|
||||||
|
|
||||||
logger.debug("Guild {}: track loaded: {}", guild.getId(), audioTrack.getIdentifier());
|
logger.debug("Guild {}: track loaded: {}", guild.getId(), audioTrack.getIdentifier());
|
||||||
scheduler.getQueueManager().queue(audioTrack, context.getGuildUser());
|
|
||||||
|
|
||||||
if (!silent) {
|
if (MusicUtils.connect(context)) {
|
||||||
context.reply(MessageFunction.buildAddingTrackMessage(audioTrack, context.getGuildUser(), type));
|
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;
|
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) {
|
public static boolean checkIfConnected(Context context) {
|
||||||
MusicManager manager = MusicManager.get(context.getGuild());
|
MusicManager manager = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user