ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/client/alerters/IRC__Alerter.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/alerters/IRC__Alerter.java (file contents):
Revision 1.30.2.3 by tdb, Tue Feb 5 18:00:15 2002 UTC vs.
Revision 1.30.2.4 by tdb, Tue Feb 5 21:40:03 2002 UTC

# Line 224 | Line 224 | public class IRC__Alerter extends AlerterSkeleton {
224           *
225           * @throws IOException if there is any problem initialising
226           */
227 <        public void init() throws IOException {
227 >        private void init() throws IOException {
228              _logger.write(this.toString(), Logger.DEBUG, "Initialising IRCBot...");
229              
230              // get a hook on the configuration system
# Line 245 | Line 245 | public class IRC__Alerter extends AlerterSkeleton {
245              }
246              
247              // get hold of the user details and nickname list
248 <            String user, comment, finger, nickList;
248 >            String user, nickList;
249              try {
250                  user = cp.getProperty(_name, "Alerter.IRC.user");
251                comment = cp.getProperty(_name, "Alerter.IRC.comment");
252                finger = cp.getProperty(_name, "Alerter.IRC.finger");
251                  nickList = cp.getProperty(_name, "Alerter.IRC.nickList");
252              } catch (PropertyNotFoundException e) {
253                  _logger.write(this.toString(), Logger.ERROR, "Configuration error: "+e);
254                  throw new IOException("Can't get user/nickname details due to configuration error");
255              }
256              
257 +            // get hold of comment and finger information
258 +            //  -- we're not too fussed if these aren't set
259 +            String comment = "Alerter.IRC.comment is undefined";
260 +            String finger = "Alerter.IRC.finger is undefined";
261 +            try {
262 +                comment = cp.getProperty(_name, "Alerter.IRC.comment");
263 +                finger = cp.getProperty(_name, "Alerter.IRC.finger");
264 +            } catch (PropertyNotFoundException e) {
265 +                _logger.write(this.toString(), Logger.WARNING, "Configuration warning, using default: "+e);
266 +            }
267 +            
268              // put these details into the bot
269              this.setLogin(user);
270              this.setVersion(comment);
# Line 326 | Line 335 | public class IRC__Alerter extends AlerterSkeleton {
335           *
336           * @param message The message to send
337           */
338 <        public void sendMessage(String message) {
338 >        private void sendMessage(String message) {
339              sendMessage(_channel, message);
340          }
341          
# Line 364 | Line 373 | public class IRC__Alerter extends AlerterSkeleton {
373           * @param message The message sent
374           */
375          public void onMessage(String channel, String sender, String login, String hostname, String message) {
376 <            if(isForMe(message)) {
377 <                handleInput(message, channel);
376 >            String trimmedMessage = isForMe(message);
377 >            // if trimmedMessage is null, it's not for us
378 >            if(trimmedMessage != null) {
379 >                handleInput(trimmedMessage, channel);
380              }
381          }
382          
# Line 470 | Line 481 | public class IRC__Alerter extends AlerterSkeleton {
481              
482              // see if the message matches (loosely!) any
483              // of our known commands
484 <            if(message.indexOf(stopCommand) != -1) {
484 >            if(message.equalsIgnoreCase(stopCommand)) {
485                  _active = false;
486                  sendMessage(source, "alerts have been stopped");
487              }
488 <            else if(message.indexOf(startCommand) != -1) {
488 >            else if(message.equalsIgnoreCase(startCommand)) {
489                  _active = true;
490                  sendMessage(source, "alerts have been activated");
491              }
492              // this needs to go before lastAlertCommand if it contains
493              // the same words as the lastAlertCommand.
494 <            else if(message.indexOf(timeSinceLastAlertCommand) != -1) {
494 >            else if(message.equalsIgnoreCase(timeSinceLastAlertCommand)) {
495                  if(_lastAlertTime != -1) {
496                      long uptime = (System.currentTimeMillis() - _lastAlertTime) / 1000;
497                      String uptimeText = DateUtils.formatTime(uptime, "%DAYS% days, %HOURS% hours, %MINS% mins, and %SECS% secs");
# Line 490 | Line 501 | public class IRC__Alerter extends AlerterSkeleton {
501                      sendMessage(source, "I've never sent an alert!");
502                  }
503              }
504 <            else if(message.indexOf(lastAlertCommand) != -1) {
504 >            else if(message.equalsIgnoreCase(lastAlertCommand)) {
505                  if(_lastAlertTime != -1) {
506                      String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.UK).format(new Date(_lastAlertTime));
507                      sendMessage(source, "last alert was at "+date+"; "+_lastAlert);
# Line 500 | Line 511 | public class IRC__Alerter extends AlerterSkeleton {
511                  }
512                  
513              }
514 <            else if(message.indexOf(joinCommand) != -1) {
514 >            else if(message.equalsIgnoreCase(joinCommand)) {
515                  String joinCmd = joinCommand;
516                  String newChan = message.substring(message.indexOf(joinCmd) + joinCmd.length() + 1);
517                  int endOfChan = newChan.indexOf(" ");
# Line 516 | Line 527 | public class IRC__Alerter extends AlerterSkeleton {
527                      _channel = newChan;
528                  }
529              }
530 <            else if(message.indexOf(nickChangeCommand) != -1) {
530 >            else if(message.equalsIgnoreCase(nickChangeCommand)) {
531                  String nickChangeCmd = nickChangeCommand;
532                  String newNick = message.substring(message.indexOf(nickChangeCmd) + nickChangeCmd.length() + 1);
533                  int endOfNick = newNick.indexOf(" ");
# Line 526 | Line 537 | public class IRC__Alerter extends AlerterSkeleton {
537                  newNick = newNick.substring(0, endOfNick);
538                  changeNick(newNick);
539              }
540 <            else if(message.indexOf(versionCommand) != -1) {
541 <                sendMessage(source, "I am version "+REVISION.substring(11, REVISION.length() -2)+" of the i-scream alerting bot");
540 >            else if(message.equalsIgnoreCase(versionCommand)) {
541 >                sendMessage(source, "I am version "+REVISION.substring(11, REVISION.length()-2)+" of the i-scream alerting bot");
542              }
543 <            else if(message.indexOf(helpCommand) != -1) {
543 >            else if(message.equalsIgnoreCase(helpCommand)) {
544                  sendMessage(source, "Hello, I am the i-scream alerting bot version "+REVISION.substring(11, REVISION.length() -2));
545                  sendMessage(source, "I understand the following commands;");
546                  sendMessage(source, stopCommand);
# Line 542 | Line 553 | public class IRC__Alerter extends AlerterSkeleton {
553                  sendMessage(source, timeSinceLastAlertCommand);
554                  sendMessage(source, helpCommand);
555              }
556 <            else if(message.indexOf(statCommand) != -1) {
556 >            else if(message.equalsIgnoreCase(statCommand)) {
557                  sendMessage(source, "I have sent a total of "+_alertCount+" alerts, and ignored a total of "+_ignoredCount+"!");
558              }
559 <            else if(message.indexOf(uptimeCommand) != -1) {
559 >            else if(message.equalsIgnoreCase(uptimeCommand)) {
560                  long uptime = (System.currentTimeMillis() - _startTime) / 1000;
561                  String uptimeText = DateUtils.formatTime(uptime, "%DAYS% days, %HOURS% hours, %MINS% mins, and %SECS% secs");
562                  sendMessage(source, "I have been running for "+uptimeText);
563              }
564 <            else if(message.indexOf("ping") != -1) {
564 >            else if(message.equalsIgnoreCase("ping")) {
565                  sendMessage(source, "pong");
566              }
567 <            else if(message.indexOf("do a jibble dance") != -1) {
567 >            else if(message.equalsIgnoreCase("do a jibble dance")) {
568                  // little joke :)
569                  sendAction(source, "jives to the funky beat shouting \"ii--screeeaaammm\"");
570              }
# Line 572 | Line 583 | public class IRC__Alerter extends AlerterSkeleton {
583           * Quick method to check if the message appears
584           * to be directed at us. We simply check to see
585           * if it starts with our nick in some fashion.
586 +         * This will return null if the message is not
587 +         * for us - thus allowing this method to perform
588 +         * two tasks at once.
589           *
590           * @param message the message to check
591 <         * @return if the message is for us
591 >         * @return the message (with our nick removed), or null if it's not for us.
592           */
593 <        private boolean isForMe(String message) {
593 >        private String isForMe(String message) {
594 >            // change to lower case to remove
595 >            // case ambiguities
596              String nick = _nickname.toLowerCase();
597              String msg = message.toLowerCase();
598              if(msg.startsWith(nick + ", ") ||
599                 msg.startsWith(nick + ": ") ||
600                 msg.startsWith(nick + " ")) {
601 <                return true;
601 >                // NOTE that the 1 here is hardcoded to be the length
602 >                // of the above 'extra' character (eg , or :)
603 >                return message.substring(nick.length()+1).trim();
604              }
605              else {
606 <                return false;
606 >                return null;
607              }
608          }
609          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines