package com.bwfcwalshy.flarebot.commands.music;

import com.bwfcwalshy.flarebot.FlareBot;
import com.bwfcwalshy.flarebot.MessageUtils;
import com.bwfcwalshy.flarebot.commands.Command;
import com.bwfcwalshy.flarebot.commands.CommandType;
import com.bwfcwalshy.flarebot.music.MusicManager;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.util.audio.AudioPlayer;

public class SkipCommand implements Command {

    private MusicManager musicManager;
    public SkipCommand(FlareBot bot){
        this.musicManager = bot.getMusicManager();
    }

    @Override
    public void onCommand(IUser sender, IChannel channel, IMessage message, String[] args) {
        if(args.length == 1){
            String arg = args[0];
            if(arg.startsWith("#")){
                arg = arg.substring(1);
                try {
                    int num = Integer.parseInt(arg) - 1;
                    AudioPlayer pl = musicManager.getPlayers().get(channel.getGuild().getID());
                    if(pl != null && pl.getPlaylistSize() < num){
                        pl.getPlaylist().remove(num);
                        return;
                    }
                } catch (NumberFormatException e){
                    MessageUtils.sendMessage(channel, "Must be a number!");
                }
            }
            try {
                int num = Integer.parseInt(arg);
                musicManager.skip(channel.getGuild().getID(), num);
            } catch (NumberFormatException e){
                MessageUtils.sendMessage(channel, "Must be a number!");
            }
            return;
        }
        musicManager.skip(channel.getGuild().getID());
    }

    @Override
    public String getCommand() {
        return "skip";
    }

    @Override
    public String getDescription() {
        return "Skip the current song playing, or if specified #NUMBER for the song under NUMBER or just NUMBER for next NUMBER songs.";
    }

    @Override
    public CommandType getType() { return CommandType.MUSIC; }
}

@@ -544,16 +544,17 @@
 anager;%0A
+%0A
     publ
@@ -581,16 +581,17 @@
 Bot bot)
+ 
 %7B%0A      
@@ -755,24 +755,25 @@
 %7B%0A        if
+ 
 (args.length
@@ -778,16 +778,17 @@
 th == 1)
+ 
 %7B%0A      
@@ -829,16 +829,17 @@
       if
+ 
 (arg.sta
@@ -851,16 +851,17 @@
 th(%22#%22))
+ 
 %7B%0A      
@@ -1091,16 +1091,17 @@
       if
+ 
 (pl != n
@@ -1132,14 +1132,27 @@
 e() 
-%3C num)
+%3E num && num %3E= 0) 
 %7B%0A  
@@ -1207,40 +1207,8 @@
 m);%0A
-                        return;%0A
     
@@ -1266,32 +1266,33 @@
 rmatException e)
+ 
 %7B%0A              
@@ -1376,33 +1376,42 @@
  %7D%0A            %7D
-%0A
+ else%0A    
             try 
@@ -1404,32 +1404,36 @@
           try %7B%0A
+    
                 
@@ -1473,32 +1473,36 @@
                 
+ 
+   
 musicManager.ski
@@ -1541,32 +1541,36 @@
 m);%0A            
+    
 %7D catch (NumberF
@@ -1586,18 +1586,23 @@
 ption e)
+ 
 %7B%0A
+    
         
@@ -1669,32 +1669,36 @@
 %22);%0A            
+    
 %7D%0A            re
@@ -1695,30 +1695,43 @@
     
-    return;%0A   
+%7D else if (args.length == 0) %7B%0A
     
- %7D%0A
     
@@ -1777,24 +1777,114 @@
 ).getID());%0A
+        %7D else MessageUtils.sendMessage(channel, %22Incorrect usage! %22 + getDescription());%0A
     %7D%0A%0A    @
@@ -2198,16 +2198,24 @@
 Type() %7B
+%0A       
  return 
@@ -2232,13 +2232,17 @@
 e.MUSIC;
+%0A   
  %7D%0A%7D%0A

Fix a dumb logic error in the skip command