|
Erebot
latest
A modular IRC bot for PHP 5.3+
|
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) | |
An abstract class which serves as the base to build additional modules for Erebot.
|
final |
Constructor for modules.
| 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().
|
protected |
Register a timer.
| Erebot::TimerInterface | $timer | The timer to register. |
|
staticprotected |
Quotes a CTCP message.
| string | $message | Message to quote. |
| string | Quoted version of the message. |
| Erebot\Module\Base::getFactory | ( | $iface | ) |
Return the name of the class to use to create instances with the given interface.
| string | $iface | Name of the interface for which the factory must be returned. |
| string | Name of the class that acts as a factory for that interface. |
Definition at line 283 of file Base.php.
Referenced by Erebot\Module\Base\getFormatter(), and Erebot\Module\Base\getNumRef().
|
protected |
Returns the appropriate formatter for the given channel.
| null | false | string | $chan | The 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. |
| Erebot::StylingInterface | A 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.
| $name | Name of the numeric message for which a reference must be returned (eg. "RPL_WELCOME"). |
| Erebot::Interfaces::NumericReference | A numeric reference. |
Definition at line 676 of file Base.php.
References Erebot\Module\Base\getFactory().
|
protected |
Returns the boolean value for a setting in this module's configuration.
| string | $param | The 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. |
| bool | The value for that parameter. |
| Erebot::InvalidValueException | The given $default value does not have the right type. |
Definition at line 521 of file Base.php.
References Erebot\Module\Base\parseSomething().
|
protected |
Returns the integer value for a setting in this module's configuration.
| int | $param | The 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. |
| int | The value for that parameter. |
| Erebot::InvalidValueException | The given $default value does not have the right type. |
Definition at line 563 of file Base.php.
References Erebot\Module\Base\parseSomething().
|
protected |
Returns the real value for a setting in this module's configuration.
| string | $param | The 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. |
| float | The value for that parameter. |
| Erebot::InvalidValueException | The given $default value does not have the right type. |
Definition at line 584 of file Base.php.
References Erebot\Module\Base\parseSomething().
|
private |
Retrieves a parameter from the module's configuration by recursively traversing the configuration hierarchy and parses it using the appropriate function.
| string | $something | The type of parsing to apply to the parameter. This is used to determine the correct parsing method to call. |
| string | $param | The name of the parameter to retrieve. |
| mixed | $default | The default value if the parameter is absent. It's actual type depends on the type of parsing applied by the $something argument. |
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().
|
protected |
Returns the string value for a setting in this module's configuration.
| string | $param | The name of the parameter we are interested in. |
| string | $default | An optional default value in case no value has been set at the configuration level. |
| string | The value for that parameter. |
| Erebot::InvalidValueException | The given $default value does not have the right type. |
Definition at line 542 of file Base.php.
References Erebot\Module\Base\parseSomething().
|
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.
| Erebot::CallableInterface | $callback | The callback to register as the help method for this module. |
| true | The callback could be registered. |
| false | The callback could not be registered. |
Definition at line 612 of file Base.php.
Referenced by Erebot\Module\Base\reloadModule().
|
abstractprotected |
This method is called whenever the module is (re)loaded.
| int | $flags | A bitwise OR of the Erebot::Module::Base::RELOAD_* constants. Your method should take proper actions depending on the value of those flags. |
Referenced by Erebot\Module\Base\reloadModule().
|
final |
Public method to (re)load a module. This eventually reconfigures the bot.
| Erebot::Interfaces::Connection | $connection | IRC connection associated with this instance. |
| int | $flags | A bitwise OR of the Erebot::Module::Base::RELOAD_* constants. Your method should take proper actions depending on the value of those flags. |
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().
|
protected |
Unregister a timer.
| Erebot::TimerInterface | $timer | The timer to unregister. |
|
protected |
Send a raw command to the IRC server.
| string | $command | The command to send. |
Definition at line 425 of file Base.php.
References Erebot\Utils\stringifiable().
|
protected |
Send a message to a set of IRC targets (nicks or channels).
| string | list | $targets | Either a single nick or channel to which the message must be sent or an array of nicks/channels. |
| string | $message | The 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. |
| Exception | An 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.
| string | $iface | Name of the interface to act upon. |
| string | $cls | Name of the class that acts as a factory for that interface. If must implement that interface. |
Definition at line 234 of file Base.php.
Referenced by Erebot\Module\Base\__construct().
|
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().
|
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().