package org.freecode.irc.votebot.api;

import org.freecode.irc.Privmsg;
import org.freecode.irc.Transmittable;
import org.freecode.irc.votebot.FreeVoteBot;

import java.sql.Connection;

public abstract class AdminModule extends CommandModule {
    public AdminModule(FreeVoteBot fvb, Connection dbConn) {
        super(fvb, dbConn);
    }

    @Override
    public boolean canRun(Transmittable trns) {
        if (super.canRun(trns)) {
            String host = ((Privmsg) trns).getHost();
            for (String admin_host : FreeVoteBot.ADMIN_HOSTS) {
                if (host.equals(admin_host)) {
                    return true;
                }
            }
        }
        return false;
    }
}

@@ -32,16 +32,48 @@
 t.api;%0A%0A
+import org.freecode.irc.Notice;%0A
 import o
@@ -185,34 +185,116 @@
 ot;%0A
-%0Aimport java.sql.Connectio
+import org.freecode.irc.votebot.NoticeFilter;%0A%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Patter
 n;%0A%0A
@@ -393,27 +393,8 @@
  fvb
-, Connection dbConn
 ) %7B%0A
@@ -414,16 +414,8 @@
 (fvb
-, dbConn
 );%0A 
@@ -449,22 +449,20 @@
 lic 
-boolean canRun
+void process
 (Tra
@@ -492,249 +492,1081 @@
     
-if (super.canRun(trns)) %7B%0A            String host = ((Privmsg) trns).getHost();%0A            for (String admin_host : FreeVoteBot.ADMIN_HOSTS) %7B%0A                if (host.equals(admin_host)) %7B%0A                    return true;%0A                %7D
+final Privmsg privmsg = (Privmsg) trns;%0A        privmsg.getIrcConnection().addListener(new NoticeFilter() %7B%0A            public boolean accept(Notice notice) %7B%0A                Pattern pattern = Pattern.compile(%22%5Cu0002(.+?)%5Cu0002%22);%0A                Matcher matcher = pattern.matcher(notice.getMessage());%0A                if (matcher.find() && matcher.find()) %7B%0A                    String access = matcher.group(1);%0A                    System.out.println(access);%0A                    if (access.equals(%22Founder%22)) %7B%0A                        return notice.getNick().equals(%22ChanServ%22) && notice.getMessage().contains(%22Main nick:%22) && notice.getMessage().contains(%22%5Cu0002%22 + privmsg.getNick() + %22%5Cu0002%22);%0A                    %7D%0A                %7D%0A                if (notice.getMessage().equals(%22Permission denied.%22))%0A                    notice.getIrcConnection().removeListener(this);%0A                return false;%0A            %7D%0A%0A            public void run(Notice notice) %7B%0A                processMessage(privmsg);%0A                privmsg.getIrcConnection().removeListener(this);
 %0A   
@@ -1577,32 +1577,34 @@
      %7D%0A        %7D
+);
 %0A        return 
@@ -1592,34 +1592,162 @@
 %7D);%0A        
-return false
+privmsg.getIrcConnection().send(new Privmsg(%22ChanServ%22, %22WHY %22 + FreeVoteBot.CHANNEL + %22 %22 + privmsg.getNick(), privmsg.getIrcConnection()))
 ;%0A    %7D%0A%7D%0A

Check access level instead of nick for Admin modules