refactor: remove convoluted TrackLoader and LoadableSongs abstraction
BREAKING CHANGE: removed TrackLoader amd LoadableSongs
This commit is contained in:
1 parent
0db751af44
commit
2aa75ce0fc
10 files changed
+9
-385
No files matched your search
@@ -17,16 +17,12 @@ import net.dv8tion.jda.api.entities.Guild;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TrackLoadingHandler implements AudioLoadResultHandler {
|
||||
private final Logger logger = LogManager.getLogger(TrackLoadingHandler.class);
|
||||
|
||||
private final String identifier;
|
||||
private final SourceFinder.AudioSourceType type;
|
||||
private final boolean silent;
|
||||
private Consumer<Boolean> loadConsumer;
|
||||
private boolean loadingDisabled = false;
|
||||
private final Guild guild;
|
||||
private final TrackScheduler scheduler;
|
||||
private final CommandContext context;
|
||||
@@ -40,24 +36,8 @@ public class TrackLoadingHandler implements AudioLoadResultHandler {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public synchronized void stopLoading() {
|
||||
logger.debug("Guild {}: stopped loading of new tracks", guild.getId());
|
||||
loadingDisabled = true;
|
||||
}
|
||||
|
||||
public void useCallbackOnLoad(Consumer<Boolean> consumer) {
|
||||
this.loadConsumer = consumer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trackLoaded(AudioTrack audioTrack) {
|
||||
if (loadConsumer != null) {
|
||||
loadConsumer.accept(true);
|
||||
}
|
||||
|
||||
if (loadingDisabled)
|
||||
return;
|
||||
|
||||
context.deleteMessage();
|
||||
|
||||
logger.debug("Guild {}: track loaded: {}", guild.getId(), audioTrack.getIdentifier());
|
||||
@@ -70,13 +50,6 @@ public class TrackLoadingHandler implements AudioLoadResultHandler {
|
||||
|
||||
@Override
|
||||
public void playlistLoaded(AudioPlaylist playlist) {
|
||||
if (loadConsumer != null) {
|
||||
loadConsumer.accept(true);
|
||||
}
|
||||
|
||||
if (loadingDisabled)
|
||||
return;
|
||||
|
||||
logger.debug("Guild {}: playlist loaded: {}", guild.getId(), identifier);
|
||||
|
||||
if (!playlist.getTracks().isEmpty()) {
|
||||
@@ -96,10 +69,6 @@ public class TrackLoadingHandler implements AudioLoadResultHandler {
|
||||
}
|
||||
|
||||
for (AudioTrack track : playlist.getTracks()) {
|
||||
if (loadingDisabled) {
|
||||
break;
|
||||
}
|
||||
|
||||
scheduler.getQueueManager().queue(track, context.getGuildUser());
|
||||
}
|
||||
}
|
||||
@@ -108,18 +77,12 @@ public class TrackLoadingHandler implements AudioLoadResultHandler {
|
||||
|
||||
@Override
|
||||
public void noMatches() {
|
||||
if (loadConsumer != null)
|
||||
loadConsumer.accept(false);
|
||||
|
||||
if (!silent)
|
||||
context.replyToMessage("No matches found");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFailed(FriendlyException e) {
|
||||
if (loadConsumer != null)
|
||||
loadConsumer.accept(false);
|
||||
|
||||
logger.debug("Guild {}: load failed for identifier {}", guild.getId(), identifier, e);
|
||||
LogHandler.log(e);
|
||||
|
||||
|
||||
Reference in new issue
Block a user