9 * This source file is subject to the new BSD license that is bundled
10 * with this package in the file LICENSE.
11 * It is also available through the world-wide-web at this URL:
12 * http://phergie.org/license
15 * @package Phergie_Plugin_AutoJoin
16 * @author Phergie Development Team <team@phergie.org>
17 * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
18 * @license http://phergie.org/license New BSD License
19 * @link http://pear.phergie.org/package/Phergie_Plugin_AutoJoin
23 * Automates the process of having the bot join one or more channels upon
24 * connection to the server.
26 * The configuration setting autojoin.channels is used to determine which
27 * channels to join. This setting can point to a comma-delimited string or
28 * enumerated array containing a single list of channels or an associative
29 * array keyed by hostname where each value is a comma-delimited string or
30 * enumerated array containing a list of channels to join on the server
31 * corresponding to that hostname.
34 * @package Phergie_Plugin_AutoJoin
35 * @author Phergie Development Team <team@phergie.org>
36 * @license http://phergie.org/license New BSD License
37 * @link http://pear.phergie.org/package/Phergie_Plugin_AutoJoin
39 class Phergie_Plugin_AutoJoin extends Phergie_Plugin_Abstract
42 * Intercepts the end of the "message of the day" response and responds by
43 * joining the channels specified in the configuration file.
47 public function onResponse()
49 switch ($this->getEvent()->getCode()) {
50 case Phergie_Event_Response::RPL_ENDOFMOTD:
51 case Phergie_Event_Response::ERR_NOMOTD:
52 if ($channels = $this->config['autojoin.channels']) {
53 if (is_array($channels)) {
54 // Support autojoin.channels being in these formats:
55 // 'hostname' => array('#channel1', '#channel2', ... )
56 $host = $this->getConnection()->getHost();
57 if (isset($channels[$host])) {
58 $channels = $channels[$host];
60 if (is_array($channels)) {
61 $channels = implode(',', $channels);
64 $this->doJoin($channels);
66 $this->getPluginHandler()->removePlugin($this);