public String requestChat ( SpeakService speakSvc , String text , boolean record ) { if ( text . startsWith ( "/" ) ) { // split the text up into a command and arguments String command = text . substring ( 1 ) . toLowerCase ( ) ; String [ ] hist = new String [ 1 ] ; String args = "" ; int sidx = text . indexOf ( " " ) ; if ( sidx != - 1 ) { command = text . substring ( 1 , sidx ) . toLowerCase ( ) ; args = text . substring ( sidx + 1 ) . trim ( ) ; } Map < String , CommandHandler > possibleCommands = getCommandHandlers ( command ) ; switch ( possibleCommands . size ( ) ) { case 0 : StringTokenizer tok = new StringTokenizer ( text ) ; return MessageBundle . tcompose ( "m.unknown_command" , tok . nextToken ( ) ) ; case 1 : Map . Entry < String , CommandHandler > entry = possibleCommands . entrySet ( ) . iterator ( ) . next ( ) ; String cmdName = entry . getKey ( ) ; CommandHandler cmd = entry . getValue ( ) ; String result = cmd . handleCommand ( speakSvc , cmdName , args , hist ) ; if ( ! result . equals ( ChatCodes . SUCCESS ) ) { return result ; } if ( record ) { // get the final history-ready command string hist [ 0 ] = "/" + ( ( hist [ 0 ] == null ) ? command : hist [ 0 ] ) ; // remove from history if it was present and add it to the end addToHistory ( hist [ 0 ] ) ; } return result ; default : StringBuilder buf = new StringBuilder ( ) ; for ( String pcmd : Sets . newTreeSet ( possibleCommands . keySet ( ) ) ) { buf . append ( " /" ) . append ( pcmd ) ; } return MessageBundle . tcompose ( "m.unspecific_command" , buf . toString ( ) ) ; } } // if not a command then just speak String message = text . trim ( ) ; if ( StringUtil . isBlank ( message ) ) { // report silent failure for now return ChatCodes . SUCCESS ; } return deliverChat ( speakSvc , message , ChatCodes . DEFAULT_MODE ) ; }
Parses and delivers the supplied chat message . Slash command processing and mogrification are performed and the message is added to the chat history if appropriate .