package com.techcavern.wavetact.utils.runnables;

import com.techcavern.wavetact.utils.GeneralRegistry;
import com.techcavern.wavetact.utils.GetUtils;
import com.techcavern.wavetact.utils.IRCUtils;
import com.techcavern.wavetact.utils.PermUtils;
import com.techcavern.wavetact.utils.objects.GenericCommand;
import org.apache.commons.lang3.ArrayUtils;
import org.pircbotx.Channel;
import org.pircbotx.PircBotX;
import org.pircbotx.hooks.events.PrivateMessageEvent;

/**
 * Created by jztech101 on 7/27/14.
 */
public class PrivMsgProcessor {

    public static void PrivMsgProcess(PrivateMessageEvent<PircBotX> event) {
        class process implements Runnable {
            public void run() {
                String[] messageParts = event.getMessage().replaceAll("\\P{InBasic_Latin}", "").split(" ");
                String m = messageParts[0].toLowerCase();
                GenericCommand Command = GetUtils.getCommand(m);
                if (Command == null) {
                    Command = GetUtils.getCommand(m.replaceFirst(GetUtils.getCommandChar(event.getBot()), ""));
                }
                messageParts = ArrayUtils.remove(messageParts, 0);
                if (Command != null && !Command.getCommand().equalsIgnoreCase("checkuserlevel")) {
                    if (Command.getPermLevel() >= 0 && Command.getPermLevel() <= 3) {
                        IRCUtils.processMessage(Command, event.getBot(), null, event.getUser(), 3, messageParts, true);
                    } else {
                        if (IRCUtils.getIRCHostmask(event.getBot(), event.getUser().getNick()) != null) {
                            if (Command.getPermLevel() > 18) {
                                int UserPermLevel = PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(), null, true);
                                if (UserPermLevel >= Command.getPermLevel()) {
                                    IRCUtils.processMessage(Command, event.getBot(), null, event.getUser(), UserPermLevel, messageParts, true);
                                } else {
                                    event.getUser().send().message("Permission Denied");
                                }
                            } else {
                                Channel channel = null;
                                if (messageParts.length >= 1 && messageParts[0].startsWith("#")) {
                                    channel = GetUtils.getChannelbyName(event.getBot(), messageParts[0]);
                                    messageParts = ArrayUtils.remove(messageParts, 0);
                                }
                                if (channel != null || Command.getPermLevel() == 5) {
                                    int UserPermLevel = PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(), null, true);
                                    if (UserPermLevel >= Command.getPermLevel()) {
                                        IRCUtils.processMessage(Command, event.getBot(), channel, event.getUser(), UserPermLevel, messageParts, true);
                                    } else {
                                        event.getUser().send().message("Permission Denied");
                                    }
                                } else {
                                    event.getUser().send().message("Channel Must be Specified as argument #1");
                                }
                            }
                        } else {
                            event.getUser().send().message("Error, you must be in a channel the bot is in to authenticate");
                        }
                    }
                }else if(Command.getCommand().equalsIgnoreCase("checkuserlevel")){
                    if(IRCUtils.getIRCHostmask(event.getBot(), event.getUser().getNick()) != null){
                        IRCUtils.processMessage(Command, event.getBot(), null, event.getUser(), PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(), null, true), messageParts, true);
                    }else{
                        IRCUtils.processMessage(Command, event.getBot(), null, event.getUser(), 3, messageParts, true);
                    }
                }
            }
        }
        GeneralRegistry.threadPool.execute(new process());
    }

}

@@ -3832,16 +3832,394 @@
  null)%7B%0A
+                            Channel channel = null;%0A                                if (messageParts.length %3E= 1 && messageParts%5B0%5D.startsWith(%22#%22)) %7B%0A                                    channel = GetUtils.getChannelbyName(event.getBot(), messageParts%5B0%5D);%0A                                    messageParts = ArrayUtils.remove(messageParts, 0);%0A                                %7D%0A
         

Patch Check User Level to allow Channel Checking