Changeset 203
- Timestamp:
- 04/03/08 01:31:13 (8 months ago)
- Files:
-
- trunk/Phergie/Bot.php (modified) (1 diff)
- trunk/Phergie/Driver/Abstract.php (modified) (2 diffs)
- trunk/Phergie/Driver/Streams.php (modified) (14 diffs)
- trunk/Phergie/Plugin/Abstract/Base.php (modified) (7 diffs)
- trunk/Phergie/Plugin/Abstract/Command.php (modified) (1 diff)
- trunk/Phergie/Plugin/Acronym.php (modified) (1 diff)
- trunk/Phergie/Plugin/ChuckNorris.php (modified) (5 diffs)
- trunk/Phergie/Plugin/Debug.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Dice.php (modified) (3 diffs)
- trunk/Phergie/Plugin/Drink.php (modified) (1 diff)
- trunk/Phergie/Plugin/Eval.php (modified) (2 diffs)
- trunk/Phergie/Plugin/JoinPart.php (modified) (1 diff)
- trunk/Phergie/Plugin/Karma.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Lart.php (modified) (9 diffs)
- trunk/Phergie/Plugin/Logging.php (modified) (1 diff)
- trunk/Phergie/Plugin/ModuleList.php (modified) (5 diffs)
- trunk/Phergie/Plugin/Quit.php (modified) (1 diff)
- trunk/Phergie/Plugin/Sed.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Seen.php (modified) (8 diffs)
- trunk/Phergie/Plugin/Set.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Tld.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Toggle.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Url.php (modified) (10 diffs)
- trunk/Phergie/Plugin/Weather.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Bot.php
r200 r203 140 140 case 'util': 141 141 $file = constant('PHERGIE_' . strtoupper($type) . '_DIR') . $name . '.php'; 142 if (file_exists($file) && is_readable($file)) { 143 require_once($file); 144 if (class_exists($class)) { 145 return; 146 } 147 } 142 148 break; 143 }144 145 if (file_exists($file) && is_readable($file)) {146 require_once($file);147 if (class_exists($class)) {148 return;149 }150 149 } 151 150 } trunk/Phergie/Driver/Abstract.php
r200 r203 7 7 abstract class Phergie_Driver_Abstract 8 8 { 9 /**#@+10 * Return codes for the run function, that tells the Bot script whether11 * it should re-run or not12 */13 const RETURN_RECONNECT = "reconnect";14 const RETURN_KEEPALIVE = "keepalive";15 const RETURN_END = "end";16 /**#@-*/9 /**#@+ 10 * Return codes for the run function, that tells the Bot script whether 11 * it should re-run or not 12 */ 13 const RETURN_RECONNECT = "reconnect"; 14 const RETURN_KEEPALIVE = "keepalive"; 15 const RETURN_END = "end"; 16 /**#@-*/ 17 17 18 18 /** … … 140 140 } 141 141 142 /**143 * Returns all the plugins.144 * 145 * @return Phergie_Plugin_Abstract_Base146 */147 public function getPlugins()148 {149 return $this->plugins;150 }151 152 /**153 * Returns a list of all the plugins either currently loaded or within the154 * plugin directory.155 *156 * @param $plugin $dirList If true, scan the Plugin directory for the list157 * @return array158 */159 public function getPluginList($dirList = false, $preserveExt = false)160 {161 if (!$dirList) {162 return array_keys($this->plugins);163 } else {164 $iterator = new DirectoryIterator(PHERGIE_PLUGIN_DIR);165 $plugins = array();166 167 foreach ($iterator as $filename) {168 if ($iterator->isFile() && pathinfo($filename, PATHINFO_EXTENSION) == 'php') {169 $plugins[] = ($preserveExt ? (string) $filename : basename((string) $filename, '.php'));170 }171 }172 unset($iterator, $filename, $dirList);173 174 return $plugins;175 }176 }177 178 /**179 * Returns a plugin instance.180 * 181 * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix)182 * @return Phergie_Plugin_Abstract_Base183 */184 public function getPlugin($plugin)185 {186 $plugin = strtolower($plugin);187 if (isset($this->plugins[$plugin]))188 return $this->plugins[$plugin];189 return false;190 }142 /** 143 * Returns all the plugins. 144 * 145 * @return Phergie_Plugin_Abstract_Base 146 */ 147 public function getPlugins() 148 { 149 return $this->plugins; 150 } 151 152 /** 153 * Returns a list of all the plugins either currently loaded or within the 154 * plugin directory. 155 * 156 * @param $plugin $dirList If true, scan the Plugin directory for the list 157 * @return array 158 */ 159 public function getPluginList($dirList = false, $preserveExt = false) 160 { 161 if (!$dirList) { 162 return array_keys($this->plugins); 163 } else { 164 $iterator = new DirectoryIterator(PHERGIE_PLUGIN_DIR); 165 $plugins = array(); 166 167 foreach ($iterator as $filename) { 168 if ($iterator->isFile() && pathinfo($filename, PATHINFO_EXTENSION) == 'php') { 169 $plugins[] = ($preserveExt ? (string) $filename : basename((string) $filename, '.php')); 170 } 171 } 172 unset($iterator, $filename, $dirList); 173 174 return $plugins; 175 } 176 } 177 178 /** 179 * Returns a plugin instance. 180 * 181 * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix) 182 * @return Phergie_Plugin_Abstract_Base 183 */ 184 public function getPlugin($plugin) 185 { 186 $plugin = strtolower($plugin); 187 if (isset($this->plugins[$plugin])) 188 return $this->plugins[$plugin]; 189 return false; 190 } 191 191 192 192 /** trunk/Phergie/Driver/Streams.php
r192 r203 103 103 public function run() 104 104 { 105 $this->startTime = time();106 $returnCode = $this->getIni('keepalive') ? self::RETURN_KEEPALIVE : self::RETURN_END;105 $this->startTime = time(); 106 $returnCode = $this->getIni('keepalive') ? self::RETURN_KEEPALIVE : self::RETURN_END; 107 107 $server = $this->getIni('server'); 108 108 $port = $this->getIni('port'); … … 118 118 119 119 if ($this->getIni('timeout')) { 120 $timeout = $this->getIni('timeout') * 60;120 $timeout = $this->getIni('timeout') * 60; 121 121 } elseif ($this->getIni('keepalive')) { 122 $timeout = 600;123 } else {124 $timeout = false;125 }126 $lastPacket = time();122 $timeout = 600; 123 } else { 124 $timeout = false; 125 } 126 $lastPacket = time(); 127 127 128 128 unset($port); … … 163 163 $buffer = fgets($this->socket, 512); 164 164 165 // Check if we timed out166 if ($timeout !== false) {167 // Reset last packet timestamp if we received something168 if (!empty($buffer)) {169 $lastPacket = time();170 }171 // Timed out, exit172 if ($lastPacket < (time() - $timeout)) {173 $this->debug('Timed out');174 foreach ($this->plugins as $plugin) {175 $plugin->shutdown();176 }177 break 2;178 }179 }165 // Check if we timed out 166 if ($timeout !== false) { 167 // Reset last packet timestamp if we received something 168 if (!empty($buffer)) { 169 $lastPacket = time(); 170 } 171 // Timed out, exit 172 if ($lastPacket < (time() - $timeout)) { 173 $this->debug('Timed out'); 174 foreach ($this->plugins as $plugin) { 175 $plugin->shutdown(); 176 } 177 break 2; 178 } 179 } 180 180 } 181 181 $buffer = rtrim($buffer); … … 202 202 $temp = preg_split('/ :?/', trim($args), 2); 203 203 if(substr($temp[1], 0, 1) === chr(1) && substr($temp[1], -1) === chr(1)) { 204 $ctcp = trim(substr($temp[1], 1, -1));205 list ($cmd, $args) = explode(' ', $ctcp.' ', 2);204 $ctcp = trim(substr($temp[1], 1, -1)); 205 list ($cmd, $args) = explode(' ', $ctcp.' ', 2); 206 206 $cmd = strtolower($cmd); 207 207 208 208 // Check for the type of Notice message and handle it accordingly 209 209 if ($cmd == 'action') { 210 // Return sender as source and the action as its first argument210 // Return sender as source and the action as its first argument 211 211 $args = array($nick, trim($args)); 212 212 } elseif ($cmd == 'ping' || $cmd == 'version' || $cmd == 'time') { 213 // Return sender as source and the rest of the args as its first argument214 $cmd = $cmd.'Reply';213 // Return sender as source and the rest of the args as its first argument 214 $cmd = $cmd.'Reply'; 215 215 $args = array($nick, trim($args)); 216 216 } else { 217 // Return sender as source and the ctcp as its first argument217 // Return sender as source and the ctcp as its first argument 218 218 $cmd = 'ctcpReply'; 219 219 $args = array($nick, $ctcp); … … 240 240 if(substr($temp[1], 0, 1) === chr(1) && substr($temp[1], -1) === chr(1)) { 241 241 $ctcp = trim(substr($temp[1], 1, -1)); 242 list ($cmd, $args) = explode(' ', $ctcp.' ', 2);242 list ($cmd, $args) = explode(' ', $ctcp.' ', 2); 243 243 $cmd = strtolower($cmd); 244 244 245 245 // Check for the type of CTCP message and handle it accordingly 246 246 if ($cmd == 'action') { 247 $botnick = $this->getIni('nick');248 // If sent within a channel, use the chanel as the source, else use the sender249 $source = (strtolower($temp[0]) == strtolower($botnick) ? $nick : $temp[0]);250 // Return channel/sender as source and the action as its first argument247 $botnick = $this->getIni('nick'); 248 // If sent within a channel, use the chanel as the source, else use the sender 249 $source = (strtolower($temp[0]) == strtolower($botnick) ? $nick : $temp[0]); 250 // Return channel/sender as source and the action as its first argument 251 251 $args = array($source, trim($args)); 252 252 } elseif ($cmd == 'ping' && !empty($args)) { 253 // Return nick of sender as source and the handshake as its first argument254 $args = array($nick, trim($args));253 // Return nick of sender as source and the handshake as its first argument 254 $args = array($nick, trim($args)); 255 255 } elseif (($cmd == 'version' || $cmd == 'time') && empty($args)) { 256 // Return nick of sender as source and the ctcp as its first argument256 // Return nick of sender as source and the ctcp as its first argument 257 257 $args = array($nick, $ctcp); 258 258 } else { 259 // Return nick of sender as source and the ctcp as its first argument259 // Return nick of sender as source and the ctcp as its first argument 260 260 $cmd = 'ctcp'; 261 261 $args = array($nick, $ctcp); … … 286 286 foreach ($this->plugins as $plugin) { 287 287 // Skip disabled plugins 288 if ($plugin->enabled === false) {289 continue;290 }288 if ($plugin->enabled === false) { 289 continue; 290 } 291 291 $plugin->setEvent($event); 292 292 // onRaw Handlers … … 317 317 } 318 318 if (isset($this->queue['quit'][0][1])) { 319 $returnCode = ($this->queue['quit'][0][1] === true ? self::RETURN_RECONNECT : self::RETURN_END);319 $returnCode = ($this->queue['quit'][0][1] === true ? self::RETURN_RECONNECT : self::RETURN_END); 320 320 } 321 321 $this->doQuit($reason); … … 340 340 public function send($command, array $arguments = array()) 341 341 { 342 $command = strtolower($command);342 $command = strtolower($command); 343 343 if ($this->queueing) { 344 344 if (!isset($this->queue[$command])) { … … 347 347 $this->queue[$command][] = $arguments; 348 348 } else { 349 if ($command == Phergie_Event_Request::TYPE_RAW) {349 if ($command == Phergie_Event_Request::TYPE_RAW) { 350 350 $buffer = (count($arguments) > 0 ? implode(' ', $arguments) : ''); 351 } else {351 } else { 352 352 $buffer = strtoupper($command); 353 353 if (count($arguments) > 0) { … … 373 373 { 374 374 if ($this->queueing) { 375 $this->send(Phergie_Event_Request::TYPE_QUIT, array($reason, $reconnect));375 $this->send(Phergie_Event_Request::TYPE_QUIT, array($reason, $reconnect)); 376 376 } else { 377 $this->send(Phergie_Event_Request::TYPE_QUIT, array($reason));377 $this->send(Phergie_Event_Request::TYPE_QUIT, array($reason)); 378 378 } 379 379 } … … 559 559 public function doCtcp($target, $command, $arguments = '') 560 560 { 561 if (is_array($arguments)) {561 if (is_array($arguments)) { 562 562 $arguments = implode(' ', $arguments); 563 }563 } 564 564 $this->doPrivmsg($target, chr(1) . trim(strtoupper($command) . ' ' . $arguments) . chr(1)); 565 565 } … … 595 595 public function doVersionReply($target, $version = '') 596 596 { 597 $version = trim($version);598 if (empty($version)) {599 $version = 'Phergie '.PHERGIE_VERSION.' - An IRC bot written in PHP (http://www.phergie.com)';600 }597 $version = trim($version); 598 if (empty($version)) { 599 $version = 'Phergie '.PHERGIE_VERSION.' - An IRC bot written in PHP (http://www.phergie.com)'; 600 } 601 601 $this->doCtcpReply($target, 'version', $version); 602 602 } … … 610 610 public function doTimeReply($target, $time = '') 611 611 { 612 $time = trim($time);613 if (empty($time) || ctype_digit($time)) {614 if (empty($time)) $time = time();615 $time = date('D M d H:i:s o', $time);616 }612 $time = trim($time); 613 if (empty($time) || ctype_digit($time)) { 614 if (empty($time)) $time = time(); 615 $time = date('D M d H:i:s o', $time); 616 } 617 617 $this->doCtcpReply($target, 'time', $time); 618 618 } … … 626 626 public function doCtcpReply($target, $command, $reply = '') 627 627 { 628 $command = trim($command);629 if (empty($command))630 return;628 $command = trim($command); 629 if (empty($command)) 630 return; 631 631 $this->send(Phergie_Event_Request::TYPE_NOTICE, array($target, chr(1).trim(strtoupper($command).' '.$reply).chr(1))); 632 632 } trunk/Phergie/Plugin/Abstract/Base.php
r202 r203 122 122 public final function onBaseError($errno, $errstr, $errfile, $errline) { 123 123 if (!isset($this)) { 124 return false;124 return false; 125 125 } 126 126 return call_user_func_array(array($this, 'onPhpError'), array($errno, $errstr, $errfile, $errline)); … … 258 258 // Use the translit extension if installed else fallback on to basic transliteration 259 259 if (extension_loaded('iconv')) { 260 $text = iconv($charSetFrom, $charSetTo.'//TRANSLIT', $text);260 $text = iconv($charSetFrom, $charSetTo.'//TRANSLIT', $text); 261 261 // Transliteration supprt via the translit extension is still experimental 262 262 } else if (false && extension_loaded('translit')) { … … 284 284 case 0: 285 285 return chr(0); 286 case ($code & 0x7F):287 return chr($code);288 289 // 2 bytes, 11 bits290 case ($code & 0x7FF):291 return chr(0xC0 | (($code >> 6) & 0x1F)) .286 case ($code & 0x7F): 287 return chr($code); 288 289 // 2 bytes, 11 bits 290 case ($code & 0x7FF): 291 return chr(0xC0 | (($code >> 6) & 0x1F)) . 292 292 chr(0x80 | ($code & 0x3F)); 293 293 294 // 3 bytes, 16 bits295 case ($code & 0xFFFF):296 return chr(0xE0 | (($code >> 12) & 0x0F)) .294 // 3 bytes, 16 bits 295 case ($code & 0xFFFF): 296 return chr(0xE0 | (($code >> 12) & 0x0F)) . 297 297 chr(0x80 | (($code >> 6) & 0x3F)) . 298 298 chr(0x80 | ($code & 0x3F)); 299 299 300 // 4 bytes, 21 bits301 case ($code & 0x1FFFFF):302 return chr(0xF0 | ($code >> 18)) .300 // 4 bytes, 21 bits 301 case ($code & 0x1FFFFF): 302 return chr(0xF0 | ($code >> 18)) . 303 303 chr(0x80 | (($code >> 12) & 0x3F)) . 304 304 chr(0x80 | (($code >> 6) & 0x3F)) . … … 328 328 */ 329 329 public function parseArguments($args) { 330 // Strip away multiple spaces331 $args = ' '.preg_replace('#\s+#', ' ', trim($args)).' ';332 333 // Check the args string for agurments334 preg_match_all('{'.335 // String Regex: Matches "" | "foo" | "foo bar" | "foo \" bar" | foo336 '(".*?(?<!\\\)" | [^-+\s]+) | '.337 // Option Regex: Matches --opt | --opt foo | --opt= | --opt=foo | --opt="" | --opt="foo" | --opt="foo bar"338 '(--\w+ (?:=".*?(?<!\\\)" | [=\s][^-+"\s]*)?) | '.339 // Flag Regex: Matches -flag +flag340 '([-+]\w+)'.341 '}xi',342 $args, $matches);343 // Shifts the first group matches element off of matches344 $matches = array_shift($matches);345 346 // Returned data structure347 $data = array(348 'strings' => array(),349 'commands' => array(),350 'flags' => array(),351 'all' => array(352 'strings' => '',353 'commands' => array(),354 'flags' => array()355 )356 );357 358 // Loop through the results359 foreach ($matches as $match) {360 $match = trim($match);361 // Check to see if the current match an an --option362 if (substr($match, 0, 2 ) === '--') {363 $value = preg_split('/[=\s]/', $match, 2);364 $com = substr(array_shift($value), 2);365 $value = trim(join($value));366 // Strip quotes from the option's value367 $realValue = (substr($value, 0, 1) === '"' && substr($value, -1) === '"' || substr($match, -1) === '=');368 if(substr($value, 0, 1) === '"' && substr($value, -1) === '"') {369 $value = trim(substr($value, 1, -1));370 }371 if (!in_array($com, $data['all']['commands']))372 $data['all']['commands'][] = $com;373 $data['commands'][$com] = (!empty($value) || $realValue? str_replace('\"', '"', $value) : true);374 continue;375 }376 377 // Check to see if the current match is a -flag378 if (substr($match, 0, 1) === '-' || substr($match, 0, 1) === '+') {379 $flag = substr($match, 1);380 if (!in_array($flag, $data['all']['flags']))381 $data['all']['flags'][] = $flag;382 // Handle the flags using bitwise operations. 1=-flag, 2=+flag, 3=Both a plus and minus383 if (isset($data['flags'][$flag])) {384 $data['flags'][$flag] |= (substr($match, 0, 1) === '-' ? 0x1 : 0x2);385 } else {386 $data['flags'][$flag] = (substr($match, 0, 1) === '-' ? 0x1 : 0x2);387 }388 continue;389 }390 391 // Strip the quotes away from match392 if(substr($match, 0, 1) === '"' && substr($match, -1) === '"') {393 $match = trim(substr($match, 1, -1));394 }395 // The match value isn't a flag or an option so consider it a string396 if (!empty($match))397 $data['strings'][] = str_replace('\"', '"', $match);398 }399 400 $data['all']['strings'] = trim(implode(' ', $data['strings']));401 return $data;330 // Strip away multiple spaces 331 $args = ' '.preg_replace('#\s+#', ' ', trim($args)).' '; 332 333 // Check the args string for agurments 334 preg_match_all('{'. 335 // String Regex: Matches "" | "foo" | "foo bar" | "foo \" bar" | foo 336 '(".*?(?<!\\\)" | [^-+\s]+) | '. 337 // Option Regex: Matches --opt | --opt foo | --opt= | --opt=foo | --opt="" | --opt="foo" | --opt="foo bar" 338 '(--\w+ (?:=".*?(?<!\\\)" | [=\s][^-+"\s]*)?) | '. 339 // Flag Regex: Matches -flag +flag 340 '([-+]\w+)'. 341 '}xi', 342 $args, $matches); 343 // Shifts the first group matches element off of matches 344 $matches = array_shift($matches); 345 346 // Returned data structure 347 $data = array( 348 'strings' => array(), 349 'commands' => array(), 350 'flags' => array(), 351 'all' => array( 352 'strings' => '', 353 'commands' => array(), 354 'flags' => array() 355 ) 356 ); 357 358 // Loop through the results 359 foreach ($matches as $match) { 360 $match = trim($match); 361 // Check to see if the current match an an --option 362 if (substr($match, 0, 2 ) === '--') { 363 $value = preg_split('/[=\s]/', $match, 2); 364 $com = substr(array_shift($value), 2); 365 $value = trim(join($value)); 366 // Strip quotes from the option's value 367 $realValue = (substr($value, 0, 1) === '"' && substr($value, -1) === '"' || substr($match, -1) === '='); 368 if(substr($value, 0, 1) === '"' && substr($value, -1) === '"') { 369 $value = trim(substr($value, 1, -1)); 370 } 371 if (!in_array($com, $data['all']['commands'])) 372 $data['all']['commands'][] = $com; 373 $data['commands'][$com] = (!empty($value) || $realValue? str_replace('\"', '"', $value) : true); 374 continue; 375 } 376 377 // Check to see if the current match is a -flag 378 if (substr($match, 0, 1) === '-' || substr($match, 0, 1) === '+') { 379 $flag = substr($match, 1); 380 if (!in_array($flag, $data['all']['flags'])) 381 $data['all']['flags'][] = $flag; 382 // Handle the flags using bitwise operations. 1=-flag, 2=+flag, 3=Both a plus and minus 383 if (isset($data['flags'][$flag])) { 384 $data['flags'][$flag] |= (substr($match, 0, 1) === '-' ? 0x1 : 0x2); 385 } else { 386 $data['flags'][$flag] = (substr($match, 0, 1) === '-' ? 0x1 : 0x2); 387 } 388 continue; 389 } 390 391 // Strip the quotes away from match 392 if(substr($match, 0, 1) === '"' && substr($match, -1) === '"') { 393 $match = trim(substr($match, 1, -1)); 394 } 395 // The match value isn't a flag or an option so consider it a string 396 if (!empty($match)) 397 $data['strings'][] = str_replace('\"', '"', $match); 398 } 399 400 $data['all']['strings'] = trim(implode(' ', $data['strings'])); 401 return $data; 402 402 } 403 403 … … 430 430 } 431 431 432 if ($time > 0 || count($return) <= 0) {433 $return[] = $time . 's';434 }432 if ($time > 0 || count($return) <= 0) { 433 $return[] = $time . 's'; 434 } 435 435 436 436 return implode(' ', $return); … … 450 450 if (!empty($plugin)) { 451 451 if (!$client) { 452 $client = $this->client;452 $client = $this->client; 453 453 } 454 454 if (!is_array($plugins) || count($plugins) <= 0) { … … 748 748 } 749 749 if (((isset($source) && isset($this->muted[$source]) && $this->muted[$source]) || 750 (isset($this->muted['global']) && $this->muted['global'])) &&751 substr($method, 0, 2) === 'do') {752 return false;750 (isset($this->muted['global']) && $this->muted['global'])) && 751 substr($method, 0, 2) === 'do') { 752 return false; 753 753 } 754 754 trunk/Phergie/Plugin/Abstract/Command.php
r202 r203 83 83 if ($this->needsAdmin && !$this->fromAdmin()) { 84 84 $this->doNotice($user, 'You do not have permission to use the command "' . $command . '."'); 85 return;85 return; 86 86 } 87 87 trunk/Phergie/Plugin/Acronym.php
r200 r203 108 108 $today = date('md'); 109 109 110 // Matches an optional "Nick: " followed by an acronym formatted as A.B.C. or ABC110 // Matches an optional "Nick: " followed by an acronym formatted as A.B.C. or ABC 111 111 if (!preg_match('/^(?:[A-Za-z0-9\[\]`|{}_-]+: )?((?:[A-Z]\.?){2,})\?$/', $message, $acronym)) { 112 112 return; trunk/Phergie/Plugin/ChuckNorris.php
r200 r203 182 182 private function findChuckNorris() { 183 183 if (!$this->db) { 184 return false;184 return false; 185 185 } 186 186 … … 211 211 private function feedChuckNorris() { 212 212 if (!$this->db) { 213 return false;213 return false; 214 214 } 215 215 … … 242 242 { 243 243 if (!$this->db) { 244 return;244 return; 245 245 } 246 246 … … 259 259 { 260 260 if (!$this->db) { 261 return;261 return; 262 262 } 263 263 … … 296 296 297 297 if (!$this->db) { 298 return;298 return; 299 299 } 300 300 trunk/Phergie/Plugin/Debug.php
r200 r203 23 23 { 24 24 if (function_exists('memory_get_usage')) { 25 $target = $this->event->getNick();25 $target = $this->event->getNick(); 26 26 $text = 'Current : '.number_format(memory_get_usage() / 1024).'KB' . 27 27 (function_exists('memory_get_peak_usage') ? ' / Peak : '.number_format(memory_get_peak_usage() / 1024).'KB' : ''); … … 76 76 77 77 if (empty($prog)) { 78 $message = 'Phergie Version: ' . PHERGIE_VERSION;78 $message = 'Phergie Version: ' . PHERGIE_VERSION; 79 79 } else if ($prog == 'php') { 80 $message = 'PHP Version: ' . phpversion();80 $message = 'PHP Version: ' . phpversion(); 81 81 } else if (is_array($extensions) && in_array($prog, $extensions)) { 82 $version = phpversion($prog);83 $message = ucfirst($prog) . ' Version: ' . ($version ? $version : 'N/A');82 $version = phpversion($prog); 83 $message = ucfirst($prog) . ' Version: ' . ($version ? $version : 'N/A'); 84 84 } else { 85 $message = 'Unknown Extension: ' . ucfirst($prog);85 $message = 'Unknown Extension: ' . ucfirst($prog); 86 86 } 87 87 $this->doPrivmsg($this->event->getSource(), $target . ': ' . $message); trunk/Phergie/Plugin/Dice.php
r200 r203 22 22 */ 23 23 protected $max = array( 24 'total' => 20,25 'dice' => 100,26 'sides' => 10024 'total' => 20, 25 'dice' => 100, 26 'sides' => 100 27 27 ); 28 28 … … 99 99 if (!empty($message)) { 100 100 if (preg_match('{^(?:([0-9]+)[\#|:|\s])?(?:([0-9]+)[\s|d])?(?:[\s|d]?([0-9]+))(?:([+-])(.*))?$}ix', $message, $m)) { 101 if (isset($m[1]) && (!isset($m[2]) or empty($m[2]))) {102 $m[2] = $m[1]; $m[1] = null;103 }104 $numDice = ($m[1] < 1 ? 1 : ($m[1] > $this->max['total'] ? $this->max['total'] : $m[1]));105 $dice = ($m[2] < 1 ? 1 : ($m[2] > $this->max['dice'] ? $this->max['dice'] : $m[2]));106 $sides = ($m[3] < 1 ? 1 : ($m[3] > $this->max['sides'] ? $this->max['sides'] : $m[3]));107 $operator = (isset($m[4]) && $m[4] == '+' ? true : false);108 $expression = ((isset($m[5]) && !empty($m[5])) ? trim($m[5]) : '0');101 if (isset($m[1]) && (!isset($m[2]) or empty($m[2]))) { 102 $m[2] = $m[1]; $m[1] = null; 103 } 104 $numDice = ($m[1] < 1 ? 1 : ($m[1] > $this->max['total'] ? $this->max['total'] : $m[1])); 105 $dice = ($m[2] < 1 ? 1 : ($m[2] > $this->max['dice'] ? $this->max['dice'] : $m[2])); 106 $sides = ($m[3] < 1 ? 1 : ($m[3] > $this->max['sides'] ? $this->max['sides'] : $m[3])); 107 $operator = (isset($m[4]) && $m[4] == '+' ? true : false); 108 $expression = ((isset($m[5]) && !empty($m[5])) ? trim($m[5]) : '0'); 109 109 110 110 $bonus = 0; 111 if (!empty($expression) && $this->allowExpressions) {112 $bonus = $this->processExpression($expression);113 if (is_null($bonus)) {114 return ' Error while processing the dice expression.';115 }116 }111 if (!empty($expression) && $this->allowExpressions) { 112 $bonus = $this->processExpression($expression); 113 if (is_null($bonus)) { 114 return ' Error while processing the dice expression.'; 115 } 116 } 117 117 118 118 $output = array(); … … 120 120 $total = 0; 121 121 for($d = 0; $d < $dice; $d++) { 122 $total += intval(mt_rand(1, $sides) + ($operator ? $bonus : ($bonus * -1)));122 $total += intval(mt_rand(1, $sides) + ($operator ? $bonus : ($bonus * -1))); 123 123 } 124 124 $output[] = $total; trunk/Phergie/Plugin/Drink.php
r200 r203 88 88 $this->db = new PDO('sqlite:' . $this->dir . 'drink.db'); 89 89 if (!$this->db) { 90 return;90 &n