org.xwiki.ircbot
Interface IRCBot


@Role
public interface IRCBot

Represents an IRC Bot.

Since:
4.0M2
Version:
$Id: 66e145f1b16b0e55ffd87fa0d25fb20a1384fe75 $

Method Summary
 void connect(String hostname)
          Attempt to connect to the specified IRC server.
 void disconnect()
          This method disconnects from the server cleanly by calling the quitServer() method.
 Set<String> getChannelsNames()
          Gets all the name's of all the channels that we are connected to.
 org.pircbotx.hooks.managers.ListenerManager<? extends org.pircbotx.PircBotX> getListenerManager()
          Returns the current ListenerManager in use by this bot.
 void identify(String password)
          Identify the bot with NickServ, supplying the appropriate password.
 void initialize(String wikiName)
          Initialize the IRC Bot.
 boolean isConnected()
          Returns whether or not the Bot is currently connected to a server.
 void joinChannel(String channel)
          Joins a channel.
 void sendMessage(String target, String message)
          Sends a message to a channel or a private message to a user.
 void setName(String botName)
          Sets the name of the bot, which will be used as its nick when it tries to join an IRC server.
 

Method Detail

initialize

void initialize(String wikiName)
Initialize the IRC Bot. Needs to be called before the Bot can be used.

Parameters:
wikiName - the name of the wiki under which the IRC Bot listener will execute (eg "xwiki")
Since:
4.3M1

setName

void setName(String botName)
Sets the name of the bot, which will be used as its nick when it tries to join an IRC server. This should be set before joining any servers, otherwise the default nick will be used. The changeNick method should be used if you wish to change your nick when you are connected to a server.

Parameters:
botName - the new name of the Bot

connect

void connect(String hostname)
             throws IOException,
                    org.pircbotx.exception.IrcException
Attempt to connect to the specified IRC server. The onConnect method is called upon success.

Parameters:
hostname - the hostname of the server to connect to
Throws:
IOException - if it was not possible to connect to the server
org.pircbotx.exception.IrcException - if the server would not let us join it

joinChannel

void joinChannel(String channel)
Joins a channel.

Parameters:
channel - the name of the channel to join (eg "#cs")

disconnect

void disconnect()
This method disconnects from the server cleanly by calling the quitServer() method. Providing the Bot was connected to an IRC server, DisconnectEvent will be dispatched as soon as the disconnection is made by the server.


identify

void identify(String password)
Identify the bot with NickServ, supplying the appropriate password. Some IRC Networks (such as freenode) require users to register and identify with NickServ before they are able to send private messages to other users, thus reducing the amount of spam. If you are using an IRC network where this kind of policy is enforced, you will need to make your bot identify itself to NickServ before you can send private messages. Assuming you have already registered your bot's nick with NickServ, this method can be used to identify with the supplied password. It usually makes sense to identify with NickServ immediately after connecting to a server.

This method issues a raw NICKSERV command to the server, and is therefore safer than the alternative approach of sending a private message to NickServ. The latter approach is considered dangerous, as it may cause you to inadvertently transmit your password to an untrusted party if you connect to a network which does not run a NickServ service and where the untrusted party has assumed the nick "NickServ". However, if your IRC network is only compatible with the private message approach, you may typically identify like so:

sendMessage("NickServ", "identify PASSWORD");

Note that this method will add a temporary listener for ConnectEvent if the bot is not logged in yet. If the bot is logged in the command is sent immediately to the server

Parameters:
password - The password which will be used to identify with NickServ.

sendMessage

void sendMessage(String target,
                 String message)
Sends a message to a channel or a private message to a user. These messages are added to the outgoing message queue and sent at the earliest possible opportunity.

Some examples: -

    // Send the message "Hello!" to the channel #cs.
    sendMessage("#cs", "Hello!");

    // Send a private message to Paul that says "Hi".
    sendMessage("Paul", "Hi");
You may optionally apply colours, boldness, underlining, etc to the message by using the Colors class.

Parameters:
target - The name of the channel or user nick to send to.
message - The message to send.

getChannelsNames

Set<String> getChannelsNames()
Gets all the name's of all the channels that we are connected to.

Returns:
An Unmodifiable set of Channel names

isConnected

boolean isConnected()
Returns whether or not the Bot is currently connected to a server. The result of this method should only act as a rough guide, as the result may not be valid by the time you act upon it.

Returns:
True if and only if the Bot is currently connected to a server.

getListenerManager

org.pircbotx.hooks.managers.ListenerManager<? extends org.pircbotx.PircBotX> getListenerManager()
Returns the current ListenerManager in use by this bot.

Returns:
the current ListenerManager


Copyright © 2004-2012 XWiki. All Rights Reserved.