X-Git-Url: http://pileus.org/git/?p=~andy%2Fspades;a=blobdiff_plain;f=src%2Forg%2Fpileus%2Fspades%2FMessage.java;h=ad71c2d5b2dbdee779b4ca3241d3575f9971844f;hp=1f52ebe133443e167c216c0e0e82ea0108e8daef;hb=254a01823368fd3692476fb87022805b6e4a184f;hpb=e3336e9ab000713f7c2f9cbfdf2d29ac402353fa diff --git a/src/org/pileus/spades/Message.java b/src/org/pileus/spades/Message.java index 1f52ebe..ad71c2d 100644 --- a/src/org/pileus/spades/Message.java +++ b/src/org/pileus/spades/Message.java @@ -1,5 +1,6 @@ package org.pileus.spades; +import java.util.Date; import java.util.regex.Pattern; import java.util.regex.Matcher; @@ -7,18 +8,26 @@ public class Message { /* Enumerations */ enum Type { - OTHER, - PRIVMSG, - TOPIC, - NAMES, - ERROR, - CAP, - AUTH, - AUTHOK, - AUTHFAIL, + OTHER, // Unknown message type + PRIVMSG, // Private message + TOPIC, // Display current topic + NAMES, // Display user names + ERROR, // Error message from server + CAP, // Server capabilities + AUTH, // Authentication message + AUTHOK, // Authentication succeeded + AUTHFAIL, // Authentication failed }; - /* Constnats */ + enum How { + OTHER, // Unknown message type + CHANNEL, // Normal message to a channel + MENTION, // User was mentioned in message text + DIRECT, // Message directed towards user + PRIVMSG // Private message to user only + }; + + /* Constants */ private final String reMsg = "(:([^ ]+) +)?(([A-Z0-9]+) +)(([^ ]+)[= ]+)?(([^: ]+) *)?(:(.*))?"; private final String reFrom = "([^! ]+)!.*"; private final String reTo = "(([^ :,]*)[:,] *)?(.*)"; @@ -28,6 +37,8 @@ public class Message private static Pattern ptTo = null; /* Public data */ + public Date time = null; + public String line = ""; public String src = ""; @@ -37,6 +48,7 @@ public class Message public String msg = ""; public Type type = Type.OTHER; + public How how = How.OTHER; public String from = ""; public String to = ""; public String txt = ""; @@ -57,17 +69,19 @@ public class Message this.line = this.cmd + " " + this.dst + " :" + this.msg; } - public Message(String line) + public Message(String line, String name) { // Initialize regexes if (ptMsg == null) ptMsg = Pattern.compile(reMsg); if (ptFrom == null) ptFrom = Pattern.compile(reFrom); if (ptTo == null) ptTo = Pattern.compile(reTo); + // Set time stamp + this.time = new Date(); + // Cleanup line line = line.replaceAll("\\s+", " "); line = line.replaceAll("^ | $", ""); - line = line.replaceAll("\003[0-9]*", ""); this.line = line; // Split line into parts @@ -106,6 +120,12 @@ public class Message else if (this.cmd.equals("905")) this.type = Type.AUTHFAIL; else if (this.cmd.equals("906")) this.type = Type.AUTHFAIL; else if (this.cmd.equals("907")) this.type = Type.AUTHFAIL; + + // Set directed + if (this.dst.equals(name)) this.how = How.PRIVMSG; + else if (this.to.equals(name)) this.how = How.DIRECT; + else if (this.msg.contains(name)) this.how = How.MENTION; + else if (this.type == Type.PRIVMSG) this.how = How.CHANNEL; } public void debug()