Erebot  latest
A modular IRC bot for PHP 5.3+
Erebot\Module\Base Class Reference

An abstract class which serves as the base to build additional modules for Erebot. More...

Public Member Functions

 __construct ($channel)
 
 __destruct ()
 
 getFactory ($iface)
 
 getNumRef ($name)
 
 reloadModule (\Erebot\Interfaces\Connection $connection, $flags)
 
 setFactory ($iface, $cls)
 
 unloadModule ()
 

Public Attributes

const MSG_TYPE_ACTION = 'ACTION'
 An action.
 
const MSG_TYPE_CTCP = 'CTCP'
 A CTCP request.
 
const MSG_TYPE_CTCPREPLY = 'CTCPREPLY'
 A reply to a CTCP request.
 
const MSG_TYPE_NOTICE = 'NOTICE'
 A notice.
 
const MSG_TYPE_PRIVMSG = 'PRIVMSG'
 A regular message.
 
const RELOAD_ALL = 0xF0
 The module should (re)load all of its contents.
 
const RELOAD_HANDLERS = 0x20
 The module should (re)load its handlers.
 
const RELOAD_INIT = 0x01
 Passed when the module is loaded (instead of reloaded).
 
const RELOAD_MEMBERS = 0x10
 The module should (re)load its members.
 
const RELOAD_TESTING = 0x02
 Passed during unittests (currently unused...).
 

Protected Member Functions

 addTimer (\Erebot\TimerInterface $timer)
 
 getFormatter ($chan)
 
 parseBool ($param, $default=null)
 
 parseInt ($param, $default=null)
 
 parseReal ($param, $default=null)
 
 parseString ($param, $default=null)
 
 registerHelpMethod (\Erebot\CallableInterface $callback)
 
 reload ($flags)
 
 removeTimer (\Erebot\TimerInterface $timer)
 
 sendCommand ($command)
 
 sendMessage ($targets, $message, $type=self::MSG_TYPE_PRIVMSG)
 
 unload ()
 

Static Protected Member Functions

static ctcpQuote ($message)
 

Protected Attributes

 $channel
 The channel associated with this instance, if any.
 
 $connection
 The connection associated with this instance.
 
 $factories
 Factories to use for this module.
 
 $logger
 A logger for this module's messages.
 
 $translator
 The translator to use for messages coming from this instance.
 

Private Member Functions

 parseSomething ($something, $param, $default)
 

Detailed Description

An abstract class which serves as the base to build additional modules for Erebot.

Definition at line 28 of file Base.php.

Constructor & Destructor Documentation

Erebot\Module\Base::__construct (   $channel)
final

Constructor for modules.

Parameters
string | null$channel(optional) The channel this instance applies to. This will be null for modules loaded at the server level or higher in the configuration hierarchy.

Definition at line 111 of file Base.php.

References Erebot\Module\Base\$channel, and Erebot\Module\Base\setFactory().

Erebot\Module\Base::__destruct ( )
final

Destructor.

Definition at line 160 of file Base.php.

Member Function Documentation

Erebot\Module\Base::addTimer ( \Erebot\TimerInterface  $timer)
protected

Register a timer.

Parameters
Erebot::TimerInterface$timerThe timer to register.
Note
This method is only a shortcut for Erebot::Interfaces::Core::addTimer().

Definition at line 443 of file Base.php.

static Erebot\Module\Base::ctcpQuote (   $message)
staticprotected

Quotes a CTCP message.

Parameters
string$messageMessage to quote.
Return values
stringQuoted version of the message.
See also
http://www.irchelp.org/irchelp/rfc/ctcpspec.html describes the quoting algorithm used.

Definition at line 399 of file Base.php.

Erebot\Module\Base::getFactory (   $iface)

Return the name of the class to use to create instances with the given interface.

Parameters
string$ifaceName of the interface for which the factory must be returned.
Return values
stringName of the class that acts as a factory for that interface.
Note
As a special shortcut, an exclamation point (!) in the interface's name will automatically be replaced with the text "Erebot_Interface_".

Definition at line 283 of file Base.php.

Referenced by Erebot\Module\Base\getFormatter(), and Erebot\Module\Base\getNumRef().

Erebot\Module\Base::getFormatter (   $chan)
protected

Returns the appropriate formatter for the given channel.

Parameters
null | false | string$chanThe channel for which a formatter must be returned. If $chan is null, the hierarchy of configurations is traversed to find the most appropriate formatter. If $chan is false, a formatter is built using the bot's main translator.
Return values
Erebot::StylingInterfaceA formatter for the given channel.

Definition at line 638 of file Base.php.

References Erebot\Module\Base\getFactory().

Erebot\Module\Base::getNumRef (   $name)

This method is a simple shortcut to create references to numeric messages.

Parameters
$nameName of the numeric message for which a reference must be returned (eg. "RPL_WELCOME").
Return values
Erebot::Interfaces::NumericReferenceA numeric reference.

Definition at line 676 of file Base.php.

References Erebot\Module\Base\getFactory().

Erebot\Module\Base::parseBool (   $param,
  $default = null 
)
protected

Returns the boolean value for a setting in this module's configuration.

Parameters
string$paramThe name of the parameter we are interested in.
bool$default(optional) A default value in case no value has been set at the configuration level.
Return values
boolThe value for that parameter.
Exceptions
Erebot::InvalidValueExceptionThe given $default value does not have the right type.

Definition at line 521 of file Base.php.

References Erebot\Module\Base\parseSomething().

Erebot\Module\Base::parseInt (   $param,
  $default = null 
)
protected

Returns the integer value for a setting in this module's configuration.

Parameters
int$paramThe name of the parameter we are interested in.
int$default(optional) A default value in case no value has been set at the configuration level.
Return values
intThe value for that parameter.
Exceptions
Erebot::InvalidValueExceptionThe given $default value does not have the right type.

Definition at line 563 of file Base.php.

References Erebot\Module\Base\parseSomething().

Erebot\Module\Base::parseReal (   $param,
  $default = null 
)
protected

Returns the real value for a setting in this module's configuration.

Parameters
string$paramThe name of the parameter we are interested in.
float$default(optional) A default value in case no value has been set at the configuration level.
Return values
floatThe value for that parameter.
Exceptions
Erebot::InvalidValueExceptionThe given $default value does not have the right type.

Definition at line 584 of file Base.php.

References Erebot\Module\Base\parseSomething().

Erebot\Module\Base::parseSomething (   $something,
  $param,
  $default 
)
private

Retrieves a parameter from the module's configuration by recursively traversing the configuration hierarchy and parses it using the appropriate function.

Parameters
string$somethingThe type of parsing to apply to the parameter. This is used to determine the correct parsing method to call.
string$paramThe name of the parameter to retrieve.
mixed$defaultThe default value if the parameter is absent. It's actual type depends on the type of parsing applied by the $something argument.
Warning
This method may throw several exceptions for different reasons (such as a missing parameter, an invalid value or an invalid default value).

Definition at line 489 of file Base.php.

Referenced by Erebot\Module\Base\parseBool(), Erebot\Module\Base\parseInt(), Erebot\Module\Base\parseReal(), and Erebot\Module\Base\parseString().

Erebot\Module\Base::parseString (   $param,
  $default = null 
)
protected

Returns the string value for a setting in this module's configuration.

Parameters
string$paramThe name of the parameter we are interested in.
string$defaultAn optional default value in case no value has been set at the configuration level.
Return values
stringThe value for that parameter.
Exceptions
Erebot::InvalidValueExceptionThe given $default value does not have the right type.

Definition at line 542 of file Base.php.

References Erebot\Module\Base\parseSomething().

Erebot\Module\Base::registerHelpMethod ( \Erebot\CallableInterface  $callback)
protected

Registers the given callback as the help method for this module. All help requests directed to this module will be passed to this method which may choose to handle it (eg. by sending back help messages to the person requesting help). This method may also choose to ignore a given request, which will result in a default "No help available" response.

Parameters
Erebot::CallableInterface$callbackThe callback to register as the help method for this module.
Return values
trueThe callback could be registered.
falseThe callback could not be registered.
Note
In case multiple calls to this method are done by the same module, only the last registered callback will effectively be called to handle help requests.

Definition at line 612 of file Base.php.

Referenced by Erebot\Module\Base\reloadModule().

Erebot\Module\Base::reload (   $flags)
abstractprotected

This method is called whenever the module is (re)loaded.

Parameters
int$flagsA bitwise OR of the Erebot::Module::Base::RELOAD_* constants. Your method should take proper actions depending on the value of those flags.
Note
See the documentation on individual RELOAD_* constants for a list of possible values.

Referenced by Erebot\Module\Base\reloadModule().

Erebot\Module\Base::reloadModule ( \Erebot\Interfaces\Connection  $connection,
  $flags 
)
final

Public method to (re)load a module. This eventually reconfigures the bot.

Parameters
Erebot::Interfaces::Connection$connectionIRC connection associated with this instance.
int$flagsA bitwise OR of the Erebot::Module::Base::RELOAD_* constants. Your method should take proper actions depending on the value of those flags.
Note
See the documentation on individual RELOAD_* constants for a list of possible values.

Definition at line 186 of file Base.php.

References Erebot\Module\Base\$connection, Erebot\Module\Base\registerHelpMethod(), Erebot\Module\Base\reload(), Erebot\Module\Base\RELOAD_INIT, and Erebot\CallableWrapper\wrap().

Erebot\Module\Base::removeTimer ( \Erebot\TimerInterface  $timer)
protected

Unregister a timer.

Parameters
Erebot::TimerInterface$timerThe timer to unregister.
Note
This method is only a shortcut for Erebot::Interfaces::Core::removeTimer().

Definition at line 459 of file Base.php.

Erebot\Module\Base::sendCommand (   $command)
protected

Send a raw command to the IRC server.

Parameters
string$commandThe command to send.

Definition at line 425 of file Base.php.

References Erebot\Utils\stringifiable().

Erebot\Module\Base::sendMessage (   $targets,
  $message,
  $type = self::MSG_TYPE_PRIVMSG 
)
protected

Send a message to a set of IRC targets (nicks or channels).

Parameters
string | list$targetsEither a single nick or channel to which the message must be sent or an array of nicks/channels.
string$messageThe message to send.
opaque$type(optional) The type of message to send. The default is to send a regular message (using the PRIVMSG command). Use the MSG_TYPE_* constants to specify a different type.
Exceptions
ExceptionAn invalid value was used for the $type or $targets parameter.

Definition at line 320 of file Base.php.

References Erebot\Utils\stringifiable().

Erebot\Module\Base::setFactory (   $iface,
  $cls 
)

Set the factory for the given interface.

Parameters
string$ifaceName of the interface to act upon.
string$clsName of the class that acts as a factory for that interface. If must implement that interface.
Note
As a special shortcut, an exclamation point (!) in the interface's name will automatically be replaced with the text "Erebot_Interface_".

Definition at line 234 of file Base.php.

Referenced by Erebot\Module\Base\__construct().

Erebot\Module\Base::unload ( )
protected

This method is called whenever the module should be unloaded.

You may redefine this method to do whatever you need to do to remove any bits of your module's existence (eg. clean up memory, etc.).

Definition at line 99 of file Base.php.

Referenced by Erebot\Module\Base\unloadModule().

Erebot\Module\Base::unloadModule ( )
final

This method is called when unloading the module. It simply calls $this->unload.

Definition at line 212 of file Base.php.

References Erebot\Module\Base\unload().


The documentation for this class was generated from the following file: