Exemplo n.º 1
0
  public IRCMsgHandler(IRCBot bot) {

    this.bot = bot;

    botnick = bot.getConfigs().getBotnick();
    startchan = bot.getConfigs().getStartChan();

    this.inboundMsgQ = bot.getInboundMsgQ();
    this.outboundMsgQ = bot.getOutboundMsgQ();

    loadServerResponseCodesToIgnore();

    ircCommands = bot.getIrcCommands();

    this.setInterruptListeners(bot.getInterruptListeners());
    this.setEventListeners(bot.getEventListeners());
    this.botCommandListeners = bot.getBotCommandListeners();

    pipelines = new Pipelines();

    setThreadExecuting(true);

    if (bot.getConfigs().isHeadless()) {
      UserInputBox uib = new UserInputBox(outboundMsgQ);
      uib.stub();
    }
  }
Exemplo n.º 2
0
  public BaseListener(IRCBot ircbot) {

    this.ircbot = ircbot;
    this.botnick = ircbot.getConfigs().getBotnick();

    this.ircCommands = ircbot.getIrcCommands();

    this.interruptListeners = this.ircbot.getInterruptListeners();
    this.eventListeners = this.ircbot.getEventListeners();
    this.outboundMsgQ = this.ircbot.getOutboundMsgQ();
  }
Exemplo n.º 3
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());
  }
Exemplo n.º 4
0
  @Test
  public void testMsgFromAdmin() {

    String channelMsg =
        ":[email protected] PRIVMSG #channelname :!b flirt nick";
    String adminMsg =
        ":[email protected] PRIVMSG #channelname :!botnick flirt nick";

    //  Set up bot and command
    IRCBot mockBot = new IRCBot(false);
    FlirtCommand flirtCommand = new FlirtCommand(mockBot);

    IRCMsg badFlirtMsg = mockBot.getIRCMsgHandler().createAndDecorateMsg(channelMsg);
    Assert.assertFalse(flirtCommand.listen(badFlirtMsg));
    String pollResult = mockBot.getOutboundMsgQ().poll();
    Assert.assertNull(pollResult);

    IRCMsg goodFlirt = mockBot.getIRCMsgHandler().createAndDecorateMsg(adminMsg);
    Assert.assertTrue(goodFlirt.isFromAdmin());

    mockBot.getIRCMsgHandler().handleMsg(adminMsg);
    pollResult = mockBot.getOutboundMsgQ().poll();
    Assert.assertNotNull(pollResult);
  }
Exemplo n.º 5
0
 public IRCMsg createAndDecorateMsg(String rawMsg) {
   IRCMsg msg = IRCMsgFactory.createIRCMsg(rawMsg);
   return IRCMessageDecorator.decorateMessage(bot.getConfigs(), msg);
 }