Added queue move command.

This commit is contained in:
Andrew Lalis 2017-08-31 19:32:30 +02:00 committed by Andrew Lalis
parent 4ffd8c9a64
commit d4163bbbea
4 changed files with 28 additions and 3 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.github.andrewlalis</groupId> <groupId>com.github.andrewlalis</groupId>
<artifactId>HandieBot</artifactId> <artifactId>HandieBot</artifactId>
<version>1.5.2</version> <version>1.5.3</version>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

View File

@ -5,6 +5,7 @@ import handiebot.command.CommandContext;
import handiebot.command.Commands; import handiebot.command.Commands;
import handiebot.command.types.ContextCommand; import handiebot.command.types.ContextCommand;
import handiebot.lavaplayer.playlist.Playlist; import handiebot.lavaplayer.playlist.Playlist;
import handiebot.lavaplayer.playlist.UnloadedTrack;
import handiebot.view.BotLog; import handiebot.view.BotLog;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -24,12 +25,13 @@ public class QueueCommand extends ContextCommand {
public QueueCommand() { public QueueCommand() {
super("queue", super("queue",
"[all|clear|save|remove]", "[all|clear|save|remove|move]",
resourceBundle.getString("commands.command.queue.description.main")+"\n" + resourceBundle.getString("commands.command.queue.description.main")+"\n" +
"\t`all` - "+resourceBundle.getString("commands.command.queue.description.all")+"\n" + "\t`all` - "+resourceBundle.getString("commands.command.queue.description.all")+"\n" +
"\t`clear` - "+resourceBundle.getString("commands.command.queue.description.clear")+"\n" + "\t`clear` - "+resourceBundle.getString("commands.command.queue.description.clear")+"\n" +
"\t`save <PLAYLIST>` - "+resourceBundle.getString("commands.command.queue.description.save")+"\n"+ "\t`save <PLAYLIST>` - "+resourceBundle.getString("commands.command.queue.description.save")+"\n"+
"\t`remove <INDEX| INDEX2...>` - "+resourceBundle.getString("commands.command.queue.description.remove"), "\t`remove <INDEX| INDEX2...>` - "+resourceBundle.getString("commands.command.queue.description.remove")+"\n"+
"\t`move <INDEX> <INDEX> - "+resourceBundle.getString("commands.command.queue.description.move"),
0); 0);
} }
@ -72,6 +74,24 @@ public class QueueCommand extends ContextCommand {
} else { } else {
sendMessage(resourceBundle.getString("commands.command.queue.remove.error"), context.getChannel()); sendMessage(resourceBundle.getString("commands.command.queue.remove.error"), context.getChannel());
} }
case ("move"):
if (context.getArgs().length == 3 && Commands.hasPermission(context, 8)){
int startIndex = Integer.parseInt(context.getArgs()[1]);
int newIndex = Integer.parseInt(context.getArgs()[2]);
Playlist playlist = HandieBot.musicPlayer.getMusicManager(context.getGuild()).scheduler.getActivePlaylist();
int trackCount = playlist.getTrackCount();
//Test if the indices are valid, and if not, show an error message.
if ((startIndex > 0) && (startIndex <= trackCount) && (newIndex > 0) && (newIndex <= trackCount)){
List<UnloadedTrack> tracks = playlist.getTracks();
UnloadedTrack track = tracks.remove(startIndex-1);
tracks.add(newIndex-1, track);
sendMessage(MessageFormat.format(resourceBundle.getString("commands.command.queue.move.success"), track.getTitle(), startIndex, newIndex), context.getChannel());
} else {
sendMessage(resourceBundle.getString("commands.command.queue.move.indexError"), context.getChannel());
}
} else {
sendMessage(resourceBundle.getString("commands.command.queue.move.error"), context.getChannel());
}
} }
} else { } else {
HandieBot.musicPlayer.showQueueList(context.getGuild(), false); HandieBot.musicPlayer.showQueueList(context.getGuild(), false);

View File

@ -96,12 +96,16 @@ commands.command.queue.description.all=Shows all songs.
commands.command.queue.description.clear=Clears the queue and stops playing. commands.command.queue.description.clear=Clears the queue and stops playing.
commands.command.queue.description.save=Saves the queue to a playlist. commands.command.queue.description.save=Saves the queue to a playlist.
commands.command.queue.description.remove=Removes a song from the queue. commands.command.queue.description.remove=Removes a song from the queue.
commands.command.queue.description.move=Moves a song from one index to another.
commands.command.queue.clear=Cleared queue. commands.command.queue.clear=Cleared queue.
commands.command.queue.save.message=Saved {0} tracks to playlist **{1}**. commands.command.queue.save.message=Saved {0} tracks to playlist **{1}**.
commands.command.queue.save.log=Saved queue to playlist [{0}]. commands.command.queue.save.log=Saved queue to playlist [{0}].
commands.command.queue.error.save=Unable to save the queue to a playlist. commands.command.queue.error.save=Unable to save the queue to a playlist.
commands.command.queue.remove.message=Removed song(s) from the active queue. commands.command.queue.remove.message=Removed song(s) from the active queue.
commands.command.queue.remove.error=You must give the index of a song to remove from the queue. commands.command.queue.remove.error=You must give the index of a song to remove from the queue.
commands.command.queue.move.error=You must give the original index of a song in the queue, and a new index.
commands.command.queue.move.indexError=The indices you entered are invalid.
commands.command.queue.move.success=Moved song *{0}* from position {1} to position {2}.
#Repeat #Repeat
commands.command.repeat.description=Sets repeating. commands.command.repeat.description=Sets repeating.
#Shuffle #Shuffle

View File

@ -133,5 +133,6 @@ commands.command.report.description=Reports a user to administrators.
commands.command.report.error=You must name a user in your report. commands.command.report.error=You must name a user in your report.
commands.command.queue.remove=Removed song(s) from the active queue. commands.command.queue.remove=Removed song(s) from the active queue.
commands.command.queue.remove.error=You must give the index of a song to remove from the queue. commands.command.queue.remove.error=You must give the index of a song to remove from the queue.
commands.command.queue.move.success=Moved song *{0}* from position {1} to position {2}.