ircbot

Class AbstractIRCBotModule

Implemented Interfaces:
Comparable, IRCBotModule
Known Direct Subclasses:
AI, Calc, Channels, Echo, Events, Help, Lang, MasterMind, Modules, News, Numbers, Pending, People, Quotes, StenSaxPase, Time, Trivia, Wiki

public abstract class AbstractIRCBotModule
extends java.lang.Object
implements IRCBotModule

This class is a partial implementation of the IRCBotModule interface. It provides the functionality to handle commands and default implementations for several methods including parseMessage, randomThought, getProbability, setModuleHandler, getModuleHandler, loadState, saveState, and compareTo.

Method Summary

String
activateEvent(IRCChannel channel)
Each module can schedule events to occur at some point in the future.
protected void
addCommand(Modules.CommandType type, String cmnd)
Declares a command that this module will handle.
int
compareTo(IRCBotModule mod)
Collection
getCommands(Modules.CommandType type)
getCommands is called to get the command line names of all commands provided by this module.
protected Modules
getModuleHandler()
The module handler can be used to find other modules loaded in the bot.
int
getProbability()
getProbability is called to determine which module to choose to express a random thought whenever the bot feels like doing that.
void
loadState(SaveState state)
loadState is called when a module is loaded into the bot.
String
parseMessage(IRCMessage message)
parseMessage is called by the bot with every message that is sent to the IRC channel with the exception for messages beginning with a command prefix, and messages sent by the bot itself.
String
randomThought(IRCChannel channel, Person sender)
An IRC bot might think that it has been too quiet in a channel for too long, or it may just feel like saying something at any given time.
void
saveState(SaveState state)
saveState is called when a module is unloaded from the bot or whenever the IRC command !save is issued.
protected void
scheduleEvent(IRCChannel channel)
Schedule an event to occur as soon as possible.
protected void
scheduleEvent(IRCChannel channel, long delay)
Schedule an event some time in the future.
void
setModuleHandler(Modules handler)
setModuleHandler is called by the module handler when a module is loaded.
String
toString()

Method Details

activateEvent

public String activateEvent(IRCChannel channel)
Each module can schedule events to occur at some point in the future. When the future arrives and it is time for the event to be executed, this method is called.
Specified by:
activateEvent in interface IRCBotModule
Parameters:
channel - The channel in which the event is about to occur.
Returns:
A String containing the scheduled message to send to the channel, or null if no message needs to be sent.

addCommand

protected void addCommand(Modules.CommandType type,
                          String cmnd)
Declares a command that this module will handle. Adds the command to the set of commands returned by getCommands.
Parameters:
cmnd - The command to add, with prefix. E.g. "!seen".

compareTo

public int compareTo(IRCBotModule mod)

getCommands

public Collection getCommands(Modules.CommandType type)
getCommands is called to get the command line names of all commands provided by this module. An IRC message starting with a member of getCommands() will invoke this modules action method. All commands are lower case and begins with the command prefix (!). Note that a module's action method is ONLY called for commands returned by getCommands.
Specified by:
getCommands in interface IRCBotModule
Parameters:
type - The needed privilege level needed to access this command.
Returns:
A Collection of String containing the commands provided by this module.
See Also:
Modules.CommandType

getModuleHandler

protected Modules getModuleHandler()
The module handler can be used to find other modules loaded in the bot. For instance to get hold of the People module to get a Person object from a nick.
Returns:
The module handler that was used to load this module.

getProbability

public int getProbability()
getProbability is called to determine which module to choose to express a random thought whenever the bot feels like doing that.
Specified by:
getProbability in interface IRCBotModule
Returns:
An integer value between 0 and 100 which represents the probability (percentage) that this module will be chosen to express a random thought. If your module has a broad variety of what is said and can be chosen several times in a row without getting boring, you should return a high probability (100 or just below). If your module does not have any random thoughts return a low probability (0).

loadState

public void loadState(SaveState state)
loadState is called when a module is loaded into the bot. It should read any settings or other external data needed for its operation from the provided state. Note that the data to be read has been saved by the saveState method in the same class. This method is only supposed to read values that has been saved by this class! If this module's saveState method does not save any data, this method should be empty. Data is read back from the state using the SaveState.get method.
Specified by:
loadState in interface IRCBotModule
Parameters:
state - The state to read from.

parseMessage

public String parseMessage(IRCMessage message)
parseMessage is called by the bot with every message that is sent to the IRC channel with the exception for messages beginning with a command prefix, and messages sent by the bot itself. If the implementing module does not care about the communication in the channel, this method should immediately return null without looking at the message.
Specified by:
parseMessage in interface IRCBotModule
Parameters:
message - The message sent to the IRC channel.
Returns:
A String containing a reply to the message, or null if nothing should be sent to the IRC channel.

randomThought

public String randomThought(IRCChannel channel,
                            Person sender)
An IRC bot might think that it has been too quiet in a channel for too long, or it may just feel like saying something at any given time. To get something to say a random module is chosen and its randomThought is invoked.
Specified by:
randomThought in interface IRCBotModule
Parameters:
channel - The channel that is too quiet.
sender - The bot who asked for this thought.
Returns:
A String containing a random thought or null if this module has nothing nice to say.

saveState

public void saveState(SaveState state)
saveState is called when a module is unloaded from the bot or whenever the IRC command !save is issued. Use it to save any settings or other data needed for this modules operation. If this module does not keep any data that needs to be stored for later sessions, this method should be empty. Use the SaveState.add method to put new data into the state. Each data object that is to be stored in the state should be tagged with a unique identifier. The identifier will be padded with the name of the module so that identifiers in different modules will not clash.
Specified by:
saveState in interface IRCBotModule
Parameters:
state - The state to write to.

scheduleEvent

protected void scheduleEvent(IRCChannel channel)
Schedule an event to occur as soon as possible.

scheduleEvent

protected void scheduleEvent(IRCChannel channel,
                             long delay)
Schedule an event some time in the future.
Parameters:
delay - The minimum time that must pass before the event is executed.

setModuleHandler

public void setModuleHandler(Modules handler)
setModuleHandler is called by the module handler when a module is loaded.
Specified by:
setModuleHandler in interface IRCBotModule
Parameters:
handler - The module handler that is loading the module.

toString

public String toString()