예제 #1
0
  @Test
  public void testPipe() {
    IRCBot mockBot = new IRCBot(false);
    ChannelInfoPipe pipe = new ChannelInfoPipe(mockBot, "#targetChan");

    IRCMsg negativeMsg =
        IRCMsgFactory.createIRCMsg(
            ":[email protected] NOTICE mockbot :Information for channel \u0002#alreadyexists\u0002:");
    IRCMsg positiveMsg =
        IRCMsgFactory.createIRCMsg(
            ":[email protected] NOTICE mockbot :Channel \u0002#targetChan\u0002 isn't registered.");

    Assert.assertFalse(pipe.isActivePipe());
    pipe.setIsActivePipe(true);
    Assert.assertTrue(pipe.isActivePipe());
    Assert.assertFalse(pipe.isActionSent());
    Assert.assertFalse(pipe.isActionSuccess());
    Assert.assertFalse(pipe.isActionFailure());

    //  Run any message through to trigger a send action
    pipe.executePipe(negativeMsg);

    Assert.assertTrue(pipe.isActionSent());
    Assert.assertEquals(1, mockBot.getOutboundMsgQ().size());
    Assert.assertEquals("chanserv info #targetChan", mockBot.getOutboundMsgQ().poll());
    Assert.assertTrue(pipe.isActionSent());
    Assert.assertFalse(pipe.isActionSuccess());
    Assert.assertFalse(pipe.isActionFailure());

    //  Run negative msg through and confirm state
    pipe.executePipe(negativeMsg);

    Assert.assertTrue(pipe.isActionSent());
    Assert.assertEquals(1, mockBot.getOutboundMsgQ().size());
    Assert.assertEquals(
        "PRIVMSG #startchan :Channel #targetChan is already registered.",
        mockBot.getOutboundMsgQ().poll());
    Assert.assertTrue(pipe.isActionSent());
    Assert.assertFalse(pipe.isActionSuccess());
    Assert.assertTrue(pipe.isActionFailure());

    //  Reset isActionFailure to false
    pipe.setActionFailure(false);

    //  Run positive msg through and confirm state
    pipe.executePipe(positiveMsg);
    Assert.assertEquals(1, mockBot.getOutboundMsgQ().size());
    Assert.assertEquals(
        "PRIVMSG #startchan :Channel #targetChan is not registered.",
        mockBot.getOutboundMsgQ().poll());
    Assert.assertTrue(pipe.isActionSuccess());
    Assert.assertFalse(pipe.isActionFailure());
  }
예제 #2
0
  public IRCMsg handleMsg(String rawMsg) {
    if (!isPing(rawMsg)) {

      log.info("IN: " + rawMsg);

      IRCMsg msg = createAndDecorateMsg(rawMsg);

      //	Check to see if this is an expected msg
      getInterruptListeners().iterateAcrossObjects(msg);

      //	Check to see if the bot should perform an action, like greet someone
      getEventListeners().iterateAcrossObjects(msg);

      //	Check to see if this is a bot command
      if (msgIsCommand(msg)) {

        log.info("BotCommand called.");
        msg = stripLeadingWordFromTrailing(msg);
        botCommandListeners.iterateAcrossObjects(msg);
      }

      //  Check to see if there are any active pipelines
      getPipelines().iterateAcrossObjects(msg);

      return interpretMsg(msg);
    } else {
      //	Wrap the raw PING msg, mostly for unit test purposes
      return IRCMsgFactory.createIRCMsg(rawMsg);
    }
  }
예제 #3
0
 public IRCMsg createAndDecorateMsg(String rawMsg) {
   IRCMsg msg = IRCMsgFactory.createIRCMsg(rawMsg);
   return IRCMessageDecorator.decorateMessage(bot.getConfigs(), msg);
 }