Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mintime similar to maxtime #1413

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/nbproject/
/target/
/Playlists/
/test/
*.json
*.txt
nb*.xml
/nbproject/
/target/
/Playlists/
/test/
*.json
*.txt
nb*.xml
.idea
Comment on lines +1 to +8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be ideal to not change the .gitignore, as it sorta falls out of scope for this PR.

20 changes: 19 additions & 1 deletion src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -342,6 +343,11 @@ public long getMaxSeconds()
{
return maxSeconds;
}

public long getMinSeconds()
{
return minSeconds;
}

public int getMaxYTPlaylistPages()
{
Expand All @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/jagrosh/jmusicbot/audio/QueuedTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)));
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/commands/music/SearchCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down