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

A simple prompt which can be used to send commands remotely. More...

+ Inheritance diagram for Erebot\Prompt:

Public Member Functions

 __construct (\Erebot\Interfaces\Core $bot, $connector=null, $group=null, $perms=0660)
 
 __destruct ()
 Destructor.
 
 connect ()
 
 disconnect ($quitMessage=null)
 
 getBot ()
 
 getConfig ($chan)
 
 getIO ()
 
 getSocket ()
 
 isConnected ()
 
 process ()
 Processes commands queued in the input buffer.
 
 read ()
 

Protected Member Functions

 handleMessage ($line)
 

Protected Attributes

 $bot
 A bot object implementing the Erebot::Interfaces::Core interface.
 
 $io
 I/O manager for the socket.
 
 $socket
 The underlying socket, represented as a stream.
 

Detailed Description

A simple prompt which can be used to send commands remotely.

This class can be used by external processes to send commands through the bot. It creates a UNIX socket other programs can send commands to whenever they want the bot to send certain commands to an IRC server.

Such commands must be prefixed by a pattern (which accepts '*' and '?' as wildcards, but not the full grammar of regular expressions) to indicate which server(s) the command must be sent to (hint: '*' can be used to refer to all servers the bot is connected to).

This makes in possible to display the output of some shell script on IRC. For example, the following command would display the output of /some/command.sh to #Erebot on all servers the bot is currently connected to:

/some/command.sh | sed 's/^/* PRIVMSG #Erebot :/' | \
* socat - UNIX-SENDTO:/path/to/the/prompt.sock
*

Definition at line 45 of file Prompt.php.

Constructor & Destructor Documentation

Erebot\Prompt::__construct ( \Erebot\Interfaces\Core  $bot,
  $connector = null,
  $group = null,
  $perms = 0660 
)

Constructs the UNIX socket that represents the prompt.

Parameters
Erebot::Interfaces::Core$botInstance of the bot to operate on.
string$connector(optional) Path where the newly-created UNIX socket will be made accessible. The default is to create a UNIX socket named "Erebot.sock" in the system's temporary directory (usually "/tmp/").
mixed$group(optional) Either the name or the identifier of the UNIX group the socket will belong to. The default is to not change the group of the socket (i.e. to keep whatever is the main group for the user running Erebot).
int$perms(optional) UNIX permissions the newly-created socket will receive. The default is to give read/write access to the user running Erebot and to the group the socket belongs to (see $group).
Note
On most systems, only the superuser may change the group of a file arbitrarily, while other users may only change it to a group they are a member of.
Warning
Using the wrong combination of $group and $perms may lead to security issues. Use with caution. The default values are safe as long as you trust users belonging to the same group as the main group of the user running Erebot.
See also
http://php.net/chmod provides more information on the meaning of $perms' value (see the description for mode).

Definition at line 99 of file Prompt.php.

Member Function Documentation

Erebot\Prompt::connect ( )

Makes the actual connection to an IRC server, using the configuration data passed to the constructor.

Exceptions
Erebot::ConnectionFailureExceptionThrown whenever the bot fails to establish a connection to the given server.

Implements Erebot\Interfaces\Connection.

Definition at line 171 of file Prompt.php.

Erebot\Prompt::disconnect (   $quitMessage = null)

Disconnects the bot from that particular IRC server.

Parameters
string$quitMessage(optional) A message which will be visible by other users when the bot gets disconnected. If no message is given, the IrcConnector module is probed for its "quit_message" parameter. If no message is available, the bot quits with an empty string as its quit message.

Implements Erebot\Interfaces\Connection.

Definition at line 176 of file Prompt.php.

Erebot\Prompt::getBot ( )

Returns the bot instance this connection is associated with.

Return values
Erebot::Interfaces::CoreAn instance of the core class (Erebot).

Implements Erebot\Interfaces\Connection.

Definition at line 251 of file Prompt.php.

Erebot\Prompt::getConfig (   $chan)

Retrieves the configuration for a given channel.

Parameters
null | string$chanThe name of the IRC channel for which a configuration must be retrieved. If $chan is null, the configuration associated with this object is returned instead (an instance of the Erebot::Interfaces::Config::Server).
Return values
Erebot::Interfaces::Config::ChannelThe configuration for the given channel, if there is one.
Erebot::Interfaces::Config::ServerOtherwise, the configuration for the associated IRC server.
Exceptions
Erebot::NotFoundExceptionNo Erebot::Interfaces::Config::Channel object exists for the given channel.

Implements Erebot\Interfaces\Connection.

Definition at line 256 of file Prompt.php.

Erebot\Prompt::getIO ( )

Returns the object used to handle I/O (input/output) with this connection.

Note
Do not use this object directly unless you know what you're doing. Instead, use the methods from the appropriate interfaces: Erebot::Interfaces::SendingConnection for writing and Erebot::Interfaces::ReceivingConnection for reading.

Implements Erebot\Interfaces\Connection.

Definition at line 195 of file Prompt.php.

Erebot\Prompt::getSocket ( )

Returns the underlying transport implementation for this connection.

Return values
streamReturns this connection's socket, as a PHP stream.
Note
You generally don't need any sort of access to this stream, but it may be useful in cases where you need to do a select() on the connection.

Implements Erebot\Interfaces\Connection.

Definition at line 190 of file Prompt.php.

Erebot\Prompt::handleMessage (   $line)
protected

Handles a line received from the prompt.

Parameters
string$lineA single line of text received from the prompt, with the end-of-line sequence stripped.

Definition at line 224 of file Prompt.php.

Erebot\Prompt::isConnected ( )

Returns whether this connection object is currently connected to a server.

Return values
booltrue if the connection is really connected, false otherwise.

Implements Erebot\Interfaces\Connection.

Definition at line 185 of file Prompt.php.

Erebot\Prompt::read ( )

Processes data from the incoming buffer.

Once this method has been called, all lines awaiting processing in the incoming buffer have been transferred to the incoming FIFO. You must call Erebot::Connection::processQueuedData() after that in order to process the lines in the FIFO. This is done so that a throttling policy may be put in place if needed (eg. for an anti-flood system).

Implements Erebot\Interfaces\ReceivingConnection.

Definition at line 200 of file Prompt.php.


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