Version 3.0

This commit is contained in:
anthorob committed 2025-03-09 20:08:43 +00:00
1 parent 5fb29ea4ed
commit 1242118b0d
174 files changed
+8366 -3263

No files matched your search

@@ -12,19 +12,22 @@ import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import me.bobert.netneutrality.core.LogHandler;
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;
public class TrackLoadingHandler implements AudioLoadResultHandler {
private final Logger logger = LogManager.getLogger(TrackLoadingHandler.class);
private static final Logger logger = LogManager.getLogger(TrackLoadingHandler.class);
private final String identifier;
private final SourceFinder.AudioSourceType type;
private final boolean silent;
private final Guild guild;
private final TrackScheduler scheduler;
private final QueueManager queueManager;
private final CommandContext context;
public TrackLoadingHandler(CommandContext context, MusicManager manager, String identifier, SourceFinder.AudioSourceType type, boolean silent) {
@@ -32,19 +35,21 @@ public class TrackLoadingHandler implements AudioLoadResultHandler {
this.type = type;
this.silent = silent;
this.guild = manager.getGuild();
this.scheduler = manager.getScheduler();
this.queueManager = manager.getQueueManager();
this.context = context;
}
@Override
public void trackLoaded(AudioTrack audioTrack) {
context.deleteMessage();
logger.debug("Guild {}: track loaded: {}", guild.getId(), audioTrack.getIdentifier());
scheduler.getQueueManager().queue(audioTrack, context.getGuildUser());
if (!silent) {
context.reply(MessageFunction.buildAddingTrackMessage(audioTrack, type));
context.deleteMessage();
if (MusicUtils.connect(context)) {
queueManager.queue(audioTrack, context.getGuildUser());
if (!silent) {
context.reply(MessageFunction.buildAddingTrackMessage(audioTrack, context.getGuildUser(), type));
}
}
}
@@ -52,41 +57,26 @@ public class TrackLoadingHandler implements AudioLoadResultHandler {
public void playlistLoaded(AudioPlaylist playlist) {
logger.debug("Guild {}: playlist loaded: {}", guild.getId(), identifier);
if (!playlist.getTracks().isEmpty()) {
if (playlist.isSearchResult()) {
AudioTrack track = playlist.getTracks().get(0);
scheduler.getQueueManager().queue(track, context.getGuildUser());
if (!silent) {
context.reply(MessageFunction.buildAddingTrackMessage(track, type));
}
} else {
context.deleteMessage();
if (!silent) {
context.reply(MessageFunction.buildAddingPlaylistMessage(playlist, identifier, type));
}
for (AudioTrack track : playlist.getTracks()) {
scheduler.getQueueManager().queue(track, context.getGuildUser());
}
}
}
new LoadPlaylistTask(playlist, type).insert(context);
}
@Override
public void noMatches() {
logger.debug("Guild {}: no matches for identifier {}", guild.getId(), identifier);
if (!silent)
context.replyToMessage("No matches found");
context.reply("No matches found");
}
@Override
public void loadFailed(FriendlyException e) {
logger.debug("Guild {}: load failed for identifier {}", guild.getId(), identifier, e);
LogHandler.log(e);
logger.debug("Guild {}: load failed for identifier {}", guild.getId(), identifier);
//TODO: better error messages
RuntimeException exception = new RuntimeException("Failed to load track: " + e.getMessage(), e);
LogHandler.log(exception);
if (!silent)
context.replyToMessage(MessageFunction.buildSentryErrorMessage(new RuntimeException("Failed to load track: " + e.getMessage())));
context.reply(MessageFunction.buildSentryErrorMessage(exception));
}
}