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 1 commit
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 @@ -42,7 +42,7 @@ public class BotConfig
private String token, prefix, altprefix, helpWord, playlistsFolder,
successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji;
private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
private long owner, maxSeconds, aloneTimeUntilStop;
private long owner, maxSeconds, minSeconds, aloneTimeUntilStop;
private OnlineStatus status;
private Activity game;
private Config aliases, transforms;
Expand Down Expand Up @@ -87,6 +87,7 @@ public void load()
updatealerts = config.getBoolean("updatealerts");
useEval = config.getBoolean("eval");
maxSeconds = config.getLong("maxtime");
minSeconds = config.getLong("mintime");
aloneTimeUntilStop = config.getLong("alonetimeuntilstop");
playlistsFolder = config.getString("playlistsfolder");
aliases = config.getConfig("aliases");
Expand Down Expand Up @@ -315,12 +316,22 @@ public long getMaxSeconds()
{
return maxSeconds;
}

public long getMinSeconds()
{
return minSeconds;
}

public String getMaxTime()
{
return FormatUtil.formatTime(maxSeconds * 1000);
}

public String getMinTime()
{
return FormatUtil.formatTime(minSeconds * 1000);
}

public long getAloneTimeUntilStop()
{
return aloneTimeUntilStop;
Expand All @@ -333,6 +344,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 @@ -82,6 +82,12 @@ private void loadSingle(AudioTrack track)
+FormatUtil.formatTime(track.getDuration())+"` > `"+FormatUtil.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: `"
+FormatUtil.formatTime(track.getDuration())+"` < `"+FormatUtil.formatTime(bot.getConfig().getMinSeconds()*1000)+"`")).queue();
return;
}
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
int pos = handler.addTrackToFront(new QueuedTrack(track, event.getAuthor()))+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 @@ -111,6 +111,12 @@ private void loadSingle(AudioTrack track, AudioPlaylist playlist)
+FormatUtil.formatTime(track.getDuration())+"` > `"+FormatUtil.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: `"
+FormatUtil.formatTime(track.getDuration())+"` < `"+FormatUtil.formatTime(bot.getConfig().getMinSeconds()*1000)+"`")).queue();
return;
}
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
int pos = handler.addTrack(new QueuedTrack(track, event.getAuthor()))+1;
String addMsg = FormatUtil.filter(event.getClient().getSuccess()+" Added **"+track.getInfo().title
Expand Down Expand Up @@ -141,7 +147,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, event.getAuthor()));
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 @@ -91,6 +91,12 @@ public void trackLoaded(AudioTrack track)
+FormatUtil.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: `"
+FormatUtil.formatTime(track.getDuration())+"` < `"+bot.getConfig().getMinTime()+"`")).queue();
return;
}
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
int pos = handler.addTrack(new QueuedTrack(track, event.getAuthor()))+1;
m.editMessage(FormatUtil.filter(event.getClient().getSuccess()+" Added **"+track.getInfo().title
Expand All @@ -113,6 +119,12 @@ public void playlistLoaded(AudioPlaylist playlist)
+FormatUtil.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: `"
+FormatUtil.formatTime(track.getDuration())+"` < `"+bot.getConfig().getMinTime()+"`");
return;
}
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
int pos = handler.addTrack(new QueuedTrack(track, event.getAuthor()))+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 @@ -99,6 +99,13 @@ stayinchannel = false
maxtime = 0


// 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