diff options
author | Sven Gothel <[email protected]> | 2013-01-17 03:33:31 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-01-17 03:33:31 +0100 |
commit | 4529bf562834b6929faa41813988934e7b8854f9 (patch) | |
tree | e8faad5e1835fbf506c2dd53645c891a3fce6073 /src/org/jogamp/jabot/irc/CatOut.java |
Initial Commit
Diffstat (limited to 'src/org/jogamp/jabot/irc/CatOut.java')
-rw-r--r-- | src/org/jogamp/jabot/irc/CatOut.java | 92 |
1 files changed, 92 insertions, 0 deletions
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); + } +} |