]> git.scottworley.com Git - reliable-chat/blobdiff - webclient/rc.html
Streamline /command checking a little
[reliable-chat] / webclient / rc.html
index 8d1c84a02755210f083e4277fb739692d9a27e88..2bb1610ac7930e2c03f0a46fcc5345dc15814589 100644 (file)
                                                var messages = JSON.parse(rtxt);
                                                if (messages != null) {
                                                        rcreceivemessages(server, messages);
                                                var messages = JSON.parse(rtxt);
                                                if (messages != null) {
                                                        rcreceivemessages(server, messages);
-                                                       window.parent.postMessage(rtxt, "*");
                                                        delay = 40;
                                                        if (messages.length >= 1 && "Time" in messages[messages.length-1]) {
                                                                since[server] = messages[messages.length-1]["Time"];
                                                        delay = 40;
                                                        if (messages.length >= 1 && "Time" in messages[messages.length-1]) {
                                                                since[server] = messages[messages.length-1]["Time"];
                        status_indicator.setAttribute("class", "sad");
                        document.getElementById("status").appendChild(status_indicator);
                }
                        status_indicator.setAttribute("class", "sad");
                        document.getElementById("status").appendChild(status_indicator);
                }
-               if (rcnick() == 'anonymous') {
-                       rcaddmessagetohistory("-!- Set your nick with /nick");
-               }
        }
 
        function rcsend(d, message) {
        }
 
        function rcsend(d, message) {
                }
        }
 
                }
        }
 
+       function rcinput(input) {
+               var message;
+               var re = /^\/([a-z]+) (.*)/
+               var match = re.exec(input);
+               if (match && match[1] == 'me') {
+                       message = "* " + rcnick() + "  " + match[2];
+               } else if (match && match[1] == 'nick') {
+                       message = "*** " + rcnick() + " is now known as " + match[2];
+                       rcsetnick(match[2]);
+               } else {
+                       message = "<" + rcnick() + "> " + input;
+               }
+
+               var d = rcaddmessagetohistory(message);
+               rcsend(d, message);
+       }
+
        function rckeydown(event) {
                if (event.keyCode == 13) {
        function rckeydown(event) {
                if (event.keyCode == 13) {
-                       var input = document.input.say.value;
+                       rcinput(document.input.say.value);
                        document.input.say.value = "";
                        
                        document.input.say.value = "";
                        
-                       // Check nick change
-                       var message;
-                       var re = /^\/nick (.*)/;
-                       var match = re.exec(input);
-                       if (match) {
-                               message = "*** " + rcnick() + " is now known as " + match[1];
-                               rcsetnick(match[1]);
-                       } else {
-                               message = "<" + rcnick() + "> " + input;
-                       }
-
-                       // /me support
-                       var message;
-                       var re = /^\/me (.*)/;
-                       var match = re.exec(input);
-                       var inputme = input.substring(4);
-                       if (match) {
-                               message = "* " + rcnick() + "  " + inputme;
-                       } else {
-                               message = "<" + rcnick() + "> " + input;
-                       }
-
-                       // Say the message
-                       var d = rcaddmessagetohistory(message);
-                       rcsend(d, message);
-
-                       // Remind people to set their nick
-                       if (rcnick() == 'anonymous') {
-                               rcaddmessagetohistory("-!- Set your nick with /nick");
-                       }
                }
        }
   //--><!]]></script>
                }
        }
   //--><!]]></script>