@SuppressWarnings({"StringContatenationInLoop"}) public final void connect() { while (!isConnected()) { try { connect(host, port); sendRawLine("PRIVMSG NickServ :identify " + getNickPassword()); sleep(authWait); final List<Channel> channelList = channelDao.getChannels(); if (channelList.isEmpty()) { Channel chan = new Channel(); chan.setName("##" + getNick()); System.out.println("No channels found. Initializing to " + chan.getName()); changeDao.save(chan); chan.join(this); } else { for (final Channel channel : channelList) { new Thread( new Runnable() { @Override public void run() { channel.join(Javabot.this); } }) .start(); } } } catch (Exception exception) { disconnect(); log.error(exception.getMessage(), exception); } sleep(1000); } }
@Override public void onPart( final String channel, final String sender, final String login, final String hostname) { final Channel chan = channelDao.get(channel); if (chan != null && chan.getLogged()) { logsDao.logMessage(Logs.Type.PART, sender, channel, "parted the channel"); } }
@Override public void onQuit( final String channel, final String sender, final String login, final String hostname) { final Channel chan = channelDao.get(channel); if (chan != null && chan.getLogged()) { logsDao.logMessage(Logs.Type.QUIT, sender, channel, "quit"); } else if (chan == null) { log.debug("not logging " + channel); } }
private List<Logs> dailyLog(String channelName, DateTime date) { Channel channel = channelDao.get(channelName); List<Logs> list = null; if (channel.getLogged()) { DateTime start = (date == null ? new DateTime(DateTimeZone.forID("US/Eastern")) : date) .withTimeAtStartOfDay(); DateTime tomorrow = start.plusDays(1); LogsCriteria criteria = new LogsCriteria(ds); criteria.channel().equal(channelName); criteria.and( criteria.updated().greaterThanOrEq(start), criteria.updated().lessThanOrEq(tomorrow)); list = criteria.query().asList(); } return list; }