Setup gradle build
authorJan Dittberner <jandd@cacert.org>
Sat, 11 Jun 2016 11:25:59 +0000 (13:25 +0200)
committerJan Dittberner <jandd@cacert.org>
Sat, 11 Jun 2016 11:25:59 +0000 (13:25 +0200)
This commit defines a gradle build setup for the vote bot. The eclipse
specific configuration has been removed, the source code has been moved
to src/main/java. Gradle wrapper has been included to make bootstraping
as easy as running ./gradlew build

18 files changed:
.classpath [deleted file]
.gitignore
.project [deleted file]
build.gradle [new file with mode: 0644]
gradle/wrapper/gradle-wrapper.jar [new file with mode: 0644]
gradle/wrapper/gradle-wrapper.properties [new file with mode: 0644]
gradlew [new file with mode: 0755]
gradlew.bat [new file with mode: 0644]
src/main/java/org/cacert/votebot/CAcertVoteAuditor.java [new file with mode: 0644]
src/main/java/org/cacert/votebot/CAcertVoteBot.java [new file with mode: 0644]
src/main/java/org/cacert/votebot/CAcertVoteMechanics.java [new file with mode: 0644]
src/main/java/org/cacert/votebot/IRCBot.java [new file with mode: 0644]
src/main/java/org/cacert/votebot/IRCClient.java [new file with mode: 0644]
src/org/cacert/votebot/CAcertVoteAuditor.java [deleted file]
src/org/cacert/votebot/CAcertVoteBot.java [deleted file]
src/org/cacert/votebot/CAcertVoteMechanics.java [deleted file]
src/org/cacert/votebot/IRCBot.java [deleted file]
src/org/cacert/votebot/IRCClient.java [deleted file]

diff --git a/.classpath b/.classpath
deleted file mode 100644 (file)
index 91ee9a5..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>\r
-<classpath>\r
-       <classpathentry kind="src" path="src"/>\r
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>\r
-       <classpathentry kind="output" path="bin"/>\r
-</classpath>\r
index bd3461c..ac1453e 100644 (file)
@@ -6,3 +6,6 @@ services.properties
 /bin
 /plugins_bin
 infiniteStory
+.classpath
+.gradle/
+build/
diff --git a/.project b/.project
deleted file mode 100644 (file)
index 9453078..0000000
--- a/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-       <name>cacert-votebot</name>
-       <comment></comment>
-       <projects>
-       </projects>
-       <buildSpec>
-               <buildCommand>
-                       <name>org.eclipse.jdt.core.javabuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-       </buildSpec>
-       <natures>
-               <nature>org.eclipse.jdt.core.javanature</nature>
-       </natures>
-</projectDescription>
diff --git a/build.gradle b/build.gradle
new file mode 100644 (file)
index 0000000..fe5908e
--- /dev/null
@@ -0,0 +1,18 @@
+description = "IRC vote bot for CAcert.org"
+
+apply plugin: 'java'
+
+sourceCompatibility = 1.7
+targetCompatibility = 1.7
+
+repositories {
+    mavenCentral()
+}
+
+group = 'org.cacert'
+version = '0.1.0-SNAPSHOT'
+
+task wrapper(type: Wrapper) {
+    gradleVersion = '2.13'
+}
+
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644 (file)
index 0000000..adaeaca
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644 (file)
index 0000000..4745bc6
--- /dev/null
@@ -0,0 +1,6 @@
+#Sat Jun 11 13:18:17 CEST 2016
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
diff --git a/gradlew b/gradlew
new file mode 100755 (executable)
index 0000000..27309d9
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+  NONSTOP* )
+    nonstop=true
+    ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+    JAVACMD=`cygpath --unix "$JAVACMD"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644 (file)
index 0000000..832fdb6
--- /dev/null
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/src/main/java/org/cacert/votebot/CAcertVoteAuditor.java b/src/main/java/org/cacert/votebot/CAcertVoteAuditor.java
new file mode 100644 (file)
index 0000000..95fc87d
--- /dev/null
@@ -0,0 +1,109 @@
+package org.cacert.votebot;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.cacert.votebot.CAcertVoteMechanics.VoteType;
+
+public class CAcertVoteAuditor extends IRCBot {
+
+    public CAcertVoteAuditor(IRCClient c, String toAudit) {
+        super(c);
+        this.toAudit = toAudit;
+        c.join(voteAuxChn);
+    }
+
+    String voteAuxChn = System.getProperty("auditor.target.voteChn", "vote");
+
+    String toAudit;
+
+    long warn = Long.parseLong(System.getProperty("voteBot.warnSecs", "90"));
+
+    long timeout = Long.parseLong(System.getProperty("voteBot.timeoutSecs", "120"));
+
+    CAcertVoteMechanics mech = new CAcertVoteMechanics();
+
+    String[] capturedResults = new String[VoteType.values().length];
+
+    int ctr = -1;
+
+    @Override
+    public synchronized void publicMessage(String from, String channel, String message) {
+        if (channel.equals(voteAuxChn)) {
+            if (from.equals(toAudit)) {
+                if (ctr >= 0) {
+                    capturedResults[ctr++] = message;
+
+                    if (ctr == capturedResults.length) {
+                        String[] reals = mech.closeVote();
+
+                        if (Arrays.equals(reals, capturedResults)) {
+                            System.out.println("Audit for vote was successful.");
+                        } else {
+                            System.out.println("Audit failed! Vote Bot (or Auditor) is probably broken.");
+                        }
+
+                        ctr = -1;
+                    }
+
+                    return;
+                }
+                if (message.startsWith("New Vote: ")) {
+                    System.out.println("detected vote-start");
+
+                    Pattern p = Pattern.compile("New Vote: (.*) has started a vote on \"(.*)\"");
+                    Matcher m = p.matcher(message);
+
+                    if ( !m.matches()) {
+                        System.out.println("error: vote-start malformed");
+                        return;
+                    }
+
+                    mech.callVote(m.group(1), m.group(2));
+                } else if (message.startsWith("Results: ")) {
+                    System.out.println("detected vote-end. Reading results");
+
+                    ctr = 0;
+                }
+            } else {
+                if (ctr != -1) {
+                    System.out.println("Vote after end.");
+                    return;
+                }
+
+                System.out.println("detected vote");
+                mech.evaluateVote(from, message);
+                System.out.println("Current state: " + mech.getCurrentResult());
+            }
+        }
+    }
+
+    @Override
+    public synchronized void privateMessage(String from, String message) {
+
+    }
+
+    @Override
+    public synchronized void join(String cleanReferent, String chn) {
+
+    }
+
+    @Override
+    public synchronized void part(String cleanReferent, String chn) {
+
+    }
+
+    public static void main(String[] args) throws IOException, InterruptedException {
+        IRCClient ic = IRCClient.parseCommandLine(args, "dogcraft_de-Auditor");
+        String targetNick = System.getProperty("auditor.target.nick");
+
+        if (targetNick == null) {
+            System.out.println("use -Dauditor.target.nick=TargetNick to set a target nick");
+            System.exit(0);
+        }
+
+        ic.setBot(new CAcertVoteAuditor(ic, targetNick));
+    }
+}
diff --git a/src/main/java/org/cacert/votebot/CAcertVoteBot.java b/src/main/java/org/cacert/votebot/CAcertVoteBot.java
new file mode 100644 (file)
index 0000000..94c2f2d
--- /dev/null
@@ -0,0 +1,94 @@
+package org.cacert.votebot;
+
+import java.io.IOException;
+
+import org.cacert.votebot.CAcertVoteMechanics.State;
+
+public class CAcertVoteBot extends IRCBot implements Runnable {
+
+    public CAcertVoteBot(IRCClient c) {
+        super(c);
+
+        c.join(meetingChn);
+        c.join(voteAuxChn);
+
+        new Thread(this).start();
+    }
+
+    String meetingChn = System.getProperty("voteBot.meetingChn", "agm");
+
+    String voteAuxChn = System.getProperty("voteBot.voteChn", "vote");
+
+    long warn = Long.parseLong(System.getProperty("voteBot.warnSecs", "90"));
+
+    long timeout = Long.parseLong(System.getProperty("voteBot.timeoutSecs", "120"));
+
+    CAcertVoteMechanics mech = new CAcertVoteMechanics();
+
+    @Override
+    public synchronized void publicMessage(String from, String channel, String message) {
+        if (channel.equals(voteAuxChn)) {
+            sendPublicMessage(voteAuxChn, mech.evaluateVote(from, message));
+        }
+    }
+
+    @Override
+    public synchronized void privateMessage(String from, String message) {
+        if (message.startsWith("vote ")) {
+            String response = mech.callVote(from, message.substring(5));
+            sendPrivateMessage(from, response);
+
+            if (response.startsWith("Sorry,")) {
+                return;
+            }
+
+            anounce("New Vote: " + from + " has started a vote on \"" + mech.getTopic() + "\"");
+            sendPublicMessage(meetingChn, "Please cast your vote in #vote");
+            sendPublicMessage(voteAuxChn, "Please cast your vote in the next " + timeout + " seconds.");
+        }
+    }
+
+    private synchronized void anounce(String msg) {
+        sendPublicMessage(meetingChn, msg);
+        sendPublicMessage(voteAuxChn, msg);
+    }
+
+    public void run() {
+        try {
+            while (true) {
+                while (mech.getState() == State.IDLE) {
+                    Thread.sleep(1000);
+                }
+
+                Thread.sleep(warn * 1000);
+                anounce("Voting on " + mech.getTopic() + " will end in " + (timeout - warn) + " seconds.");
+                Thread.sleep((timeout - warn) * 1000);
+                anounce("Voting on " + mech.getTopic() + " has closed.");
+                String[] res = mech.closeVote();
+                anounce("Results: for " + mech.getTopic() + ":");
+
+                for (int i = 0; i < res.length; i++) {
+                    anounce(res[i]);
+                }
+            }
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public synchronized void join(String cleanReferent, String chn) {
+
+    }
+
+    @Override
+    public synchronized void part(String cleanReferent, String chn) {
+
+    }
+
+    public static void main(String[] args) throws IOException, InterruptedException {
+        IRCClient ic = IRCClient.parseCommandLine(args, "dogcraft_de");
+        ic.setBot(new CAcertVoteBot(ic));
+    }
+
+}
diff --git a/src/main/java/org/cacert/votebot/CAcertVoteMechanics.java b/src/main/java/org/cacert/votebot/CAcertVoteMechanics.java
new file mode 100644 (file)
index 0000000..e331eac
--- /dev/null
@@ -0,0 +1,171 @@
+package org.cacert.votebot;
+
+import java.util.HashMap;
+import java.util.Map.Entry;
+
+/**
+ * Reprenents the voting-automata for voting in IRC chanenls.
+ */
+public class CAcertVoteMechanics {
+
+    public static enum VoteType {
+        AYE, NAYE, ABSTAIN
+    }
+
+    public static enum State {
+        RUNNING, IDLE
+    }
+
+    State state = State.IDLE;
+
+    String voteCaller;
+
+    String topic;
+
+    private String vote(String voter, String actor, VoteType type) {
+        votes.put(voter, type);
+
+        if (voter.equals(actor)) {
+            return "Thanks " + actor + " I count your vote as " + type;
+        } else {
+            return "Thanks " + actor + " I count your vote for " + voter + " as " + type;
+        }
+    }
+
+    HashMap<String, VoteType> votes = new HashMap<>();
+
+    private String voteError(String actor) {
+        return "Sorry " + actor + ", I did not understand your vote, your current vote state remains unchanged!";
+    }
+
+    /**
+     * Adds a vote to the current topic. This interprets proxies.
+     *
+     * @param actor
+     *            the person that sent this vote
+     * @param txt
+     *            the text that the person sent.
+     * @return A message to
+     *
+     *         <pre>
+     * actor
+     * </pre>
+     *
+     *         indicating tha result of his action.
+     */
+    public synchronized String evaluateVote(String actor, String txt) {
+        if (state != State.RUNNING) {
+            return "Sorry " + actor + ", but currently no vote is running.";
+        }
+
+        String voter = actor;
+        String value = null;
+
+        if (txt.toLowerCase().matches("^\\s*proxy\\s.*")) {
+            String[] parts = txt.split("\\s+");
+            if (parts.length == 3) {
+                voter = parts[1];
+                value = parts[2];
+            }
+        } else {
+            value = txt.replaceAll("^\\s*|\\s*$", "");
+        }
+
+        if (value == null) {
+            return voteError(actor);
+        } else {
+            value = value.toLowerCase();
+
+            switch (value) {
+            case "aye":
+            case "yes":
+            case "oui":
+            case "ja": {
+                return vote(voter, actor, VoteType.AYE);
+            }
+            case "naye":
+            case "nay":
+            case "no":
+            case "non":
+            case "nein": {
+                return vote(voter, actor, VoteType.NAYE);
+            }
+            case "abstain":
+            case "enthaltung":
+            case "enthalten":
+            case "abs": {
+                return vote(voter, actor, VoteType.ABSTAIN);
+            }
+            }
+        }
+
+        return voteError(actor);
+    }
+
+    /**
+     * A new vote begins.
+     * 
+     * @param from
+     *            the nick that called the vote
+     * @param topic
+     *            the topic of the vote
+     * @return A response to
+     * 
+     *         <pre>
+     * from
+     * </pre>
+     * 
+     *         indicating success or failure.
+     */
+    public synchronized String callVote(String from, String topic) {
+        if (state != State.IDLE) {
+            return "Sorry, a vote is already running";
+        }
+
+        voteCaller = from;
+        this.topic = topic;
+        votes.clear();
+
+        state = State.RUNNING;
+
+        return "Vote started.";
+    }
+
+    /**
+     * Ends a vote.
+     * 
+     * @return An array of Strings containing result status messages.
+     */
+    public synchronized String[] closeVote() {
+        int[] res = new int[VoteType.values().length];
+
+        for (Entry<String, VoteType> i : votes.entrySet()) {
+            res[i.getValue().ordinal()]++;
+        }
+
+        String[] results = new String[VoteType.values().length];
+
+        for (int i = 0; i < res.length; i++) {
+            results[i] = (VoteType.values()[i] + ": " + res[i]);
+        }
+
+        votes.clear();
+        voteCaller = null;
+        state = State.IDLE;
+
+        return results;
+    }
+
+    public String getTopic() {
+        return topic;
+    }
+
+    public State getState() {
+        return state;
+    }
+
+    public String getCurrentResult() {
+        return votes.toString();
+    }
+
+}
diff --git a/src/main/java/org/cacert/votebot/IRCBot.java b/src/main/java/org/cacert/votebot/IRCBot.java
new file mode 100644 (file)
index 0000000..2fe40ad
--- /dev/null
@@ -0,0 +1,28 @@
+package org.cacert.votebot;
+
+public abstract class IRCBot {
+
+    private IRCClient c;
+
+    public IRCBot(IRCClient c) {
+        this.c = c;
+    }
+
+    public abstract void publicMessage(String from, String channel,
+            String message);
+
+    public abstract void privateMessage(String from, String message);
+
+    public void sendPublicMessage(String channel, String message) {
+        c.send(message, channel);
+    }
+
+    public void sendPrivateMessage(String to, String message) {
+        c.sendPrivate(message, to);
+    }
+
+    public abstract void part(String cleanReferent, String chn);
+
+    public abstract void join(String cleanReferent, String chn);
+
+}
diff --git a/src/main/java/org/cacert/votebot/IRCClient.java b/src/main/java/org/cacert/votebot/IRCClient.java
new file mode 100644 (file)
index 0000000..52aad37
--- /dev/null
@@ -0,0 +1,256 @@
+package org.cacert.votebot;
+
+import java.io.BufferedReader;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.concurrent.Semaphore;
+
+import javax.net.ssl.SSLSocketFactory;
+
+public class IRCClient {
+
+    private Semaphore loggedin = new Semaphore(0);
+
+    private PrintWriter out;
+
+    private Socket s;
+
+    class ServerReader implements Runnable {
+
+        private BufferedReader br;
+
+        public ServerReader(BufferedReader br) {
+            this.br = br;
+
+            new Thread(this).start();
+        }
+
+        @Override
+        public void run() {
+            String l;
+
+            try {
+                while ((l = br.readLine()) != null) {
+                    String fullline = l;
+                    // System.out.println(l);
+
+                    if (l.startsWith("PING ")) {
+                        System.out.println("PONG");
+                        out.println("PONG " + l.substring(5));
+                    }
+
+                    String referent = "";
+
+                    if (l.startsWith(":")) {
+                        String[] parts = l.split(" ", 2);
+                        referent = parts[0];
+                        l = parts[1];
+                    }
+
+                    String[] command = l.split(" ", 3);
+
+                    if (command[0].equals("001")) {
+                        loggedin.release();
+                    }
+
+                    if (command[0].equals("PRIVMSG")) {
+                        String msg = command[2].substring(1);
+                        String chnl = command[1];
+
+                        if ( !chnl.startsWith("#")) {
+                            handlePrivMsg(referent, msg);
+                        } else {
+                            handleMsg(referent, chnl, msg);
+                        }
+
+                        log(chnl, fullline);
+                    } else if (command[0].equals("JOIN")) {
+                        String chn = command[1].substring(1);
+                        targetBot.join(cleanReferent(referent), chn.substring(1));
+                        log(chn, fullline);
+                    } else if (command[0].equals("PART")) {
+                        String chn = command[1];
+                        targetBot.part(cleanReferent(referent), chn);
+                        log(chn, fullline);
+                    } else {
+                        System.out.println("unknown line: ");
+                        System.out.println(l);
+                    }
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+
+        }
+
+        private String cleanReferent(String referent) {
+            String[] parts = referent.split("!");
+
+            if ( !parts[0].startsWith(":")) {
+                System.err.println("invalid public message");
+                return "unknown";
+            }
+
+            return parts[0];
+        }
+
+        HashMap<String, PrintWriter> logs = new HashMap<String, PrintWriter>();
+
+        private void log(String chn, String l) throws IOException {
+            PrintWriter log = logs.get(chn);
+
+            if (log == null) {
+                log = new PrintWriter(new FileOutputStream("irc/log_" + chn), true);
+                logs.put(chn, log);
+            }
+
+            log.println(l);
+        }
+
+        private void handlePrivMsg(String referent, String msg) {
+            String[] parts = referent.split("!");
+
+            if ( !parts[0].startsWith(":")) {
+                System.err.println("invalid private message");
+                return;
+            }
+
+            if (targetBot == null) {
+                System.out.println("dropping message");
+                return;
+            }
+
+            targetBot.privateMessage(parts[0].substring(1), msg);
+        }
+
+        private void handleMsg(String referent, String chnl, String msg) {
+            String[] parts = referent.split("!");
+
+            if ( !parts[0].startsWith(":")) {
+                System.err.println("invalid public message");
+                return;
+            }
+
+            if (targetBot == null) {
+                System.out.println("dropping message");
+                return;
+            }
+
+            if ( !chnl.startsWith("#")) {
+                System.err.println("invalid public message (chnl)");
+                return;
+            }
+
+            targetBot.publicMessage(parts[0].substring(1), chnl.substring(1), msg);
+        }
+
+    }
+
+    public IRCClient(String nick, String server, int port, boolean ssl) throws IOException, InterruptedException {
+        if ( !nick.matches("[a-zA-Z0-9_-]+")) {
+            throw new Error("malformed");
+        }
+
+        if (ssl) {
+            s = SSLSocketFactory.getDefault().createSocket(server, port);//default-ssl = 7000
+            // default-ssl = 7000
+        } else {
+            s = new Socket(server, port);
+            // default-plain = 6667
+        }
+
+        out = new PrintWriter(s.getOutputStream(), true);
+        BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
+
+        new ServerReader(in);
+
+        out.println("USER " + nick + " 0 * :unknown");
+        out.println("NICK " + nick);
+
+        loggedin.acquire();
+    }
+
+    HashSet<String> joined = new HashSet<String>();
+
+    private IRCBot targetBot;
+
+    public void join(String channel) {
+        if ( !channel.matches("[a-zA-Z0-9_-]+")) {
+            return;
+        }
+
+        if (joined.add(channel)) {
+            out.println("JOIN #" + channel);
+        }
+    }
+
+    public void leave(String channel) {
+        if ( !channel.matches("[a-zA-Z0-9_-]+")) {
+            return;
+        }
+
+        if (joined.remove(channel)) {
+            out.println("PART #" + channel);
+        }
+    }
+
+    public void send(String msg, String channel) {
+        if ( !channel.matches("[a-zA-Z0-9_-]+")) {
+            return;
+        }
+
+        out.println("PRIVMSG #" + channel + " :" + msg);
+    }
+
+    public void sendPrivate(String msg, String to) {
+        if ( !to.matches("[a-zA-Z0-9_-]+")) {
+            return;
+        }
+
+        out.println("PRIVMSG " + to + " :" + msg);
+    }
+
+    public void setBot(IRCBot bot) {
+        this.targetBot = bot;
+    }
+
+    public static IRCClient parseCommandLine(String[] commandLine, String nick) throws IOException, InterruptedException {
+        String host = null;
+        int port = 7000;
+        boolean ssl = true;
+
+        for (int i = 0; i < commandLine.length; i++) {
+            String cmd = commandLine[i];
+
+            if (cmd.equals("--no-ssl") || cmd.equals("-u")) {
+                ssl = false;
+            } else if (cmd.equals("--ssl") || cmd.equals("-s")) {
+                ssl = true;
+            } else if (cmd.equals("--host") || cmd.equals("-h")) {
+                host = commandLine[++i];
+            } else if (cmd.equals("--port") || cmd.equals("-p")) {
+                port = Integer.parseInt(commandLine[++i]);
+            } else if (cmd.equals("--nick") || cmd.equals("-n")) {
+                nick = commandLine[++i];
+            } else if (cmd.equals("--help") || cmd.equals("-h")) {
+                System.out.println("Options: [--no-ssl|-u|--ssl|-s|[--host|-h] <host>|[--port|-p] <port>|[--nick|-n] <nick>]*");
+                System.out.println("Requires the -host argument, --ssl is default, last argument of a kind is significant.");
+                throw new Error("Operation caneled");
+            } else {
+                throw new Error("Invalid option (usage with --help): " + cmd);
+            }
+        }
+
+        if (host == null) {
+            throw new Error("--host <host> is missing");
+        }
+
+        return new IRCClient(nick, host, port, ssl);
+    }
+
+}
diff --git a/src/org/cacert/votebot/CAcertVoteAuditor.java b/src/org/cacert/votebot/CAcertVoteAuditor.java
deleted file mode 100644 (file)
index 95fc87d..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.cacert.votebot;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.cacert.votebot.CAcertVoteMechanics.VoteType;
-
-public class CAcertVoteAuditor extends IRCBot {
-
-    public CAcertVoteAuditor(IRCClient c, String toAudit) {
-        super(c);
-        this.toAudit = toAudit;
-        c.join(voteAuxChn);
-    }
-
-    String voteAuxChn = System.getProperty("auditor.target.voteChn", "vote");
-
-    String toAudit;
-
-    long warn = Long.parseLong(System.getProperty("voteBot.warnSecs", "90"));
-
-    long timeout = Long.parseLong(System.getProperty("voteBot.timeoutSecs", "120"));
-
-    CAcertVoteMechanics mech = new CAcertVoteMechanics();
-
-    String[] capturedResults = new String[VoteType.values().length];
-
-    int ctr = -1;
-
-    @Override
-    public synchronized void publicMessage(String from, String channel, String message) {
-        if (channel.equals(voteAuxChn)) {
-            if (from.equals(toAudit)) {
-                if (ctr >= 0) {
-                    capturedResults[ctr++] = message;
-
-                    if (ctr == capturedResults.length) {
-                        String[] reals = mech.closeVote();
-
-                        if (Arrays.equals(reals, capturedResults)) {
-                            System.out.println("Audit for vote was successful.");
-                        } else {
-                            System.out.println("Audit failed! Vote Bot (or Auditor) is probably broken.");
-                        }
-
-                        ctr = -1;
-                    }
-
-                    return;
-                }
-                if (message.startsWith("New Vote: ")) {
-                    System.out.println("detected vote-start");
-
-                    Pattern p = Pattern.compile("New Vote: (.*) has started a vote on \"(.*)\"");
-                    Matcher m = p.matcher(message);
-
-                    if ( !m.matches()) {
-                        System.out.println("error: vote-start malformed");
-                        return;
-                    }
-
-                    mech.callVote(m.group(1), m.group(2));
-                } else if (message.startsWith("Results: ")) {
-                    System.out.println("detected vote-end. Reading results");
-
-                    ctr = 0;
-                }
-            } else {
-                if (ctr != -1) {
-                    System.out.println("Vote after end.");
-                    return;
-                }
-
-                System.out.println("detected vote");
-                mech.evaluateVote(from, message);
-                System.out.println("Current state: " + mech.getCurrentResult());
-            }
-        }
-    }
-
-    @Override
-    public synchronized void privateMessage(String from, String message) {
-
-    }
-
-    @Override
-    public synchronized void join(String cleanReferent, String chn) {
-
-    }
-
-    @Override
-    public synchronized void part(String cleanReferent, String chn) {
-
-    }
-
-    public static void main(String[] args) throws IOException, InterruptedException {
-        IRCClient ic = IRCClient.parseCommandLine(args, "dogcraft_de-Auditor");
-        String targetNick = System.getProperty("auditor.target.nick");
-
-        if (targetNick == null) {
-            System.out.println("use -Dauditor.target.nick=TargetNick to set a target nick");
-            System.exit(0);
-        }
-
-        ic.setBot(new CAcertVoteAuditor(ic, targetNick));
-    }
-}
diff --git a/src/org/cacert/votebot/CAcertVoteBot.java b/src/org/cacert/votebot/CAcertVoteBot.java
deleted file mode 100644 (file)
index 94c2f2d..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-package org.cacert.votebot;
-
-import java.io.IOException;
-
-import org.cacert.votebot.CAcertVoteMechanics.State;
-
-public class CAcertVoteBot extends IRCBot implements Runnable {
-
-    public CAcertVoteBot(IRCClient c) {
-        super(c);
-
-        c.join(meetingChn);
-        c.join(voteAuxChn);
-
-        new Thread(this).start();
-    }
-
-    String meetingChn = System.getProperty("voteBot.meetingChn", "agm");
-
-    String voteAuxChn = System.getProperty("voteBot.voteChn", "vote");
-
-    long warn = Long.parseLong(System.getProperty("voteBot.warnSecs", "90"));
-
-    long timeout = Long.parseLong(System.getProperty("voteBot.timeoutSecs", "120"));
-
-    CAcertVoteMechanics mech = new CAcertVoteMechanics();
-
-    @Override
-    public synchronized void publicMessage(String from, String channel, String message) {
-        if (channel.equals(voteAuxChn)) {
-            sendPublicMessage(voteAuxChn, mech.evaluateVote(from, message));
-        }
-    }
-
-    @Override
-    public synchronized void privateMessage(String from, String message) {
-        if (message.startsWith("vote ")) {
-            String response = mech.callVote(from, message.substring(5));
-            sendPrivateMessage(from, response);
-
-            if (response.startsWith("Sorry,")) {
-                return;
-            }
-
-            anounce("New Vote: " + from + " has started a vote on \"" + mech.getTopic() + "\"");
-            sendPublicMessage(meetingChn, "Please cast your vote in #vote");
-            sendPublicMessage(voteAuxChn, "Please cast your vote in the next " + timeout + " seconds.");
-        }
-    }
-
-    private synchronized void anounce(String msg) {
-        sendPublicMessage(meetingChn, msg);
-        sendPublicMessage(voteAuxChn, msg);
-    }
-
-    public void run() {
-        try {
-            while (true) {
-                while (mech.getState() == State.IDLE) {
-                    Thread.sleep(1000);
-                }
-
-                Thread.sleep(warn * 1000);
-                anounce("Voting on " + mech.getTopic() + " will end in " + (timeout - warn) + " seconds.");
-                Thread.sleep((timeout - warn) * 1000);
-                anounce("Voting on " + mech.getTopic() + " has closed.");
-                String[] res = mech.closeVote();
-                anounce("Results: for " + mech.getTopic() + ":");
-
-                for (int i = 0; i < res.length; i++) {
-                    anounce(res[i]);
-                }
-            }
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-    }
-
-    @Override
-    public synchronized void join(String cleanReferent, String chn) {
-
-    }
-
-    @Override
-    public synchronized void part(String cleanReferent, String chn) {
-
-    }
-
-    public static void main(String[] args) throws IOException, InterruptedException {
-        IRCClient ic = IRCClient.parseCommandLine(args, "dogcraft_de");
-        ic.setBot(new CAcertVoteBot(ic));
-    }
-
-}
diff --git a/src/org/cacert/votebot/CAcertVoteMechanics.java b/src/org/cacert/votebot/CAcertVoteMechanics.java
deleted file mode 100644 (file)
index e331eac..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-package org.cacert.votebot;
-
-import java.util.HashMap;
-import java.util.Map.Entry;
-
-/**
- * Reprenents the voting-automata for voting in IRC chanenls.
- */
-public class CAcertVoteMechanics {
-
-    public static enum VoteType {
-        AYE, NAYE, ABSTAIN
-    }
-
-    public static enum State {
-        RUNNING, IDLE
-    }
-
-    State state = State.IDLE;
-
-    String voteCaller;
-
-    String topic;
-
-    private String vote(String voter, String actor, VoteType type) {
-        votes.put(voter, type);
-
-        if (voter.equals(actor)) {
-            return "Thanks " + actor + " I count your vote as " + type;
-        } else {
-            return "Thanks " + actor + " I count your vote for " + voter + " as " + type;
-        }
-    }
-
-    HashMap<String, VoteType> votes = new HashMap<>();
-
-    private String voteError(String actor) {
-        return "Sorry " + actor + ", I did not understand your vote, your current vote state remains unchanged!";
-    }
-
-    /**
-     * Adds a vote to the current topic. This interprets proxies.
-     *
-     * @param actor
-     *            the person that sent this vote
-     * @param txt
-     *            the text that the person sent.
-     * @return A message to
-     *
-     *         <pre>
-     * actor
-     * </pre>
-     *
-     *         indicating tha result of his action.
-     */
-    public synchronized String evaluateVote(String actor, String txt) {
-        if (state != State.RUNNING) {
-            return "Sorry " + actor + ", but currently no vote is running.";
-        }
-
-        String voter = actor;
-        String value = null;
-
-        if (txt.toLowerCase().matches("^\\s*proxy\\s.*")) {
-            String[] parts = txt.split("\\s+");
-            if (parts.length == 3) {
-                voter = parts[1];
-                value = parts[2];
-            }
-        } else {
-            value = txt.replaceAll("^\\s*|\\s*$", "");
-        }
-
-        if (value == null) {
-            return voteError(actor);
-        } else {
-            value = value.toLowerCase();
-
-            switch (value) {
-            case "aye":
-            case "yes":
-            case "oui":
-            case "ja": {
-                return vote(voter, actor, VoteType.AYE);
-            }
-            case "naye":
-            case "nay":
-            case "no":
-            case "non":
-            case "nein": {
-                return vote(voter, actor, VoteType.NAYE);
-            }
-            case "abstain":
-            case "enthaltung":
-            case "enthalten":
-            case "abs": {
-                return vote(voter, actor, VoteType.ABSTAIN);
-            }
-            }
-        }
-
-        return voteError(actor);
-    }
-
-    /**
-     * A new vote begins.
-     * 
-     * @param from
-     *            the nick that called the vote
-     * @param topic
-     *            the topic of the vote
-     * @return A response to
-     * 
-     *         <pre>
-     * from
-     * </pre>
-     * 
-     *         indicating success or failure.
-     */
-    public synchronized String callVote(String from, String topic) {
-        if (state != State.IDLE) {
-            return "Sorry, a vote is already running";
-        }
-
-        voteCaller = from;
-        this.topic = topic;
-        votes.clear();
-
-        state = State.RUNNING;
-
-        return "Vote started.";
-    }
-
-    /**
-     * Ends a vote.
-     * 
-     * @return An array of Strings containing result status messages.
-     */
-    public synchronized String[] closeVote() {
-        int[] res = new int[VoteType.values().length];
-
-        for (Entry<String, VoteType> i : votes.entrySet()) {
-            res[i.getValue().ordinal()]++;
-        }
-
-        String[] results = new String[VoteType.values().length];
-
-        for (int i = 0; i < res.length; i++) {
-            results[i] = (VoteType.values()[i] + ": " + res[i]);
-        }
-
-        votes.clear();
-        voteCaller = null;
-        state = State.IDLE;
-
-        return results;
-    }
-
-    public String getTopic() {
-        return topic;
-    }
-
-    public State getState() {
-        return state;
-    }
-
-    public String getCurrentResult() {
-        return votes.toString();
-    }
-
-}
diff --git a/src/org/cacert/votebot/IRCBot.java b/src/org/cacert/votebot/IRCBot.java
deleted file mode 100644 (file)
index 2fe40ad..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.cacert.votebot;
-
-public abstract class IRCBot {
-
-    private IRCClient c;
-
-    public IRCBot(IRCClient c) {
-        this.c = c;
-    }
-
-    public abstract void publicMessage(String from, String channel,
-            String message);
-
-    public abstract void privateMessage(String from, String message);
-
-    public void sendPublicMessage(String channel, String message) {
-        c.send(message, channel);
-    }
-
-    public void sendPrivateMessage(String to, String message) {
-        c.sendPrivate(message, to);
-    }
-
-    public abstract void part(String cleanReferent, String chn);
-
-    public abstract void join(String cleanReferent, String chn);
-
-}
diff --git a/src/org/cacert/votebot/IRCClient.java b/src/org/cacert/votebot/IRCClient.java
deleted file mode 100644 (file)
index 52aad37..0000000
+++ /dev/null
@@ -1,256 +0,0 @@
-package org.cacert.votebot;
-
-import java.io.BufferedReader;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.net.Socket;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.concurrent.Semaphore;
-
-import javax.net.ssl.SSLSocketFactory;
-
-public class IRCClient {
-
-    private Semaphore loggedin = new Semaphore(0);
-
-    private PrintWriter out;
-
-    private Socket s;
-
-    class ServerReader implements Runnable {
-
-        private BufferedReader br;
-
-        public ServerReader(BufferedReader br) {
-            this.br = br;
-
-            new Thread(this).start();
-        }
-
-        @Override
-        public void run() {
-            String l;
-
-            try {
-                while ((l = br.readLine()) != null) {
-                    String fullline = l;
-                    // System.out.println(l);
-
-                    if (l.startsWith("PING ")) {
-                        System.out.println("PONG");
-                        out.println("PONG " + l.substring(5));
-                    }
-
-                    String referent = "";
-
-                    if (l.startsWith(":")) {
-                        String[] parts = l.split(" ", 2);
-                        referent = parts[0];
-                        l = parts[1];
-                    }
-
-                    String[] command = l.split(" ", 3);
-
-                    if (command[0].equals("001")) {
-                        loggedin.release();
-                    }
-
-                    if (command[0].equals("PRIVMSG")) {
-                        String msg = command[2].substring(1);
-                        String chnl = command[1];
-
-                        if ( !chnl.startsWith("#")) {
-                            handlePrivMsg(referent, msg);
-                        } else {
-                            handleMsg(referent, chnl, msg);
-                        }
-
-                        log(chnl, fullline);
-                    } else if (command[0].equals("JOIN")) {
-                        String chn = command[1].substring(1);
-                        targetBot.join(cleanReferent(referent), chn.substring(1));
-                        log(chn, fullline);
-                    } else if (command[0].equals("PART")) {
-                        String chn = command[1];
-                        targetBot.part(cleanReferent(referent), chn);
-                        log(chn, fullline);
-                    } else {
-                        System.out.println("unknown line: ");
-                        System.out.println(l);
-                    }
-                }
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-
-        }
-
-        private String cleanReferent(String referent) {
-            String[] parts = referent.split("!");
-
-            if ( !parts[0].startsWith(":")) {
-                System.err.println("invalid public message");
-                return "unknown";
-            }
-
-            return parts[0];
-        }
-
-        HashMap<String, PrintWriter> logs = new HashMap<String, PrintWriter>();
-
-        private void log(String chn, String l) throws IOException {
-            PrintWriter log = logs.get(chn);
-
-            if (log == null) {
-                log = new PrintWriter(new FileOutputStream("irc/log_" + chn), true);
-                logs.put(chn, log);
-            }
-
-            log.println(l);
-        }
-
-        private void handlePrivMsg(String referent, String msg) {
-            String[] parts = referent.split("!");
-
-            if ( !parts[0].startsWith(":")) {
-                System.err.println("invalid private message");
-                return;
-            }
-
-            if (targetBot == null) {
-                System.out.println("dropping message");
-                return;
-            }
-
-            targetBot.privateMessage(parts[0].substring(1), msg);
-        }
-
-        private void handleMsg(String referent, String chnl, String msg) {
-            String[] parts = referent.split("!");
-
-            if ( !parts[0].startsWith(":")) {
-                System.err.println("invalid public message");
-                return;
-            }
-
-            if (targetBot == null) {
-                System.out.println("dropping message");
-                return;
-            }
-
-            if ( !chnl.startsWith("#")) {
-                System.err.println("invalid public message (chnl)");
-                return;
-            }
-
-            targetBot.publicMessage(parts[0].substring(1), chnl.substring(1), msg);
-        }
-
-    }
-
-    public IRCClient(String nick, String server, int port, boolean ssl) throws IOException, InterruptedException {
-        if ( !nick.matches("[a-zA-Z0-9_-]+")) {
-            throw new Error("malformed");
-        }
-
-        if (ssl) {
-            s = SSLSocketFactory.getDefault().createSocket(server, port);//default-ssl = 7000
-            // default-ssl = 7000
-        } else {
-            s = new Socket(server, port);
-            // default-plain = 6667
-        }
-
-        out = new PrintWriter(s.getOutputStream(), true);
-        BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
-
-        new ServerReader(in);
-
-        out.println("USER " + nick + " 0 * :unknown");
-        out.println("NICK " + nick);
-
-        loggedin.acquire();
-    }
-
-    HashSet<String> joined = new HashSet<String>();
-
-    private IRCBot targetBot;
-
-    public void join(String channel) {
-        if ( !channel.matches("[a-zA-Z0-9_-]+")) {
-            return;
-        }
-
-        if (joined.add(channel)) {
-            out.println("JOIN #" + channel);
-        }
-    }
-
-    public void leave(String channel) {
-        if ( !channel.matches("[a-zA-Z0-9_-]+")) {
-            return;
-        }
-
-        if (joined.remove(channel)) {
-            out.println("PART #" + channel);
-        }
-    }
-
-    public void send(String msg, String channel) {
-        if ( !channel.matches("[a-zA-Z0-9_-]+")) {
-            return;
-        }
-
-        out.println("PRIVMSG #" + channel + " :" + msg);
-    }
-
-    public void sendPrivate(String msg, String to) {
-        if ( !to.matches("[a-zA-Z0-9_-]+")) {
-            return;
-        }
-
-        out.println("PRIVMSG " + to + " :" + msg);
-    }
-
-    public void setBot(IRCBot bot) {
-        this.targetBot = bot;
-    }
-
-    public static IRCClient parseCommandLine(String[] commandLine, String nick) throws IOException, InterruptedException {
-        String host = null;
-        int port = 7000;
-        boolean ssl = true;
-
-        for (int i = 0; i < commandLine.length; i++) {
-            String cmd = commandLine[i];
-
-            if (cmd.equals("--no-ssl") || cmd.equals("-u")) {
-                ssl = false;
-            } else if (cmd.equals("--ssl") || cmd.equals("-s")) {
-                ssl = true;
-            } else if (cmd.equals("--host") || cmd.equals("-h")) {
-                host = commandLine[++i];
-            } else if (cmd.equals("--port") || cmd.equals("-p")) {
-                port = Integer.parseInt(commandLine[++i]);
-            } else if (cmd.equals("--nick") || cmd.equals("-n")) {
-                nick = commandLine[++i];
-            } else if (cmd.equals("--help") || cmd.equals("-h")) {
-                System.out.println("Options: [--no-ssl|-u|--ssl|-s|[--host|-h] <host>|[--port|-p] <port>|[--nick|-n] <nick>]*");
-                System.out.println("Requires the -host argument, --ssl is default, last argument of a kind is significant.");
-                throw new Error("Operation caneled");
-            } else {
-                throw new Error("Invalid option (usage with --help): " + cmd);
-            }
-        }
-
-        if (host == null) {
-            throw new Error("--host <host> is missing");
-        }
-
-        return new IRCClient(nick, host, port, ssl);
-    }
-
-}