ircbot
Class IRCBot
public class IRCBot
extends java.lang.Object
This is the main engine for the bot. This class provides methods to
handle the network connection, and the main loop that reads
messages from the IRC network. Most functionality of the bot has
been placed in separate modules so there isn't really that much
action in this class. This engine only handles one module, all
other modules are handled by the module Modules
.
void | connect() -
Network connection
|
void | connect(BufferedReader in, BufferedWriter out) - Connect to the given readers.
|
void | connect(String network) - Used to connect to an IRC network.
|
void | connect(String network, int port) - Used to connect to an IRC network.
|
void | doTheBotThing() -
Main loop
|
Collection | getEvents()
|
String | getName()
|
static boolean | isCommandPrefix(char ch) - This method defines what characters are considered to be
command prefixes.
|
void | logMessage(String msg)
|
static String | makeList(Collection>c ) - Creates a string representation of a list with all elements
from the given collection of Strings.
|
static String | makeList(Collection c, boolean sorted) - Creates a string representation of a list with all elements
from the given collection of Strings.
|
static String | maybeReply(double prob, String message) - Used to filter messages if a reply every single time something
happens is not desired.
|
void | quit() - Called to terminate the network connection.
|
void | scheduleEvent(IRCEvent event) -
Event management
|
static void | sleep(int millis) - Put the bot to sleep for a while.
|
void | unscheduleEvent(IRCEvent event)
|
void | unscheduleEvents(IRCChannel channel)
|
IRCBot
public IRCBot(IRCBotConfig config)
Create a new bot given a name and a description.
connect
public void connect()
throws IOException
Network connection
connect
public void connect(BufferedReader in,
BufferedWriter out)
Connect to the given readers. Can be used to connect to an
input and an output file or to stdin and stdout.
in
- The BufferedReader to connect to.out
- The BufferedWriter to connect to.
connect
public void connect(String network)
throws IOException
Used to connect to an IRC network.
network
- The domain name of the network to connect to.
connect
public void connect(String network,
int port)
throws IOException
Used to connect to an IRC network.
network
- The domain name of the network to connect to.port
- The port to connect to.
doTheBotThing
public void doTheBotThing()
throws IOException
Main loop
getEvents
public Collection getEvents()
getName
public String getName()
isCommandPrefix
public static boolean isCommandPrefix(char ch)
This method defines what characters are considered to be
command prefixes. Only messages starting with one of these
characters will be considered commands.
ch
- The character to test.
- TRUE if the given character was a command prefix, FALSE
otherwise.
logMessage
public void logMessage(String msg)
makeList
public static String makeList(Collection>c )
Creates a string representation of a list with all elements
from the given collection of Strings.
- A string containing the list.
makeList
public static String makeList(Collection c,
boolean sorted)
Creates a string representation of a list with all elements
from the given collection of Strings. If requested, the list is
sorted alphabetically.
c
- The collection to create a list from.sorted
- TRUE to generate a sorted list, FALSE otherwise.
- A string containing the list.
maybeReply
public static String maybeReply(double prob,
String message)
Used to filter messages if a reply every single time something
happens is not desired.
prob
- The probability of a reply. A value between 0 and 1
where 0 means not a chance and 1 means every single time.message
- The message that should be sent if we are lucky.
- The message, or null if no message is to be sent.
quit
public void quit()
throws IOException
Called to terminate the network connection.
scheduleEvent
public void scheduleEvent(IRCEvent event)
Event management
sleep
public static void sleep(int millis)
Put the bot to sleep for a while.
millis
- The number of milliseconds to sleep.
unscheduleEvent
public void unscheduleEvent(IRCEvent event)
unscheduleEvents
public void unscheduleEvents(IRCChannel channel)