use of org.pircbotx.hooks.events.ConnectEvent in project ircbot-plugin by jenkinsci.
the class IRCConnection method connect.
// @Override
public boolean connect() {
try {
LOGGER.info(String.format("Connecting to %s:%s as %s using charset %s", this.descriptor.getHost(), this.descriptor.getPort(), this.descriptor.getNick(), this.descriptor.getCharset()));
if (botThread != null) {
botThread.interrupt();
}
final CountDownLatch connectLatch = new CountDownLatch(1);
ListenerAdapter<PircBotX> connectListener = new ListenerAdapter<PircBotX>() {
@Override
public void onConnect(ConnectEvent<PircBotX> event) throws Exception {
connectLatch.countDown();
LOGGER.info("connected to IRC");
}
};
cfg.addListener(connectListener);
botThread = new Thread("IRC Bot") {
public void run() {
pircConnection = new PircBotX(cfg.buildConfiguration());
try {
pircConnection.startBot();
} catch (Exception e) {
LOGGER.warning("Error connecting to irc: " + e);
}
}
};
botThread.start();
try {
boolean connected = connectLatch.await(2, TimeUnit.MINUTES);
if (!connected) {
LOGGER.warning("Time out waiting for connecting to irc");
close();
return false;
}
} catch (InterruptedException e) {
LOGGER.warning("Interrupted waiting for connecting to irc: " + e);
Thread.currentThread().interrupt();
}
pircConnection.getConfiguration().getListenerManager().removeListener(connectListener);
// final String nickServPassword = this.descriptor.getNickServPassword();
// if(Util.fixEmpty(nickServPassword) != null) {
// this.pircConnection.identify(nickServPassword);
//
// if (!this.groupChats.isEmpty()) {
// // Sleep some time so chances are good we're already identified
// // when we try to join the channels.
// // Unfortunately there seems to be no standard way in IRC to recognize
// // if one has been identified already.
// LOGGER.fine("Sleeping some time to wait for being authenticated");
// try {
// Thread.sleep(TimeUnit.SECONDS.toMillis(5));
// } catch (InterruptedException e) {
// // ignore
// }
// }
// }
joinGroupChats();
return pircConnection.isConnected();
} catch (RuntimeException e) {
LOGGER.log(WARNING, "Error connecting to irc", e);
return false;
}
}
use of org.pircbotx.hooks.events.ConnectEvent 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);
}
Aggregations