Search in sources :

Example 1 with UserHostmask

use of org.pircbotx.UserHostmask in project downlords-faf-client by FAForever.

the class PircBotXChatServiceTest method testRegisterOnNotRegisteredNotice.

@Test
public void testRegisterOnNotRegisteredNotice() throws Exception {
    String password = "123";
    when(userService.getPassword()).thenReturn(password);
    connect();
    botStartedFuture.get(TIMEOUT, TIMEOUT_UNIT);
    UserHostmask nickServHostMask = mock(UserHostmask.class);
    when(nickServHostMask.getHostmask()).thenReturn("nickserv");
    firePircBotXEvent(new NoticeEvent(pircBotX, nickServHostMask, null, null, "", "User foo isn't registered"));
    instance.connectionState.set(ConnectionState.CONNECTED);
    String md5sha256Password = Hashing.md5().hashString(Hashing.sha256().hashString(password, UTF_8).toString(), UTF_8).toString();
    verify(outputIrc, timeout(100)).message("nickserv", String.format("register %s junit@users.faforever.com", md5sha256Password));
}
Also used : NoticeEvent(org.pircbotx.hooks.events.NoticeEvent) UserHostmask(org.pircbotx.UserHostmask) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 2 with UserHostmask

use of org.pircbotx.UserHostmask in project downlords-faf-client by FAForever.

the class PircBotXChatServiceTest method connect.

private void connect() throws Exception {
    instance.connect();
    verify(pircBotXFactory).createPircBotX(configurationCaptor.capture());
    CountDownLatch latch = listenForConnected();
    firePircBotXEvent(new ConnectEvent(pircBotX));
    assertTrue(latch.await(TIMEOUT, TIMEOUT_UNIT));
    UserHostmask nickServHostMask = mock(UserHostmask.class);
    when(nickServHostMask.getHostmask()).thenReturn("nickserv");
    when(configuration.getNickservNick()).thenReturn("nickserv");
    when(configuration.getNickservOnSuccess()).thenReturn("you are now");
    firePircBotXEvent(new NoticeEvent(pircBotX, nickServHostMask, null, null, "", "you are now identified"));
    SocialMessage socialMessage = new SocialMessage();
    socialMessage.setChannels(Collections.emptyList());
    socialMessageListenerCaptor.getValue().accept(socialMessage);
    verify(outputIrc, timeout(TIMEOUT).atLeastOnce()).joinChannel(DEFAULT_CHANNEL_NAME);
}
Also used : ConnectEvent(org.pircbotx.hooks.events.ConnectEvent) NoticeEvent(org.pircbotx.hooks.events.NoticeEvent) SocialMessage(com.faforever.client.remote.domain.SocialMessage) UserHostmask(org.pircbotx.UserHostmask) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 3 with UserHostmask

use of org.pircbotx.UserHostmask in project downlords-faf-client by FAForever.

the class PircBotXChatService method onNotice.

private void onNotice(NoticeEvent event) {
    Configuration config = event.getBot().getConfiguration();
    UserHostmask hostmask = event.getUserHostmask();
    if (config.getNickservOnSuccess() != null && containsIgnoreCase(hostmask.getHostmask(), config.getNickservNick())) {
        String message = event.getMessage();
        if (containsIgnoreCase(message, config.getNickservOnSuccess()) || containsIgnoreCase(message, "registered under your account")) {
            onIdentified();
        } else if (message.contains("isn't registered")) {
            pircBotX.sendIRC().message(config.getNickservNick(), format("register %s %s@users.faforever.com", getPassword(), userService.getUsername()));
        } else if (message.contains(" registered")) {
            // We just registered and are now identified
            onIdentified();
        } else if (message.contains("choose a different nick")) {
            // The server didn't accept our IDENTIFY command, well then, let's send a private message to nickserv manually
            sendIdentify(config);
        }
    }
}
Also used : Configuration(org.pircbotx.Configuration) UserHostmask(org.pircbotx.UserHostmask)

Aggregations

UserHostmask (org.pircbotx.UserHostmask)3 NoticeEvent (org.pircbotx.hooks.events.NoticeEvent)2 SocialMessage (com.faforever.client.remote.domain.SocialMessage)1 AbstractPlainJavaFxTest (com.faforever.client.test.AbstractPlainJavaFxTest)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1 Configuration (org.pircbotx.Configuration)1 ConnectEvent (org.pircbotx.hooks.events.ConnectEvent)1