Changeset 103
- Timestamp:
- 03/02/08 15:50:02 (9 months ago)
- Files:
-
- trunk/Phergie/Driver/Abstract.php (modified) (3 diffs)
- trunk/Phergie/Driver/Streams.php (modified) (3 diffs)
- trunk/Phergie/Plugin/Abstract/AdminCommand.php (modified) (1 diff)
- trunk/Phergie/Plugin/Debug.php (modified) (2 diffs)
- trunk/Phergie/phergie.ini (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Driver/Abstract.php
r96 r103 58 58 59 59 /** 60 * Parses a IRC hostmask and sets nick, user and host bits61 *62 * @param string $hostmask Hostmask to parse63 * @param string $nick Container for the nick64 * @param string $user Container for the username65 * @param string $host Container for the hostname66 * @return void67 */60 * Parses a IRC hostmask and sets nick, user and host bits. 61 * 62 * @param string $hostmask Hostmask to parse 63 * @param string $nick Container for the nick 64 * @param string $user Container for the username 65 * @param string $host Container for the hostname 66 * @return void 67 */ 68 68 public function parseHostmask($hostmask, &$nick, &$user, &$host) 69 69 { … … 73 73 $host = $hostmask; 74 74 } 75 } 76 77 /** 78 * Converts a delimited string of hostmasks into a regular expression 79 * that will match any hostmask in the original string. 80 * 81 * @param string $list Delimited string of hostmasks 82 * @return string Regular expression 83 */ 84 public function hostmasksToRegex($list) 85 { 86 $patterns = array(); 87 88 foreach (preg_split('#[\s\r\n,]+#', $list) as $hostmask) { 89 // Find out which chars are present in the config mask and exclude them from the regex match 90 $excluded = ''; 91 if (strpos($hostmask, '!')!==false) { 92 $excluded .= '!'; 93 } 94 if (strpos($hostmask, '@')!==false) { 95 $excluded .= '@'; 96 } 97 98 // Escape regex meta characters 99 $hostmask = str_replace( 100 array('\\', '^', '$', '.', '[', ']', '|', '(', ')', '?', '+', '{', '}'), 101 array('\\\\', '\\^', '\\$', '\\.', '\\[', '\\]', '\\|', '\\(', '\\)', '\\?', '\\+', '\\{', '\\}'), 102 $hostmask 103 ); 104 105 // Replace * so that they match correctly in a regex 106 $patterns[] = str_replace('*', ($excluded === '' ? '.*' : '[^'.$excluded.']*'), $hostmask); 107 } 108 109 return ('#^' . implode('|', $patterns) . '$#'); 75 110 } 76 111 … … 102 137 103 138 /** 104 * Returns a plugin instance105 *106 * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix)107 * @return Phergie_Plugin_Abstract_Base108 */139 * Returns a plugin instance 140 * 141 * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix) 142 * @return Phergie_Plugin_Abstract_Base 143 */ 109 144 public abstract function getPlugin($plugin); 110 145 trunk/Phergie/Driver/Streams.php
r98 r103 165 165 166 166 unset($params); 167 168 $ignore = $this->hostmasksToRegex($this->getIni('ignore')); 167 169 168 170 while(true) { … … 249 251 250 252 foreach ($this->plugins as $plugin) { 251 if ($plugin->enabled === false) { // Skip disabled plugins 253 // Skip disabled plugins 254 if ($plugin->enabled === false) { 252 255 continue; 253 256 } … … 255 258 if ($event instanceof Phergie_Event_Response) { 256 259 $plugin->onResponse(); 257 } else { 260 // Skip events from ignored users 261 } elseif (!preg_match($ignore, $event->getHostmask())) { 258 262 call_user_func(array($plugin, 'on' . ucfirst($event->getType()))); 259 263 } trunk/Phergie/Plugin/Abstract/AdminCommand.php
r96 r103 83 83 } 84 84 if (!empty ($ini)) { 85 $admins = preg_split('#[\s\r\n,]+#', $ini); 86 foreach ($admins as $admin) { 87 // Find out which chars are present in the config mask and exclude them from the regex match 88 $excluded = ''; 89 if (strpos($admin, '!')!==false) { 90 $excluded .= '!'; 91 } 92 if (strpos($admin, '@')!==false) { 93 $excluded .= '@'; 94 } 95 96 // Escape regex meta characters 97 $admin = str_replace( 98 array('\\', '^', '$', '.', '[', ']', '|', '(', ')', '?', '+', '{', '}'), 99 array('\\\\', '\\^', '\\$', '\\.', '\\[', '\\]', '\\|', '\\(', '\\)', '\\?', '\\+', '\\{', '\\}'), 100 $admin 101 ); 102 // Replace * so that they match correctly in a regex 103 $this->admins[$class][] = str_replace('*', ($excluded === '' ? '.*' : '[^'.$excluded.']*'), $admin); 104 } 105 $this->admins[$class] = '#^' . implode('|', $this->admins[$class]) . '$#'; 85 $this->admins[$class] = $this->hostmasksToRegex($ini); 106 86 } 107 87 } trunk/Phergie/Plugin/Debug.php
r60 r103 13 13 { 14 14 /** 15 * Timestamp used to calculate uptime 16 * 17 * @var int 18 */ 19 protected $uptime; 20 21 /** 22 * Initializes a local timestamp used to calculate uptime. 23 * 24 * @return void 25 */ 26 public function init() 27 { 28 parent::init(); 29 30 $this->uptime = time(); 31 } 32 33 /** 15 34 * Responds to requests for statistics related to the bot's memory 16 35 * consumption. … … 23 42 $this->doPrivmsg($this->event->getSource(), $text); 24 43 } 44 45 /** 46 * Returns the amount of time the bot has been up. 47 * 48 * @return void 49 */ 50 public function onDoUptime() 51 { 52 $diff = time() - $this->uptime; 53 $uptime = array(); 54 55 $days = floor($diff / 86400); 56 if ($days > 0) { 57 $uptime[] = $days . 'd'; 58 $diff = $diff % 86400; 59 } 60 61 $hours = floor($diff / 3600); 62 if ($hours > 0) { 63 $uptime[] = $hours . 'h'; 64 $diff = $diff % 3600; 65 } 66 67 $minutes = floor($diff / 60); 68 if ($minutes > 0) { 69 $uptime[] = $minutes . 'm'; 70 $diff = $diff % 60; 71 } 72 73 $uptime[] = $diff . 's'; 74 75 $uptime = 'uptime : ' . implode(' ', $uptime); 76 77 $this->doPrivmsg($this->event->getSource(), $uptime); 78 } 25 79 } trunk/Phergie/phergie.ini
r102 r103 54 54 ; bad words, etc. defaults to false. 55 55 curses = false 56 57 ; ignore : 58 ; a comma- or space-delimited list of hostmasks (may contain wildcards 59 ; using *) of users from which events should be ignored (i. e. not 60 ; processed by plugins), surrounded by double-quotes 61 ignore = 56 62 57 63 ; plugins :