diff --git a/.gitignore b/.gitignore index 4ed319bec..a650691c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ -/nbproject/ -/target/ -/Playlists/ -/test/ -*.json -*.txt -nb*.xml \ No newline at end of file +/nbproject/ +/target/ +/Playlists/ +/test/ +*.json +*.txt +nb*.xml +.idea diff --git a/src/main/java/com/jagrosh/jmusicbot/BotConfig.java b/src/main/java/com/jagrosh/jmusicbot/BotConfig.java index f6a8757ac..90594d7d2 100644 --- a/src/main/java/com/jagrosh/jmusicbot/BotConfig.java +++ b/src/main/java/com/jagrosh/jmusicbot/BotConfig.java @@ -43,7 +43,7 @@ public class BotConfig successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji, evalEngine; private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots; - private long owner, maxSeconds, aloneTimeUntilStop; + private long owner, maxSeconds, minSeconds, aloneTimeUntilStop; private int maxYTPlaylistPages; private double skipratio; private OnlineStatus status; @@ -92,6 +92,7 @@ public void load() useEval = config.getBoolean("eval"); evalEngine = config.getString("evalengine"); maxSeconds = config.getLong("maxtime"); + minSeconds = config.getLong("mintime"); maxYTPlaylistPages = config.getInt("maxytplaylistpages"); aloneTimeUntilStop = config.getLong("alonetimeuntilstop"); playlistsFolder = config.getString("playlistsfolder"); @@ -342,6 +343,11 @@ public long getMaxSeconds() { return maxSeconds; } + + public long getMinSeconds() + { + return minSeconds; + } public int getMaxYTPlaylistPages() { @@ -353,6 +359,11 @@ public String getMaxTime() return TimeUtil.formatTime(maxSeconds * 1000); } + public String getMinTime() + { + return TimeUtil.formatTime(minSeconds * 1000); + } + public long getAloneTimeUntilStop() { return aloneTimeUntilStop; @@ -365,6 +376,13 @@ public boolean isTooLong(AudioTrack track) return Math.round(track.getDuration()/1000.0) > maxSeconds; } + public boolean isTooShort(AudioTrack track) + { + if(minSeconds<=0) + return false; + return Math.round(track.getDuration()/1000.0) < minSeconds; + } + public String[] getAliases(String command) { try diff --git a/src/main/java/com/jagrosh/jmusicbot/audio/NowplayingHandler.java b/src/main/java/com/jagrosh/jmusicbot/audio/NowplayingHandler.java index e09e3e643..d1f3c7b5e 100644 --- a/src/main/java/com/jagrosh/jmusicbot/audio/NowplayingHandler.java +++ b/src/main/java/com/jagrosh/jmusicbot/audio/NowplayingHandler.java @@ -17,19 +17,16 @@ import com.jagrosh.jmusicbot.Bot; import com.jagrosh.jmusicbot.entities.Pair; -import com.jagrosh.jmusicbot.settings.Settings; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import java.util.HashMap; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; -import net.dv8tion.jda.api.Permission; + import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.exceptions.PermissionException; -import net.dv8tion.jda.api.exceptions.RateLimitedException; /** * diff --git a/src/main/java/com/jagrosh/jmusicbot/audio/QueuedTrack.java b/src/main/java/com/jagrosh/jmusicbot/audio/QueuedTrack.java index 81e4f75c2..957b1368e 100644 --- a/src/main/java/com/jagrosh/jmusicbot/audio/QueuedTrack.java +++ b/src/main/java/com/jagrosh/jmusicbot/audio/QueuedTrack.java @@ -19,7 +19,6 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo; import com.jagrosh.jmusicbot.queue.Queueable; -import net.dv8tion.jda.api.entities.User; /** * diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/dj/PlaynextCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/dj/PlaynextCmd.java index 0d5924edc..d280133ba 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/dj/PlaynextCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/dj/PlaynextCmd.java @@ -84,6 +84,12 @@ private void loadSingle(AudioTrack track) + TimeUtil.formatTime(track.getDuration())+"` > `"+ TimeUtil.formatTime(bot.getConfig().getMaxSeconds()*1000)+"`")).queue(); return; } + if(bot.getConfig().isTooShort(track)) + { + m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" This track (**"+track.getInfo().title+"**) is shorter than the allowed minimum: `" + +TimeUtil.formatTime(track.getDuration())+"` < `"+TimeUtil.formatTime(bot.getConfig().getMinSeconds()*1000)+"`")).queue(); + return; + } AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); int pos = handler.addTrackToFront(new QueuedTrack(track, RequestMetadata.fromResultHandler(track, event)))+1; String addMsg = FormatUtil.filter(event.getClient().getSuccess()+" Added **"+track.getInfo().title diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/music/PlayCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/music/PlayCmd.java index 67c8c8a1b..108c14061 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/music/PlayCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/music/PlayCmd.java @@ -113,6 +113,12 @@ private void loadSingle(AudioTrack track, AudioPlaylist playlist) + TimeUtil.formatTime(track.getDuration())+"` > `"+ TimeUtil.formatTime(bot.getConfig().getMaxSeconds()*1000)+"`")).queue(); return; } + if(bot.getConfig().isTooShort(track)) + { + m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" This track (**"+track.getInfo().title+"**) is shorter than the allowed minimum: `" + +TimeUtil.formatTime(track.getDuration())+"` < `"+TimeUtil.formatTime(bot.getConfig().getMinSeconds()*1000)+"`")).queue(); + return; + } AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); int pos = handler.addTrack(new QueuedTrack(track, RequestMetadata.fromResultHandler(track, event)))+1; String addMsg = FormatUtil.filter(event.getClient().getSuccess()+" Added **"+track.getInfo().title @@ -143,7 +149,7 @@ private int loadPlaylist(AudioPlaylist playlist, AudioTrack exclude) { int[] count = {0}; playlist.getTracks().stream().forEach((track) -> { - if(!bot.getConfig().isTooLong(track) && !track.equals(exclude)) + if(!bot.getConfig().isTooLong(track) && !bot.getConfig().isTooShort(track) && !track.equals(exclude)) { AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); handler.addTrack(new QueuedTrack(track, RequestMetadata.fromResultHandler(track, event))); diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/music/SearchCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/music/SearchCmd.java index 265be6045..74a7c3e46 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/music/SearchCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/music/SearchCmd.java @@ -93,6 +93,12 @@ public void trackLoaded(AudioTrack track) + TimeUtil.formatTime(track.getDuration())+"` > `"+bot.getConfig().getMaxTime()+"`")).queue(); return; } + if(bot.getConfig().isTooShort(track)) + { + m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" This track (**"+track.getInfo().title+"**) is shorter than the allowed minimum: `" + +TimeUtil.formatTime(track.getDuration())+"` < `"+bot.getConfig().getMinTime()+"`")).queue(); + return; + } AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); int pos = handler.addTrack(new QueuedTrack(track, RequestMetadata.fromResultHandler(track, event)))+1; m.editMessage(FormatUtil.filter(event.getClient().getSuccess()+" Added **"+track.getInfo().title @@ -115,6 +121,12 @@ public void playlistLoaded(AudioPlaylist playlist) + TimeUtil.formatTime(track.getDuration())+"` > `"+bot.getConfig().getMaxTime()+"`"); return; } + if(bot.getConfig().isTooShort(track)) + { + event.replyWarning("This track (**"+track.getInfo().title+"**) is shorter than the allowed minimum: `" + +TimeUtil.formatTime(track.getDuration())+"` < `"+bot.getConfig().getMinTime()+"`"); + return; + } AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); int pos = handler.addTrack(new QueuedTrack(track, RequestMetadata.fromResultHandler(track, event)))+1; event.replySuccess("Added **" + FormatUtil.filter(track.getInfo().title) diff --git a/src/main/java/com/jagrosh/jmusicbot/playlist/PlaylistLoader.java b/src/main/java/com/jagrosh/jmusicbot/playlist/PlaylistLoader.java index 602235fcf..ddec70d35 100644 --- a/src/main/java/com/jagrosh/jmusicbot/playlist/PlaylistLoader.java +++ b/src/main/java/com/jagrosh/jmusicbot/playlist/PlaylistLoader.java @@ -182,6 +182,8 @@ public void trackLoaded(AudioTrack at) { if(config.isTooLong(at)) errors.add(new PlaylistLoadError(index, items.get(index), "This track is longer than the allowed maximum")); + else if(config.isTooShort(at)) + errors.add(new PlaylistLoadError(index, items.get(index), "This track is shorter than the allowed minimum")); else { at.setUserData(0L); @@ -213,7 +215,7 @@ else if(ap.getSelectedTrack()!=null) loaded.set(first, loaded.get(second)); loaded.set(second, tmp); } - loaded.removeIf(track -> config.isTooLong(track)); + loaded.removeIf(track -> config.isTooLong(track) || config.isTooShort(track)); loaded.forEach(at -> at.setUserData(0L)); tracks.addAll(loaded); loaded.forEach(at -> consumer.accept(at)); diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index a4fda1e02..3c80b6e0f 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -115,6 +115,13 @@ maxytplaylistpages = 10 skipratio = 0.55 +// This sets the minimum amount of seconds any track loaded can be. If not set or set +// to any number less than or equal to zero, there is no minimum time length. This time +// restriction applies to songs loaded from any source. + +mintime = 0 + + // This sets the amount of seconds the bot will stay alone on a voice channel until it // automatically leaves the voice channel and clears the queue. If not set or set // to any number less than or equal to zero, the bot won't leave when alone.