]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Phergie/Plugin/AutoJoin.php
a6d1adfbb2516c3c6fddc7ad3d7f32d63595acc0
[quix0rs-gnu-social.git] / plugins / Irc / extlib / phergie / Phergie / Plugin / AutoJoin.php
1 <?php
2 /**
3  * Phergie 
4  *
5  * PHP version 5
6  *
7  * LICENSE
8  *
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
13  *
14  * @category  Phergie 
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
20  */
21
22 /**
23  * Automates the process of having the bot join one or more channels upon
24  * connection to the server.
25  *
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.
32  *
33  * @category Phergie 
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
38  */
39 class Phergie_Plugin_AutoJoin extends Phergie_Plugin_Abstract
40 {
41     /**
42      * Intercepts the end of the "message of the day" response and responds by
43      * joining the channels specified in the configuration file.
44      *
45      * @return void
46      */
47     public function onResponse()
48     {
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];
59                     }
60                     if (is_array($channels)) {
61                         $channels = implode(',', $channels);
62                     }
63                 }
64                 $this->doJoin($channels);
65             }
66             $this->getPluginHandler()->removePlugin($this);
67         }
68     }
69 }