Assembla home | Assembla project page
 

root/trunk/Phergie/Plugin/JoinPart.php

Revision 227, 2.6 kB (checked in by Slynderdale, 7 months ago)

Fixed a offset problem in Seen when retrieving records for others and their selves. Tweaked URL a bit to be more verbose why a URL failed.

Line 
1 <?php
2
3 /**
4  * Handles administrator-issued requests for the bot to join or part from a
5  * specified channel.
6  */
7 class Phergie_Plugin_JoinPart extends Phergie_Plugin_Abstract_Command
8 {
9     /**
10      * Flag indicating whether or not the plugin is an admin plugin or not
11      *
12      * @var bool
13      */
14     public $needsAdmin = true;
15
16     /**
17      * Joins the specified channel.
18      *
19      * @param string $channel Name of the channel to join
20      */
21     public function onDoJoin($channel)
22     {
23         if (!empty($channel)) {
24             $channel = preg_replace('/,\s+/', ',', trim($channel));
25             $this->doJoin($channel);
26         }
27     }
28
29     /**
30      * Parts either the specified channel or the channel from which the
31      * request originates if no channel is specified.
32      *
33      * @param string $channel Name of the channel to part (optional)
34      * @param Phergie_Event_Request $event Intercepted event
35      */
36     public function onDoPart($channel = null)
37     {
38         $source = $this->event->getSource();
39         $channel = trim($channel);
40
41         // If the channel is empty, part the current channel where the command was used
42         if (empty($channel) && $source[0] == '#') {
43             $this->doPart($source);
44         // Check whether a channel or multiple channels were given as well as a reason
45         } else if (preg_match('/^([#&][^\s,]+ (?:\s*,+\s* [#&][^\s,]+)* | all | \#)?(?:[\s,]+)?(.*)?$/xis', $channel, $match)) {
46             $channels = preg_replace(array('{\s}', '{,+}'), array('', ','), $match[1]);
47             if (!empty($channels) || $source[0] == '#') {
48                 if (empty($channels) || $channels == '#') {
49                     if ($source[0] != '#') return;
50                     $channels = $source;
51                 } else if ($channels == 'all') {
52                     //Check to see if the Users plugin is enabled  to retrieve a list of channels
53                     if (!$this->pluginLoaded('ServerInfo')) {
54                         // A fallback, most IRC servers cause the user to part all channels if they try to join 0
55                         $this->doJoin('0');
56                     } else {
57                         $channels = implode(',', Phergie_Plugin_ServerInfo::getChannels());
58                     }
59                 }
60
61                 $reason = trim($match[2]);
62                 if (substr($reason, 0, 1) === '(' && substr($reason, -1) === ')') {
63                     $reason = trim(substr($reason, 1, -1));
64                 }
65
66                 $this->doPart($channels, $reason);
67             }
68         }
69         unset($channel, $channels, $reason);
70     }
71 }
72
Note: See TracBrowser for help on using the browser.