summaryrefslogtreecommitdiffstats
path: root/src/org/jogamp/jabot/irc/CatOut.java
blob: af2f04d130ed5bc2b454e441a137c195cca1aa8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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);
    }    
}