- 0 Talk
-
this wiki
Home
AboutWelcome to the JerkLib Wiki! JerkLib is an event driven IRC library for Java that provides a complete set of classes to facilitate the writing of IRC clients.
InstallDownload Jerklib and unpack the package. Add the jerklib.jar included to the classpath.
UsingLets make a simple IRC bot and connect it to Freenode. package jerklib.examples; import jerklib.ConnectionManager; import jerklib.Profile; public class Bot { public Bot() { ConnectionManager conman = new ConnectionManager(new Profile("jerkbot")); conman.requestConnection("irc.freenode.net"); } } Lets add a listener to the connection so we can hear what's happening.The following will print out the Type and raw data of events. package jerklib.examples; import jerklib.ConnectionManager; import jerklib.Profile; import jerklib.events.IRCEvent; import jerklib.listeners.IRCEventListener; public class Bot implements IRCEventListener { public Bot() { ConnectionManager conman = new ConnectionManager(new Profile("jerkbot")); conman.requestConnection("irc.freenode.net").addIRCEventListener(this); } public void receiveEvent(IRCEvent e) { System.out.println(e.getType() + " : " + e.getRawEventData()); } } Jerklib will let you know when the Freenode connection is complete by sending a ConnectionComplete event. Once that event is received we can start joining channels. package jerklib.examples; import jerklib.ConnectionManager; import jerklib.Profile; import jerklib.events.IRCEvent; import jerklib.events.JoinCompleteEvent; import jerklib.events.IRCEvent.Type; import jerklib.listeners.IRCEventListener; public class Bot implements IRCEventListener { public Bot() { ConnectionManager conman = new ConnectionManager(new Profile("jerkbot")); conman.requestConnection("irc.freenode.net").addIRCEventListener(this); } public void receiveEvent(IRCEvent e) { if(e.getType() == Type.CONNECT_COMPLETE) { e.getSession().join("#jerklib"); } else if(e.getType() == Type.JOIN_COMPLETE) { JoinCompleteEvent jce = (JoinCompleteEvent)e; jce.getChannel().say("Hello World!!"); } else { System.out.println(e.getType() + " : " + e.getRawEventData()); } } } Jerklib dispatches all events as IRCEvents. You should always
check the type of the IRCEvent by examing the return of e.getType() (e is an instance of IRCEvent). getType() will return a member
of the Type enum. Once you know the type of the event
you can cast it to a more specific type. This will give you access to methods relavent for such an event.
Getting Help
|