]> Pileus Git - ~andy/spades/commitdiff
Add /msg command
authorAndy Spencer <andy753421@gmail.com>
Wed, 11 Dec 2013 03:29:47 +0000 (03:29 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 11 Dec 2013 03:29:47 +0000 (03:29 +0000)
src/org/pileus/spades/Message.java

index 717677c35e3faddbefcc5f5ecf9ab8aafe8eb8e9..d12f42fce69e908e8a57ab81c37111cabe69d8e7 100644 (file)
@@ -104,7 +104,7 @@ public class Message
        private static final String  reMsg  = "(:([^ ]+) +)?(([A-Z0-9]+) +)(([^ ]+)[= ]+)?(([^: ]+) *)?(:(.*))?";
        private static final String  reFrom = "([^! ]+)!.*";
        private static final String  reTo   = "(([^ :,]*)[:,] *)?(.*)";
-       private static final String  reCmd  = "/([a-z]+)( +(.*))?";
+       private static final String  reCmd  = "/([a-z]+)(?: +([^ ]*)(?: +(.*))?)?";
 
        private static final Pattern ptMsg  = Pattern.compile(reMsg);
        private static final Pattern ptFrom = Pattern.compile(reFrom);
@@ -210,7 +210,8 @@ public class Message
                        return false;
 
                String cmd = notnull(mr.group(1));
-               String arg = notnull(mr.group(3));
+               String arg = notnull(mr.group(2));
+               String txt = notnull(mr.group(3));
 
                // Parse commands
                if (cmd.matches("j(oin)?")) {
@@ -229,6 +230,15 @@ public class Message
                        this.line = this.cmd + " :" + arg;
                }
 
+               if (cmd.matches("msg") && arg != null) {
+                       Os.debug("Message: /msg");
+                       this.type = Type.PRIVMSG;
+                       this.cmd  = "PRIVMSG";
+                       this.dst  = arg;
+                       this.msg  = txt;
+                       this.line = this.cmd + " " + arg + " :" + txt;
+               }
+
                // Print warning if command is not recognized
                if (this.line == null)
                        Os.debug("Message: unknown command");