summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-01-17 03:33:31 +0100
committerSven Gothel <[email protected]>2013-01-17 03:33:31 +0100
commit4529bf562834b6929faa41813988934e7b8854f9 (patch)
treee8faad5e1835fbf506c2dd53645c891a3fce6073
Initial Commit
-rw-r--r--.classpath7
-rw-r--r--.project17
-rw-r--r--LICENSE.txt11
-rw-r--r--build.xml51
-rw-r--r--lib/pircbot-1.5.0-java.zipbin0 -> 45683 bytes
-rw-r--r--lib/pircbot-1.5.0.jarbin0 -> 32258 bytes
-rwxr-xr-xscripts/jogamp-log01.sh3
-rw-r--r--src/org/jogamp/jabot/irc/CatOut.java92
-rw-r--r--src/org/jogamp/jabot/util/TimeTool.java55
9 files changed, 236 insertions, 0 deletions
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..7aea4af
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="lib" path="lib/pircbot-1.5.0.jar" sourcepath="lib/pircbot-1.5.0-java.zip"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="build/classes"/>
+</classpath>
diff --git a/.project b/.project
new file mode 100644
index 0000000..785ea16
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>JABot</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/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..cff016e
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,11 @@
+JABot
+ Copyright 2013 JogAmp Community. All rights reserved.
+
+ Licence: This software product is licensed under the GNU General Public License (GPL) Version 3.
+ http://www.gnu.org/licenses/gpl.html
+
+Using following components:
+
+ PircBot 1.5.0
+ URL: http://www.jibble.org/pircbot.php
+ Licence: This software product is OSI Certified Open Source Software, available under the GNU General Public License (GPL).
diff --git a/build.xml b/build.xml
new file mode 100644
index 0000000..f21afdf
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="JABot" default="all">
+
+ <property name="project.root" value="." />
+
+ <property name="rootrel.build" value="build" />
+ <property name="build" location="${project.root}/${rootrel.build}" />
+ <property name="lib" location="${project.root}/lib" />
+
+ <target name="init">
+ <property name="pircbot.jar" value="pircbot-1.5.0.jar" />
+ <property name="jabot.jar" value="${build}/jabot.jar" />
+ <property name="classes" value="${build}/classes" />
+ <property name="src" value="${project.root}/src" />
+ </target>
+
+ <target name="all" depends="init">
+ <mkdir dir="${classes}" />
+ <path id="jabot.classpath">
+ <pathelement location="${lib}/${pircbot.jar}" />
+ </path>
+ <javac destdir="${classes}"
+ includeantruntime="false"
+ encoding="UTF-8">
+ <src path="${src}" />
+ <classpath refid="jabot.classpath" />
+ </javac>
+ <jar destfile="${jabot.jar}">
+ <fileset dir="${classes}">
+ <include name="**" />
+ </fileset>
+ <archives>
+ <zips>
+ <fileset dir="${lib}" includes="${pircbot.jar}" />
+ </zips>
+ </archives>
+ <fileset dir="${src}">
+ <include name="**/*.cfg" />
+ <include name="**/*.xml" />
+ <include name="**/*.txt" />
+ </fileset>
+ </jar>
+ </target>
+
+ <target name="clean" depends="init">
+ <delete includeEmptyDirs="true" quiet="true">
+ <fileset dir="${build}" />
+ </delete>
+ </target>
+
+ </project>
diff --git a/lib/pircbot-1.5.0-java.zip b/lib/pircbot-1.5.0-java.zip
new file mode 100644
index 0000000..cdf89b9
--- /dev/null
+++ b/lib/pircbot-1.5.0-java.zip
Binary files differ
diff --git a/lib/pircbot-1.5.0.jar b/lib/pircbot-1.5.0.jar
new file mode 100644
index 0000000..dcc0a7e
--- /dev/null
+++ b/lib/pircbot-1.5.0.jar
Binary files differ
diff --git a/scripts/jogamp-log01.sh b/scripts/jogamp-log01.sh
new file mode 100755
index 0000000..918b3b9
--- /dev/null
+++ b/scripts/jogamp-log01.sh
@@ -0,0 +1,3 @@
+#! /bin/sh
+
+java -cp build/jabot.jar org.jogamp.jabot.irc.CatOut -login jogamp -name CatOut -server irc.freenode.net -channel "#jogamp"
diff --git a/src/org/jogamp/jabot/irc/CatOut.java b/src/org/jogamp/jabot/irc/CatOut.java
new file mode 100644
index 0000000..af2f04d
--- /dev/null
+++ b/src/org/jogamp/jabot/irc/CatOut.java
@@ -0,0 +1,92 @@
+package org.jogamp.jabot.irc;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.jibble.pircbot.PircBot;
+import org.jogamp.jabot.util.TimeTool;
+
+public class CatOut extends PircBot {
+
+ private final TimeZone timeZone;
+ private final Locale locale;
+ private final Calendar calendar;
+
+ public CatOut() {
+ this(TimeTool.getNearZuluTimeZone(), Locale.getDefault());
+ }
+
+ public CatOut(TimeZone timeZone, Locale locale) {
+ this.timeZone = timeZone;
+ this.locale = locale;
+ calendar = new GregorianCalendar(timeZone, locale);
+ }
+
+ public final TimeZone getTimeZone() { return timeZone; }
+ public final Locale getLocale() { return locale; }
+
+ /** Returns timestamp of internal Calendar: YYYYMMDD HH:MM:SS (TMZ) */
+ public final String getTimeStamp() {
+ return TimeTool.getTimeStamp(calendar);
+ }
+
+ public final void setLoginAndName(String login, String nick) {
+ super.setLogin(login);
+ super.setName(nick);
+ }
+
+ /** Updates internal Calendar w/ current time */
+ public final void tick() {
+ calendar.setTimeInMillis(System.currentTimeMillis());
+ }
+
+ public void onMessage(String channel, String sender,
+ String login, String hostname, String message) {
+ tick();
+ System.out.println(getTimeStamp()+" <"+sender+"/"+login+">: "+message);
+ }
+
+ public static void main(String[] args) throws Exception {
+ final String login, name, server, channel;
+ final boolean verbose;
+ {
+ String _login=null, _name=null, _server=null, _channel=null;
+ boolean _verbose=false;
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-login")) {
+ i++;
+ _login = args[i];
+ } else if(args[i].equals("-name")) {
+ i++;
+ _name = args[i];
+ } else if(args[i].equals("-server")) {
+ i++;
+ _server = args[i];
+ } else if(args[i].equals("-channel")) {
+ i++;
+ _channel= args[i];
+ } else if(args[i].equals("-verbose")) {
+ _verbose=true;
+ }
+ }
+ if( null == _login ||
+ null == _name ||
+ null == _server ||
+ null == _channel ) {
+ System.err.println("Incomplete commandline, use "+CatOut.class.getName()+" -login VAL -name VAL -server VAL -channel VAL [-verbose]");
+ return;
+ }
+ login=_login; name=_name;
+ server=_server; channel=_channel;
+ verbose=_verbose;
+ }
+
+ final CatOut bot = new CatOut();
+ bot.setVerbose(verbose);
+ bot.setLoginAndName(login, name);
+ bot.connect(server);
+ bot.joinChannel(channel);
+ }
+}
diff --git a/src/org/jogamp/jabot/util/TimeTool.java b/src/org/jogamp/jabot/util/TimeTool.java
new file mode 100644
index 0000000..de90361
--- /dev/null
+++ b/src/org/jogamp/jabot/util/TimeTool.java
@@ -0,0 +1,55 @@
+package org.jogamp.jabot.util;
+
+import java.util.Calendar;
+import java.util.TimeZone;
+
+public class TimeTool {
+ public static String UTC_TZ = "UTC";
+ public static String[] ZERO_TZs = { UTC_TZ, "GMT", "GMT0", "Zulu" };
+
+ /** Returns closest to Zulu/UTC TimeZone w/ shortest ID */
+ public static TimeZone getNearZuluTimeZone() {
+ TimeZone tz = null;
+ // Get preferred ..
+ for(int i=0; null == tz && i<ZERO_TZs.length; i++) {
+ tz = TimeZone.getTimeZone(ZERO_TZs[i]);
+ }
+ if(null == tz) {
+ // Get shortest ..
+ final String[] ids = TimeZone.getAvailableIDs(0);
+ if( null != ids && ids.length > 0 ) {
+ int min_len = Integer.MAX_VALUE;
+ int min_idx = -1;
+ for(int i=0; i<ids.length; i++) {
+ final int len = ids[i].length();
+ if( len < min_len ) {
+ min_len = len;
+ min_idx = i;
+ }
+ }
+ tz = TimeZone.getTimeZone(ids[min_idx]);
+ }
+ }
+ if(null == tz) {
+ // last resort - default
+ tz = TimeZone.getDefault();
+ }
+ return tz;
+ }
+
+ /** Returns timestamp of internal Calendar: YYYYMMDD HH:MM:SS (TMZ) */
+ public static String getTimeStamp(final Calendar calendar) {
+ final int year, month, day, hour, minute, seconds;
+ {
+ year = calendar.get(Calendar.YEAR);
+ month = calendar.get(Calendar.MONTH) + 1; // Jan - 1
+ day = calendar.get(Calendar.DAY_OF_MONTH);
+ hour = calendar.get(Calendar.HOUR_OF_DAY);
+ minute = calendar.get(Calendar.MINUTE);
+ seconds = calendar.get(Calendar.SECOND);
+ }
+ return String.format("%04d%02d%02d %02d:%02d:%02d (%s)",
+ year, month, day, hour, minute, seconds, calendar.getTimeZone().getID());
+ }
+
+}