From: Scott Worley Date: Fri, 3 Aug 2012 07:13:30 +0000 (-0700) Subject: Streamline /command checking a little X-Git-Url: http://git.scottworley.com/reliable-chat/commitdiff_plain/5a6c082a931b94c5e3593b1abb6eafeb2b4ef258 Streamline /command checking a little --- diff --git a/webclient/rc.html b/webclient/rc.html index 632956b..2bb1610 100644 --- a/webclient/rc.html +++ b/webclient/rc.html @@ -195,36 +195,28 @@ } } + 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) { - var input = document.input.say.value; + rcinput(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); } } //-->