package me.justramon.ircbot.raqbotx.commands;

import me.justramon.ircbot.raqbotx.config.ConfigHandler;
import me.justramon.ircbot.raqbotx.core.ICommand;
import me.justramon.ircbot.raqbotx.util.MessageHandler;
import me.justramon.ircbot.raqbotx.util.StringUtils;
import org.pircbotx.hooks.events.MessageEvent;

public class Operator implements ICommand<MessageEvent> {

    @Override
    public void exe(MessageEvent event, String[] args) throws Exception {
        if (args.length == 0) {
            MessageHandler.respond(event, "Please give a first argument, valid options are [List/Add/Remove]");
            return;
        }


        String cmd = args[0].toLowerCase();
        switch (cmd) {
            case "list":
                MessageHandler.respond(event, "[" + StringUtils.listToString(ConfigHandler.config.operators) + "]");
                break;

            case "add":
                if (args.length < 2) {
                    MessageHandler.respond(event, "Please give a username too!");
                    return;
                }

                for (int i = 1; i < args.length; i++) {
                    if (args[i].isEmpty())
                        continue;

                    ConfigHandler.config.operators.add(args[i]);
                }

                ConfigHandler.save();
                String addedPeople = StringUtils.arrayToString(StringUtils.trimArgrumentsFromCommand(args));
                MessageHandler.respond(event, "Added [" + addedPeople + "]");
                break;

            case "remove":
                if (args.length < 2) {
                    MessageHandler.respond(event, "Please give a username too!");
                    return;
                }

                for (int i = 1; i < args.length; i++) {
                    if (args[i].isEmpty())
                        continue;

                    ConfigHandler.config.operators.remove(args[i]);
                }

                ConfigHandler.save();

                String removedPeople = StringUtils.arrayToString(StringUtils.trimArgrumentsFromCommand(args));
                MessageHandler.respond(event, "Removed [" + removedPeople + "]");
                break;

            default:
                MessageHandler.respond(event, "Not a valid first argument, valid options are [List/Add/Remove]");
        }
    }

    @Override
    public String[] getAliases() {
        return new String[]{"operator"};
    }

    @Override
    public String getInfo() {
        return "List/Add/Remove bot operators";
    }

    @Override
    public String getUsage() {
        return "?<command> <list/add/remove> <nickname> [nickname ...]";
    }

    @Override
    public boolean xtraFunc() {
        return false;
    }

    @Override
    public boolean isOperatorCommand() {
        return true;
    }
}

@@ -256,16 +256,42 @@
 gUtils;%0A
+import org.pircbotx.User;%0A
 import o
@@ -329,16 +329,16 @@
 eEvent;%0A
-
 %0Apublic 
@@ -389,16 +389,114 @@
 ent%3E %7B%0A%0A
+    private void sendpm(User user, String message) %7B%0A        user.send().message(message);%0A    %7D%0A%0A
     @Ove
@@ -623,37 +623,32 @@
     
-MessageHandler.respond(event,
+sendpm(event.getUser(), 
  %22Pl
@@ -858,36 +858,30 @@
     
-MessageHandler.respond(event
+sendpm(event.getUser()
 , %22%5B
@@ -1060,36 +1060,30 @@
     
-MessageHandler.respond(event
+sendpm(event.getUser()
 , %22P
@@ -1544,36 +1544,30 @@
     
-MessageHandler.respond(event
+sendpm(event.getUser()
 , %22A
@@ -1710,36 +1710,30 @@
     
-MessageHandler.respond(event
+sendpm(event.getUser()
 , %22P
@@ -2200,37 +2200,32 @@
     
-MessageHandler.respond(event,
+sendpm(event.getUser(), 
  %22Re
@@ -2322,36 +2322,30 @@
     
-MessageHandler.respond(event
+sendpm(event.getUser()
 , %22N

Switch replies to pm as to not ping operators