Fandom

JerkLib Wiki

Home

6pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.


About

Welcome 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.


Install

Download Jerklib and unpack the package. Add the jerklib.jar included to the classpath.


Using

Lets 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.

To see what else you can do take a look the javadocs. Be sure to look to at Session and the jerklib.events package.


Getting Help


Also on Fandom

Random Wiki