public QuitEvent createEvent(IRCEvent event) { Session session = event.getSession(); String nick = event.getNick(); List<Channel> chanList = event.getSession().removeNickFromAllChannels(nick); return new QuitEvent( event.getRawEventData(), session, event.arg(0), // message chanList); }
@Override /** Callback whenever the Bot receives data. */ public void receiveEvent(IRCEvent e) { Type type = e.getType(); // Connects to server successfully if (type == Type.CONNECT_COMPLETE) { e.getSession().join(data.channel); // Connects to channel successfully } else if (type == Type.JOIN_COMPLETE) { channel = ((JoinCompleteEvent) e).getChannel(); e.getSession().sayPrivate("nickserv", "identify " + data.botPassword); // User joins channel } else if (type == Type.JOIN) { JoinEvent je = (JoinEvent) e; int x = new Random().nextInt(data.greetings.size()); je.getChannel().say(String.format(data.greetings.get(x), je.getNick())); for (int i = 0; i < data.notices.size(); i++) { Notice n = data.notices.get(i); if (n.to.toLowerCase().equals(je.getNick().toLowerCase())) { je.getChannel().say(je.getNick() + ", " + n.from + " says: " + n.msg); data.notices.remove(n); } } // User leaves channel } else if (type == Type.QUIT) { QuitEvent qe = (QuitEvent) e; users.remove(qe.getNick()); // Receives message in channel } else if (type == Type.CHANNEL_MESSAGE) { MessageEvent me = (MessageEvent) e; String msg = me.getMessage(); User user = loadUser(me.getNick()); boolean found = true; if (isCommand(msg)) { if (isAdmin(me.getNick())) { String cmd = getCommand(msg); if (cmd.equals("help")) cmdHelp(me); else if (cmd.equals("kick")) cmdKick(me); else if (cmd.equals("admins")) cmdAdmins(me); else if (cmd.equals("roll")) cmdRoll(me); else if (cmd.equals("announcer")) cmdAnnounce(me); else if (cmd.equals("badwords")) cmdBadWord(me); else if (cmd.equals("greetings")) cmdGreetings(me); else if (cmd.equals("quit")) cmdQuit(); else if (cmd.equals("save")) cmdSave(); else if (cmd.equals("notice")) cmdNotice(me); else if (cmd.equals("kill")) cmdKill(me); else if (cmd.equals("time")) cmdTime(me); else found = false; } String cmd = getCommand(msg); if (cmd.equals("away")) cmdAway(me); else if (!found) me.getChannel().say("Unknown command."); } if (me.getMessage().contains("lol")) { me.getChannel().say("lol"); } else { checkLanguage(me, user); checkAway(me); } } }