Assembla home | Assembla project page
 

root/trunk/Phergie/Plugin/ModuleList.php

Revision 223, 7.1 kB (checked in by Slynderdale, 6 months ago)

Various bug fixes and enhancements:

Notable Changes:

  • Bot.php: The auto loader now strips out the "Phergie_" prefix from class names while getting the path to the class file to include for those who don't have the bot in a directory called Phergie. Both the Phergie directory and the parent directory were added to the include path. Also added a check to see if they have a timezone is set in PHP.ini, if not, set the timezone to the default timezone to prevent strict errors while using date.
  • Streams.php: Added support for invite requests and also fixed a small bug where an empty command gets ent to call_user_func due to a packet getting cut off.
  • Base.php: Added onInvite and changed fromAdmin so the first argunent needs to be set to true for hostmask admin checking.
  • Lart.php: Improved lart a bit and fixed bugs where you couldn't remove certain terms due to spacing/character casing issues
  • Seen.php: Added a quote command to get a random quote by a specified user
  • Users.php: Renamed Users to ServerInfo to prepare it for future changes to make it store more information about users, channels and the server. Also fixed a bug where halfops and voiced users were considered an OP.
Line 
1 <?php
2
3 /**
4  * Handles requests from administrators to list currently running plugins.
5  * By default, plugins returns a list of all the plugins running.
6  * Optionally, you can pass arguments such as plugins -m to list all the
7  * muted. Multiple arguments can bepassed such as plugins -m -d to get a
8  * list of all the muted and disabled plugins.
9  */
10 class Phergie_Plugin_ModuleList extends Phergie_Plugin_Abstract_Command
11 {
12     /**
13      * Flag indicating whether or not the plugin is an admin plugin or not
14      *
15      * @var bool
16      */
17     public $needsAdmin = true;
18
19     /**
20      * An array containing a list of arguments as the array's keys that are
21      * available and the value is what the argurment is mapped to.
22      *
23      * @var array
24      */
25     protected $argList = array(
26         'v' => 'Verbose', // Extended/Verbose All Plugins List
27         'e' => 'Enabled', // Enabled Plugins List
28         'd' => 'Disabled', // Disabled Plugins List
29         'm' => 'Muted', // Muted Plugins list
30         'g' => 'Global_Muted', // Global Muted Plugins List
31         'l' => 'Local_Muted', // Local/Current Channel Muted plugins list
32         'u' => 'Unmuted', // Unmuted Plugins List
33         'p' => 'Passive', // Passive Plugins List
34         'a' => 'Admin', // Admin Plugins List
35         'b' => 'Base', // Base/Core Plugins List
36         'i' => 'Inactive', // Inactive Plugins List
37     );
38
39     /**
40      * An array containing a list of states to display on the verbose plugin
41      * list. The keys are the values from $argList and the values are the
42      * letters to append to the verbose list.
43      *
44      * @var array
45      */
46     protected $verboseList = array(
47         'Admin' => 'A',
48         'Disabled' => 'D',
49         'Local_Muted' => 'L',
50         'Global_Muted' => 'G',
51         'Passive' => 'P',
52         'Inactive' => 'I'
53     );
54
55     public function onDoPlugins($rawArgs = '')
56     {
57         $source = $this->event->getSource();
58         $rawArgs = $this->parseArguments($rawArgs);
59         $target = trim(strtolower(!empty($rawArgs['strings'][0]) && $this->fromAdmin(true) ? $rawArgs['strings'][0] : $source));
60         $pluginData = array();
61
62         // Loop through the parsed args and formats them
63         $args = array();
64         foreach($rawArgs['flags'] as $arg => $value) {
65             if ($arg == 'mg' || $arg == 'mutedglobal') $arg = 'g';
66             else if ($arg == 'ml' || $arg == 'mutedlocal') $arg = 'l';
67             $args[substr(strtolower($arg), 0, 1)] = $value;
68         }
69         unset($rawArgs);
70
71         // Help command, return a list of all supprted commands
72         if (isset($args['h'])) {
73             $message = 'Help Info: ';
74             foreach($this->argList as $arg => $info) {
75                 // Get the commands. Format: -c, -command = Info
76                 $message .= '-'.$arg.', -'.str_replace('_','',strtolower($info)).' = '.
77                             str_replace('_',' ',ucfirst($info)).' '.($arg == 'v'?'mode':'plugins').' | ';
78             }
79             $this->doPrivmsg($source, trim($message, "| \t\n\r\0\v\0xa0"));
80             return;
81         }
82
83         // Retrieve and loop through th plugins to gather a list of information about them.
84         $plugins = $this->getPluginList(true);
85         foreach($plugins as $plugin) {
86             $plugin = ucfirst(trim($plugin));
87             if (!empty($plugin)) {
88                 $data = $this->getPlugin($plugin);
89                 if ($data) {
90                     // Checks to see if the plugin is an enabled plugin or not
91                     if ($data->enabled) {
92                         $pluginData['Enabled'][] = $plugin;
93                     } else {
94                         $pluginData['Disabled'][] = $plugin;
95                     }
96
97                     // Checks to see if the plugin is a muted plugin or not
98                     if (!empty($data->muted[$target]) || !empty($data->muted['global'])) {
99                         $pluginData['Muted'][] = $plugin . (!empty($data->muted['global']) ? '*' : '');
100                         if (!empty($data->muted['global'])) {
101                             $pluginData['Global_Muted'][] = $plugin;
102                         }
103                         if (!empty($data->muted[$target])) {
104                             $pluginData['Local_Muted'][] = $plugin;
105                         }
106                     } else {
107                         $pluginData['Unmuted'][] = $plugin;
108                     }
109
110                     // Checks to see if the plugin is an admin plugin or not
111                     if ($data->needsAdmin) {
112                         $pluginData['Admin'][] = $plugin;
113                     } else {
114                         $pluginData['Base'][] = $plugin;
115                     }
116
117                     // Checks to see if the plugin is a passive plugin or not
118                     if ($data->passive) {
119                         $pluginData['Passive'][] = $plugin;
120                     }
121
122                     // All plugins list
123                     $pluginData['Plugins'][] = $plugin;
124                 }
125                 // Checks to see if the plugin is an inactive plugin or not
126                 else {
127                     $pluginData['Inactive'][] = $plugin;
128                 }
129
130                 // Extended/Verbose plugins list that shows every plugin and their state
131                 $state = null;
132                 if (isset($args['v']) && is_array($pluginData)) {
133                     foreach($this->verboseList as $key => $value) {
134                         if (isset($pluginData[$key]) and is_array($pluginData[$key]) &&
135                             in_array($plugin, $pluginData[$key])) {
136                             $state .= $value;
137                         }
138                     }
139                     // Format the append data if its set
140                     $pluginData['Verbose'][] = $plugin . (!empty($state) ? '(' . trim($state) . ')' : '');
141                 }
142             }
143         }
144         unset($plugins);
145
146         // Go through the list of any passed arugments and generate the plugin list for them
147         $message = null;
148         if (!isset($args['v']) && is_array($args) && count($args) > 0) {
149             foreach($args as $arg => $value) {
150                 $plugin = $this->argList[$arg];
151                 if (isset($plugin)) {
152                     if (is_array($pluginData[$plugin]) && count($pluginData[$plugin]) > 0) {
153                         sort($pluginData[$plugin]);
154                     }
155                     $plugins = trim(count($pluginData[$plugin]) > 0 ? implode(', ', $pluginData[$plugin]) : '');
156                     $message .= ucfirst(str_replace('_', ' ', $plugin)) . ': ' . ($plugins ? $plugins : 'No Plugins') . ' :: ';
157                 }
158             }
159             unset($plugins);
160         }
161
162         // If the message is empty, aka no args were passed, return the full plugin list
163         if (empty($message)) {
164             $display = (isset($args['v']) ? 'Verbose' : 'Plugins');
165             if (is_array($pluginData[$display])) {
166                 sort($pluginData[$display]);
167                 $message = $display . ': ' . implode(', ', $pluginData[$display]);
168             }
169         }
170
171         $this->doPrivmsg($source, trim($message, ": \t\n\r\0\v\0xa0"));
172         unset($message);
173     }
174 }
175
Note: See TracBrowser for help on using the browser.