3 * StatusNet - the distributed open-source microblogging tool
\r
5 * This program is free software: you can redistribute it and/or modify
\r
6 * it under the terms of the GNU Affero General Public License as published by
\r
7 * the Free Software Foundation, either version 3 of the License, or
\r
8 * (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU Affero General Public License for more details.
\r
15 * You should have received a copy of the GNU Affero General Public License
\r
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
18 * Extends the bot class (Phergie_Bot) to allow connection and access to
\r
19 * sockets and to allow StatusNet to 'drive' the bot
\r
22 * @package Phergie_StatusnetBot
\r
23 * @author Luke Fitzgerald <lw.fitzgerald@googlemail.com>
\r
24 * @copyright 2010 StatusNet, Inc.
\r
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
\r
26 * @link http://status.net/
\r
28 class Phergie_StatusnetBot extends Phergie_Bot {
\r
30 * Set up bot and connect to servers
\r
34 public function connect() {
\r
35 $ui = $this->getUi();
\r
36 $ui->setEnabled($this->getConfig('ui.enabled'));
\r
38 $this->loadPlugins();
\r
39 $this->loadConnections();
\r
43 * Transmit raw command to server using driver
\r
45 * Handles construction of command strings and their transmission to the
\r
48 * @param string $command Command to send
\r
49 * @param string|array $args Optional string or array of sequential
\r
52 * @return string Command string that was sent
\r
53 * @throws Phergie_Driver_Exception
\r
55 public function send($command, $args = '') {
\r
56 return $this->getDriver()->send($command, $args);
\r
60 * Handle incoming data on the socket using the handleEvents
\r
61 * method of the Processor
\r
65 public function handleEvents() {
\r
66 $this->getProcessor()->handleEvents();
\r
70 * Close the current connection and reconnect to the server
\r
74 public function reconnect() {
\r
75 $driver = $this->getDriver();
\r
76 $sockets = $driver->getSockets();
\r
78 // Close any existing connections
\r
80 $driver->forceQuit();
\r
81 } catch (Phergie_Driver_Exception $e){}
\r
83 $driver->doConnect();
\r
84 } catch (Phergie_Driver_Exception $e){
\r
85 $driver->forceQuit();
\r
91 * Get the sockets used by the bot
\r
93 * @return array Array of socket resources
\r
95 public function getSockets() {
\r
96 return $this->getDriver()->getSockets();
\r