net.sf.ircappender.impl
Class IrcConnection

java.lang.Object
  extended by net.sf.ircappender.impl.IrcConnection

public class IrcConnection
extends java.lang.Object

a very simple IRC bot

Author:
nhnb

Constructor Summary
IrcConnection(java.lang.String server, int port, boolean ssl, java.lang.String user, java.lang.String password, java.lang.String nick, java.lang.String channel)
          create a new IRC bot
 
Method Summary
 void connect()
          connects to the specified IRC server
 void disconnect()
          disconnects from the IRC server.
 boolean isChannelEmpty()
          checks whether the channel is empty
 boolean isRunning()
          Returns the running state of the thread
 void login()
          logs in to IRC
 void onChannelJoined()
          starts the forwarder thread
 void onNickAccepted()
          handles the acceptance of the nick name.
 void onNickInUse()
          picks a different nickname
 void sendMessage(java.lang.String target, java.lang.String message)
          sends a message to a channel or nickname
 void setDebug(boolean debug)
          Sets the debug flag
 void setEventQueue(Fifo eventQueue)
          Sets the event queue.
 void setMessageDelay(long messageDelay)
          Sets the message delay
 void setRunning(boolean isRunning)
          Sets the isRunning.
 void waitForForwardThreadToFinish()
          waits for the forwarder thread to finish
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IrcConnection

public IrcConnection(java.lang.String server,
                     int port,
                     boolean ssl,
                     java.lang.String user,
                     java.lang.String password,
                     java.lang.String nick,
                     java.lang.String channel)
create a new IRC bot

Parameters:
server - the irc server
port - the irc port
ssl - use SSL security
user - username of bot
password - password of bot
nick - nickname of bot
channel - channel to join
Method Detail

connect

public void connect()
             throws java.net.UnknownHostException,
                    java.io.IOException
connects to the specified IRC server

Throws:
java.net.UnknownHostException - in case of an invalid irc server name
java.io.IOException - in case of an unexpected input/output error

disconnect

public void disconnect()
disconnects from the IRC server. It is save to call this mehod even if not connected


isChannelEmpty

public boolean isChannelEmpty()
checks whether the channel is empty

Returns:
true, if only the bot is in the channel

isRunning

public boolean isRunning()
Returns the running state of the thread

Returns:
boolean

login

public void login()
logs in to IRC


onChannelJoined

public void onChannelJoined()
starts the forwarder thread


onNickAccepted

public void onNickAccepted()
handles the acceptance of the nick name. This method will check if the nick name is the desired one and join the channel. If the nickname is different, it will try to get nickserv to kill the other connection which is using the nickname.


onNickInUse

public void onNickInUse()
picks a different nickname


sendMessage

public void sendMessage(java.lang.String target,
                        java.lang.String message)
sends a message to a channel or nickname

Parameters:
target - channel or nickname to send to
message - message to send

setDebug

public void setDebug(boolean debug)
Sets the debug flag

Parameters:
debug - debug flag

setEventQueue

public void setEventQueue(Fifo eventQueue)
Sets the event queue.

Parameters:
eventQueue - The event queue to set

setMessageDelay

public void setMessageDelay(long messageDelay)
Sets the message delay

Parameters:
messageDelay - The message delay to set

setRunning

public void setRunning(boolean isRunning)
Sets the isRunning.

Parameters:
isRunning - The isRunning to set

waitForForwardThreadToFinish

public void waitForForwardThreadToFinish()
waits for the forwarder thread to finish