package net.acomputerdog.ircbot.command.types;

import com.sorcix.sirc.Channel;
import com.sorcix.sirc.Chattable;
import com.sorcix.sirc.User;
import net.acomputerdog.ircbot.command.Command;
import net.acomputerdog.ircbot.command.util.CommandLine;
import net.acomputerdog.ircbot.config.Config;
import net.acomputerdog.ircbot.main.Channels;
import net.acomputerdog.ircbot.main.IrcBot;

public class CommandLeave extends Command {
    public CommandLeave() {
        super("Leave", "leave", "part");
    }

    @Override
    public int getMaxArgs() {
        return 1;
    }

    @Override
    public String getHelpString() {
        return Config.COMMAND_PREFIX + "leave [channel]";
    }

    @Override
    public boolean allowedInChannel(Channel channel, User sender) {
        return sender.hasOperator() || "acomputerdog".equals(sender.getRealName());
    }

    @Override
    public boolean allowedInPM(User user) {
        return "acomputerdog".equals(user.getRealName());
    }

    @Override
    public boolean processCommand(IrcBot bot, Channel channel, User sender, Chattable target, CommandLine command) {
        if (channel == null) {
            if (!command.hasArgs()) {
                target.send(colorError("You must specify a channel to leave!"));
                return false;
            } else {
                String channelName = getChannelName(command.args.toLowerCase());
                if (Channels.isConnected(channelName)) {
                    target.send("Left channel \"" + channelName + "\".");
                    Channels.getChannel(channelName).part();
                    Channels.disconnect(channelName);
                    return true;
                } else {
                    target.send(colorError("I'm not connected to \"" + channelName + "\"!"));
                    return false;
                }
            }
        } else if (sender.hasOperator() || "acomputerdog".equals(sender.getRealName())) {
            target.send("Bye :(");
            channel.part();
            Channels.disconnect(channel.getName().toLowerCase());
            return true;
        } else {
            target.send(colorError("Only channel ops and bot admins may use \"" + Config.COMMAND_PREFIX + "leave\"!"));
            return false;
        }
    }

    private static String getChannelName(String name) {
        if (!name.startsWith("#")) {
            return "#".concat(name);
        }
        return name;
    }
}

@@ -1126,193 +1126,88 @@
 f (c
-hannel == null) %7B%0A            if (!command.hasArgs()) %7B%0A                target.send(colorError(%22You must specify a channel to leave!%22));%0A                return false;%0A            %7D else
+ommand.hasArgs()) %7B%0A            if (%22acomputerdog%22.equals(sender.getRealName()))
  %7B%0A 
@@ -1728,32 +1728,207 @@
               %7D%0A
+            %7D else %7B%0A                target.send(colorError(%22Only channel ops and bot admins may use %5C%22%22 + Config.COMMAND_PREFIX + %22leave%5C%22!%22));%0A                return false;%0A
             %7D%0A  
@@ -1940,16 +1940,30 @@
  %7D else 
+%7B%0A            
 if (send
@@ -2033,32 +2033,36 @@
 ) %7B%0A            
+    
 target.send(%22Bye
@@ -2080,16 +2080,20 @@
         
+    
 channel.
@@ -2092,32 +2092,36 @@
 channel.part();%0A
+    
             Chan
@@ -2174,32 +2174,36 @@
 ));%0A            
+  
+  
 return true;%0A   
@@ -2199,32 +2199,36 @@
 n true;%0A        
+    
 %7D else %7B%0A       
@@ -2212,32 +2212,36 @@
        %7D else %7B%0A
+    
             targ
@@ -2348,32 +2348,36 @@
 ));%0A            
+    
 return false;%0A  
@@ -2366,32 +2366,46 @@
   return false;%0A
+            %7D%0A
         %7D%0A    %7D%0A

Correct CommandLeave