3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
23 * IRC background connection manager for IRC-using queue handlers,
24 * allowing them to send outgoing messages on the right connection.
26 * Input is handled during socket select loop, keepalive pings during idle.
27 * Any incoming messages will be handled.
29 * In a multi-site queuedaemon.php run, one connection will be instantiated
30 * for each site being handled by the current process that has IRC enabled.
33 class IrcManager extends ImManager {
37 * Initialize connection to server.
38 * @return boolean true on success
40 public function start($master) {
41 if (parent::start($master)) {
49 public function getSockets() {
52 return array($this->conn->myConnection);
59 * Process IRC events that have come in over the wire.
60 * @param resource $socket
62 public function handleInput($socket) {
63 common_log(LOG_DEBUG, "Servicing the IRC queue.");
64 $this->stats('irc_process');
65 $this->conn->receive();
70 $this->conn = new Phergie_Bot;
72 $password = isset($this->plugin->password) ? $this->plugin->password : NULL;
73 $transport = isset($this->plugin->transport) ? $this->plugin->transport : 'tcp';
74 $encoding = isset($this->plugin->encoding) ? $this->plugin->encoding : 'ISO-8859-1';
76 $config = new Phergie_Extended_Config;
79 // One array per connection, pretty self-explanatory
80 'connections' => array(
81 // Ex: All connection info for the Freenode network
83 'host' => $this->plugin->host,
84 'port' => $this->plugin->port,
85 'username' => $this->plugin->username,
86 'realname' => $this->plugin->realname,
87 'nick' => $this->plugin->nickname,
88 'password' => $password,
89 'transport' => $transport,
90 'encoding' => $encoding
94 'processor' => 'async',
95 'processor.options' => array('usec' => 200000),
96 // Time zone. See: http://www.php.net/manual/en/timezones.php
99 // Whitelist of plugins to load
101 // To enable a plugin, simply add a string to this array containing
102 // the short name of the plugin as shown below.
104 // 'ShortPluginName',
106 // Below is an example of enabling the AutoJoin plugin, for which
107 // the corresponding PEAR package is Phergie_Plugin_AutoJoin. This
108 // plugin allows you to set a list of channels in this configuration
109 // file that the bot will automatically join when it connects to a
110 // server. If you'd like to enable this plugin, simply install it,
111 // uncomment the line below, and set a value for the setting
112 // autojoin.channels (examples for which are located further down in
117 // A few other recommended plugins:
119 // Servers randomly send PING events to clients to ensure that
120 // they're still connected and will eventually terminate the
122 // connection if a PONG response is not received. The Pong plugin
123 // handles sending these responses.
127 // It's sometimes difficult to distinguish between a lack of
128 // activity on a server and the client not receiving data even
129 // though a connection remains open. The Ping plugin performs a self
130 // CTCP PING sporadically to ensure that its connection is still
131 // functioning and, if not, terminates the bot.
135 // Sometimes it's desirable to have the bot disconnect gracefully
136 // when issued a command to do so via a PRIVMSG event. The Quit
137 // plugin implements this using the Command plugin to intercept the
143 // If set to true, this allows any plugin dependencies for plugins
144 // listed in the 'plugins' option to be loaded even if they are not
145 // explicitly included in that list
146 'plugins.autoload' => true,
148 // Enables shell output describing bot events via Phergie_Ui_Console
149 'ui.enabled' => true,
151 // Examples of supported values for autojoins.channel:
152 // 'autojoin.channels' => '#channel1,#channel2',
153 // 'autojoin.channels' => array('#channel1', '#channel2'),
154 // 'autojoin.channels' => array(
155 // 'host1' => '#channel1,#channel2',
156 // 'host2' => array('#channel3', '#channel4')
159 // Examples of setting values for Ping plugin settings
161 // This is the amount of time in seconds that the Ping plugin will wait
162 // to receive an event from the server before it initiates a self-ping
164 // 'ping.event' => 300, // 5 minutes
166 // This is the amount of time in seconds that the Ping plugin will wait
167 // following a self-ping attempt before it assumes that a response will
168 // never be received and terminates the connection
170 // 'ping.ping' => 10, // 10 seconds
173 $this->conn=new Aim($this->plugin->user,$this->plugin->password,4);
174 $this->conn->registerHandler("IMIn",array($this,"handle_aim_message"));
175 $this->conn->myServer="toc.oscar.aol.com";
176 $this->conn->signon();
177 $this->conn->setProfile(_m('Send me a message to post a notice'), false);
182 function handle_irc_message($data) {
183 $this->plugin->enqueue_incoming_raw($data);
187 function send_raw_message($data) {
192 $this->conn->sflapSend($data[0],$data[1],$data[2],$data[3]);