Changeset 194
- Timestamp:
- 03/29/08 13:28:33 (8 months ago)
- Files:
-
- trunk/Phergie/Event/Request.php (modified) (1 diff)
- trunk/Phergie/Plugin/Abstract/Cron.php (modified) (1 diff)
- trunk/Phergie/Plugin/Acronym.php (modified) (7 diffs)
- trunk/Phergie/Plugin/Altnick.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Autojoin.php (modified) (2 diffs)
- trunk/Phergie/Plugin/ChuckNorris.php (modified) (13 diffs)
- trunk/Phergie/Plugin/Convert.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Ctcp.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Daddy.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Debug.php (modified) (8 diffs)
- trunk/Phergie/Plugin/Dns.php (modified) (3 diffs)
- trunk/Phergie/Plugin/Drink.php (modified) (3 diffs)
- trunk/Phergie/Plugin/Eval.php (modified) (3 diffs)
- trunk/Phergie/Plugin/FeedTicker.php (modified) (4 diffs)
- trunk/Phergie/Plugin/JoinPart.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Karma.php (modified) (13 diffs)
- trunk/Phergie/Plugin/Lart.php (modified) (3 diffs)
- trunk/Phergie/Plugin/Logging.php (modified) (11 diffs)
- trunk/Phergie/Plugin/Math.php (modified) (2 diffs)
- trunk/Phergie/Plugin/ModuleList.php (modified) (6 diffs)
- trunk/Phergie/Plugin/Nickserv.php (modified) (8 diffs)
- trunk/Phergie/Plugin/Php.php (modified) (1 diff)
- trunk/Phergie/Plugin/Pong.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Puppet.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Quit.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Reconnect.php (modified) (3 diffs)
- trunk/Phergie/Plugin/Sed.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Seen.php (modified) (14 diffs)
- trunk/Phergie/Plugin/Set.php (modified) (5 diffs)
- trunk/Phergie/Plugin/Spellcheck.php (modified) (7 diffs)
- trunk/Phergie/Plugin/Tld.php (modified) (7 diffs)
- trunk/Phergie/Plugin/Toggle.php (modified) (2 diffs)
- trunk/Phergie/Plugin/UrbanDictionary.php (modified) (5 diffs)
- trunk/Phergie/Plugin/Url.php (modified) (9 diffs)
- trunk/Phergie/Plugin/Users.php (modified) (17 diffs)
- trunk/Phergie/Plugin/Weather.php (modified) (5 diffs)
- trunk/Phergie/phergie.ini (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Event/Request.php
r167 r194 114 114 115 115 self::TYPE_PART => array( 116 'channel' => 0 116 'channel' => 0, 117 'message' => 1 117 118 ), 118 119 trunk/Phergie/Plugin/Abstract/Cron.php
r166 r194 4 4 * @see Phergie_Plugin_Abstract_Base 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/Base.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Base.php'; 7 7 8 8 /** trunk/Phergie/Plugin/Acronym.php
r180 r194 4 4 * @see Phergie_Plugin_Abstract_Base 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/Base.php'; 7 8 /** 9 * @see Phergie_Plugin_Users 10 */ 11 require_once 'Phergie/Plugin/Users.php'; 6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Base.php'; 12 7 13 8 /** … … 79 74 80 75 /** 81 * Returns whether or not the plugin's dependencies are met.82 *83 * @param Phergie_Driver_Abstract $client Client instance84 * @param array $plugins List of short names for plugins that the85 * bootstrap file intends to instantiate86 * @see Phergie_Plugin_Abstract_Base::checkDependencies()87 * @return bool TRUE if dependencies are met, FALSE otherwise88 */89 public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins)90 {91 if (! in_array('Users', $plugins)92 || ! Phergie_Plugin_Users::checkDependencies($client, $plugins)) {93 return false;94 }95 96 return true;97 }98 99 /**100 76 * Returns a random action, meant for cases where an acronym lookup 101 77 * returns no results. … … 107 83 { 108 84 do { 109 $reaction = $this->reactions[ rand(0, count($this->reactions) - 1)];110 $randomUser = strpos($reaction, '%randomuser%');85 $reaction = $this->reactions[mt_rand(0, count($this->reactions) - 1)]; 86 $randomUser = (strpos($reaction, '%randomuser%') !== false); 111 87 } while ($target[0] != '#' && $randomUser); 112 88 if ($randomUser) { 113 $nick = $this->getIni('nick'); 114 do { 115 $user = Phergie_Plugin_Users::getRandomUser($target); 116 } while ($user == $nick); 89 if ($this->pluginLoaded('Users')) { 90 $nick = $this->getIni('nick'); 91 do { 92 $user = Phergie_Plugin_Users::getRandomUser($target); 93 } while ($user == $nick); 94 } else { 95 $user = $this->event->getNick(); 96 } 117 97 $reaction = str_replace('%randomuser%', $user, $reaction); 118 98 } … … 128 108 public function onPrivmsg() 129 109 { 130 $ target= $this->event->getSource();110 $source = $this->event->getSource(); 131 111 $message = $this->event->getArgument(1); 112 $target = $this->event->getNick(); 132 113 $today = date('md'); 133 114 … … 144 125 145 126 if (in_array($acronym, array('WHO', 'WHAT', 'WHERE', 'WHEN', 'WHY', 'HOW'))) { 146 $this->doAction($ target, 'shrugs.');127 $this->doAction($source, 'shrugs.'); 147 128 return; 148 129 } … … 170 151 || strpos($contents, 'no abbreviation matches') !== false 171 152 || strpos($contents, 'has exceeded the daily query limit') !== false) { 172 $this->randomAction($ target);153 $this->randomAction($source); 173 154 return; 174 155 } else { … … 200 181 201 182 $text = 'Possible matches for ' . $acronym . ': ' . implode('; ', $matches); 202 $this->doPrivmsg($ target,$text);183 $this->doPrivmsg($source, $target . ': ' . $text); 203 184 } 204 185 } trunk/Phergie/Plugin/Altnick.php
r71 r194 4 4 * @see Phergie_Plugin_Abstract_Base 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/Base.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Base.php'; 7 7 8 8 /** … … 12 12 class Phergie_Plugin_Altnick extends Phergie_Plugin_Abstract_Base 13 13 { 14 /** 15 * Determines if the plugin is a passive plugin or not 16 * 17 * @var bool 18 */ 19 public $passive = true; 20 14 21 /** 15 22 * Index of the last alternate nick that the bot attempted to use trunk/Phergie/Plugin/Autojoin.php
r175 r194 4 4 * @see Phergie_Plugin_Abstract_Base 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/Base.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Base.php'; 7 7 8 8 /** … … 15 15 class Phergie_Plugin_Autojoin extends Phergie_Plugin_Abstract_Base 16 16 { 17 /** 18 * Determines if the plugin is a passive plugin or not 19 * 20 * @var bool 21 */ 22 public $passive = true; 23 17 24 /** 18 25 * Returns whether or not the current environment meets the requirements trunk/Phergie/Plugin/ChuckNorris.php
r179 r194 4 4 * @see Phergie_Plugin_Abstract_Base 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/Command.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Base.php'; 7 7 8 8 /** … … 12 12 * into a database for quick access. 13 13 */ 14 class Phergie_Plugin_ChuckNorris extends Phergie_Plugin_Abstract_ Command14 class Phergie_Plugin_ChuckNorris extends Phergie_Plugin_Abstract_Base 15 15 { 16 16 … … 63 63 * @var int 64 64 */ 65 protected $floodCheck = 10; 65 protected $floodCheck = 30; 66 67 /** 68 * The chance of responding with a random Chuck Norris fact. The chance can 69 * bet set anywheres from 1 - 100 while a value like 50 is a 50% chance. 70 * Set to 0 or below or a value of 100 or higher to disable. 71 * 72 * @var int 73 */ 74 protected $chance = 50; 66 75 67 76 /** … … 81 90 // Initialize the database connection 82 91 $this->db = new PDO('sqlite:' . $this->dir . 'norris.db'); 92 if (!$this->db) { 93 return; 94 } 83 95 84 96 // Populate the database if necessary … … 92 104 } 93 105 } catch (PDOException $e) { } 106 107 $this->chance = intval($this->chance); 108 $this->floodCheck = intval($this->floodCheck); 94 109 } 95 110 … … 118 133 */ 119 134 private function getChuckNorris($doCrawl = true) { 120 // The current page to retrieve121 $page = trim($this->factHost . $this->crawlPage);135 // The current page to retrieve 136 $page = trim($this->factHost . $this->crawlPage); 122 137 123 138 $this->debug('Retrieving page '.$this->crawlNum.' => '.$this->crawlPage); 124 139 $contents = @file_get_contents($page); 125 140 if ($contents !== false) { 126 $this->debug('Parsing page '.$this->crawlNum.' => '.$this->crawlPage);141 $this->debug('Parsing page '.$this->crawlNum.' => '.$this->crawlPage); 127 142 preg_match_all('#<li>\s*([^<]+)\s*(?:<br>\s* )?<\/li>#im', $contents, $matches); 128 143 … … 147 162 foreach ($pages as $page => $url) { 148 163 if ($page > $this->crawlNum) { 149 $this->crawlNum = $page;164 $this->crawlNum = $page; 150 165 $this->crawlPage = $url; 151 166 … … 171 186 */ 172 187 private function findChuckNorris() { 188 if (!$this->db) { 189 return false; 190 } 191 173 192 // Checks to see if the chuckfacts table exists 174 193 $table = $this->db … … 196 215 */ 197 216 private function feedChuckNorris() { 217 if (!$this->db) { 218 return false; 219 } 220 198 221 // Check to see if there are any facts to insert 199 222 if (count($this->norrisFacts) > 0) { … … 223 246 private function praiseChuckNorris() 224 247 { 248 if (!$this->db) { 249 return; 250 } 251 225 252 return $this->db 226 253 ->query('SELECT facts FROM chuckfacts ORDER BY Random() LIMIT 1') … … 236 263 public function onPrivmsg() 237 264 { 265 if (!$this->db) { 266 return; 267 } 268 238 269 $source = $this->event->getSource(); 239 270 $message = $this->event->getArgument(1); … … 241 272 // Check to see if the message includes the word Chuck Norris. If so, check to see if 242 273 // it was a bot request by checking for Fact: at the begiining and also do a floodpro check 243 if ( !preg_match('{^(?:' . $this->getIni('nick') . '\s*:?\s+)}i', $message, $m) &&244 preg_match('{(chuck\s+norris)}i', $message, $m) &&245 strtolower(substr($message, 0, 5)) != 'fact:'&&246 ($this->floodCheck <= 0 || ($this->floodCache[$source] < (time() - $this->floodCheck)))) {274 if (preg_match('{^('.preg_quote($this->getIni('nick')).'\s*:?\s+)?\s*(chuck\s+norris)}ix', $message, $m) && 275 strtolower(substr($message, 0, 5)) != 'fact:' && ($source[0] != '#' || 276 (!empty($m[1]) || $this->chance <= 0 || $this->chance >= 100 || mt_rand(1, 100) < $this->chance) && 277 ($this->floodCheck <= 0 || ($this->floodCache[$source] < (time() - $this->floodCheck))))) { 247 278 248 279 // Retrieves a random fact … … 250 281 if (!empty($fact)) { 251 282 $this->doPrivmsg($source, 'Fact: '.$fact); 252 $this->floodCache[$source] = time(); 283 if ($source[0] == '#') { 284 $this->floodCache[$source] = time(); 285 } 253 286 unset($m, $fact); 254 287 } 255 288 } 256 289 } 290 291 /** 292 * Parses incoming CTCP request for the word "Chuck Norris" and respond with 293 * a random Chuck Norris fact retrieved from the Chuck Norris fact page. 294 * 295 * @return void 296 */ 297 public function onCtcp() 298 { 299 $source = $this->event->getSource(); 300 $ctcp = $this->event->getArgument(1); 301 302 if (!$this->db) { 303 return; 304 } 305 306 if (preg_match('{chuck[\s_+-]*norris}ix', $ctcp, $m)) { 307 // Retrieves a random fact 308 $fact = $this->praiseChuckNorris(); 309 if (!empty($fact)) { 310 $this->doCtcpReply($source, 'CHUCKNORRIS', $fact); 311 } 312 } 313 } 257 314 } trunk/Phergie/Plugin/Convert.php
r179 r194 4 4 * @see Phergie_Plugin_Abstract_Command 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/Command.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Command.php'; 7 7 8 8 /** … … 13 13 { 14 14 /** 15 * Returns whether or not the plugin's dependencies are met. 16 * 17 * @param Phergie_Driver_Abstract $client Client instance 18 * @param array $plugins List of short names for plugins that the 19 * bootstrap file intends to instantiate 20 * @see Phergie_Plugin_Abstract_Base::checkDependencies() 21 * @return bool TRUE if dependencies are met, FALSE otherwise 22 */ 23 public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 24 { 25 if (!extension_loaded('Dom')) { 26 return false; 27 } 28 29 return true; 30 } 31 32 /** 15 33 * Performs a unit conversion and returns the result in a message. 16 34 * … … 20 38 public function onDoConvert($convert) 21 39 { 40 $target = $this->event->getNick(); 41 22 42 $context = stream_context_create(array('http' => array( 23 43 'timeout' => 5, … … 38 58 $text = $result->item(0)->nodeValue; 39 59 40 $this->doPrivmsg($this->event->getSource(), $t ext);60 $this->doPrivmsg($this->event->getSource(), $target . ': ' . $text); 41 61 } 42 62 } trunk/Phergie/Plugin/Ctcp.php
r166 r194 1 1 <?php 2 2 3 require_once 'Phergie/Plugin/Abstract/Base.php';3 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Base.php'; 4 4 5 5 /** … … 8 8 class Phergie_Plugin_Ctcp extends Phergie_Plugin_Abstract_Base 9 9 { 10 /** 11 * Determines if the plugin is a passive plugin or not 12 * 13 * @var bool 14 */ 15 public $passive = true; 16 10 17 public function onTime() 11 18 { … … 41 48 $ctcp = strtoupper($this->event->getArgument(1)); 42 49 50 // Uncaught PING requests 51 if ($ctcp == 'PING') 52 $this->doCtcpReply($source, 'pong'); 43 53 // SOURCE Request, reply with the path to Phergie's SVN 44 if ($ctcp == 'SOURCE')54 else if ($ctcp == 'SOURCE') 45 55 { 46 56 $this->doCtcpReply($source, 'source', 'svn2.assembla.com:/svn/phergie/trunk/Phergie/:'); 57 } 47 58 //FINGER Request, reply with the not's real name 48 }49 59 else if ($ctcp == 'FINGER') 50 60 { … … 54 64 $finger = 'Realname: '.(!empty($realname) ? $realname: $name); 55 65 $this->doCtcpReply($source, 'finger', $finger); 66 } 56 67 // UPTIME Request, reply with the bot's uptime 57 }58 68 else if ($ctcp == 'UPTIME') 59 69 { trunk/Phergie/Plugin/Daddy.php
r176 r194 4 4 * @see Phergie_Plugin_Abstract_Base 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/Base.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Base.php'; 7 7 8 8 /** … … 22 22 $bot = $this->getIni('nick'); 23 23 $text = $this->event->getArgument(1); 24 $target = $this->event->getNick(); 24 25 if (preg_match('/' . preg_quote($bot) . '\s*:?\s+?who\'?s y(?:our|a) ([^?]+)\??/iAD', $text, $m)) { 25 if($this->getIni('curses') && rand(0,5) === 5) {26 $this->doPrivmsg($this->event->getSource(), $t his->event->getNick(). ': I am your ' . $m[1] . ', bitch!');26 if($this->getIni('curses') && mt_rand(0,5) === 5) { 27 $this->doPrivmsg($this->event->getSource(), $target . ': I am your ' . $m[1] . ', bitch!'); 27 28 } else { 28 $this->doPrivmsg($this->event->getSource(), 'You\'re my ' . $m[1] . ', ' . $t his->event->getNick(). '!');29 $this->doPrivmsg($this->event->getSource(), 'You\'re my ' . $m[1] . ', ' . $target . '!'); 29 30 } 30 31 } trunk/Phergie/Plugin/Debug.php
r181 r194 2 2 3 3 /** 4 * @see Phergie_Plugin_Abstract_ AdminCommand4 * @see Phergie_Plugin_Abstract_Command 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/AdminCommand.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Command.php'; 7 7 8 8 /** … … 10 10 * of memory consumption. 11 11 */ 12 class Phergie_Plugin_Debug extends Phergie_Plugin_Abstract_ AdminCommand12 class Phergie_Plugin_Debug extends Phergie_Plugin_Abstract_Command 13 13 { 14 /** 15 * Flag indicating whether or not the plugin is an admin plugin or not 16 * 17 * @var bool 18 */ 19 public $needsAdmin = true; 20 14 21 /** 15 22 * Responds to requests for statistics related to the bot's memory … … 20 27 public function onDoMem() 21 28 { 22 if (function_exists('memory_get_usage') && function_exists('memory_get_peak_usage')) { 23 $text = 'current : '.number_format(memory_get_usage() / 1024).'KB / peak : '.number_format(memory_get_peak_usage() / 1024).'KB'; 24 $this->doPrivmsg($this->event->getSource(), $text); 29 if (function_exists('memory_get_usage')) { 30 $target = $this->event->getNick(); 31 $text = 'Current : '.number_format(memory_get_usage() / 1024).'KB' . 32 (function_exists('memory_get_peak_usage') ? ' / Peak : '.number_format(memory_get_peak_usage() / 1024).'KB' : ''); 33 $this->doPrivmsg($this->event->getSource(), $target . ': ' . $text); 25 34 } 26 35 } … … 33 42 public function onDoUptime() 34 43 { 35 $uptime = 'Uptime: ' . $this->getCountdown(time() - $this->getStartTime());44 $target = $this->event->getNick(); 36 45 37 $this->doPrivmsg($this->event->getSource(), $ uptime);46 $this->doPrivmsg($this->event->getSource(), $target . ': Uptime: ' . $this->getCountdown(time() - $this->getStartTime())); 38 47 } 39 48 … … 45 54 public function onDoExtensions() 46 55 { 56 $target = $this->event->getNick(); 57 47 58 $extensions = get_loaded_extensions(); 48 59 if (is_array($extensions)) { … … 50 61 sort($extensions); 51 62 } 52 $this->doPrivmsg($this->event->getSource(), 'Loaded Extensions: ' . (is_array($extensions) ? implode(', ', $extensions) : 'N/A'));63 $this->doPrivmsg($this->event->getSource(), $target . ': Loaded Extensions: ' . (is_array($extensions) ? implode(', ', $extensions) : 'N/A')); 53 64 unset($extensions); 54 65 } … … 61 72 public function onDoGetversion($prog = null) 62 73 { 74 $target = $this->event->getNick(); 75 63 76 $prog = (isset($prog) ? trim(strtolower($prog)) : null); 64 77 $extensions = get_loaded_extensions(); … … 66 79 $extensions = array_map('strtolower', $extensions); 67 80 } 68 if (!isset($prog) || empty($prog)) { 69 $this->doPrivmsg($this->event->getSource(), 'Phergie Version: ' . PHERGIE_VERSION); 81 82 if (empty($prog)) { 83 $message = 'Phergie Version: ' . PHERGIE_VERSION; 70 84 } else if ($prog == 'php') { 71 $ this->doPrivmsg($this->event->getSource(), 'PHP Version: ' . phpversion());85 $message = 'PHP Version: ' . phpversion(); 72 86 } else if (is_array($extensions) && in_array($prog, $extensions)) { 73 if ($prog == 'gd' && function_exists('gd_info')) { 74 $version = gd_info(); 75 $this->doPrivmsg($this->event->getSource(), 'GD Version: ' . $version['GD Version']); 76 } else { 77 $version = phpversion($prog); 78 $this->doPrivmsg($this->event->getSource(), ucfirst($prog) . ' Version: ' . ($version ? $version : 'N/A')); 79 } 87 $version = phpversion($prog); 88 $message = ucfirst($prog) . ' Version: ' . ($version ? $version : 'N/A'); 80 89 } else { 81 $ this->doPrivmsg($this->event->getSource(), 'Unknown Extension: ' . ucfirst($prog));90 $message = 'Unknown Extension: ' . ucfirst($prog); 82 91 } 83 unset($extensions); 92 $this->doPrivmsg($this->event->getSource(), $target . ': ' . $message); 93 unset($prog, $extensions, $version, $message); 84 94 } 85 95 } trunk/Phergie/Plugin/Dns.php
r61 r194 4 4 * @see Phergie_Plugin_Abstract_Command 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/Command.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Command.php'; 7 7 8 8 /** … … 21 21 protected function processRequest($arg) 22 22 { 23 $target = $this->event->getNick(); 23 24 if (preg_match('/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/', $arg)) { 24 25 $resolved = gethostbyaddr(long2ip(ip2long($arg))); … … 29 30 $source = $this->event->getSource(); 30 31 if (!isset ($resolved)) { 31 $this->doPrivmsg($source, $ arg . ' cannot be resolved.');32 $this->doPrivmsg($source, $target . ': ' . $arg . ' cannot be resolved.'); 32 33 } else { 33 $this->doPrivmsg($source, $ arg . ' resolved to ' . $resolved);34 $this->doPrivmsg($source, $target . ': ' . $arg . ' resolved to ' . $resolved); 34 35 } 35 36 } trunk/Phergie/Plugin/Drink.php
r179 r194 4 4 * @see Phergie_Plugin_Abstract_Command 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/Command.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Command.php'; 7 7 8 8 /** … … 92 92 // Initialize the database connection 93 93 $this->db = new PDO('sqlite:' . $this->dir . 'drink.db'); 94 if (!$this->db) { 95 return; 96 } 94 97 95 98 // Populate the database if necessary … … 252 255 continue; 253 256 } 254 $this->debug('Inserted ' . $name);257 $this->debug('Inserted ' . ucfirst($table) . ': ' . $name); 255 258 $stmt->execute(array('name' => $name)); 256 259 } trunk/Phergie/Plugin/Eval.php
r172 r194 2 2 3 3 /** 4 * @see Phergie_Plugin_A dminCommand4 * @see Phergie_Plugin_Abstract_Command 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/AdminCommand.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Command.php'; 7 7 8 8 /** 9 9 * Handles requests from administrators to evaluate a string 10 10 */ 11 class Phergie_Plugin_Eval extends Phergie_Plugin_Abstract_ AdminCommand11 class Phergie_Plugin_Eval extends Phergie_Plugin_Abstract_Command 12 12 { 13 /** 14 * Flag indicating whether or not the plugin is an admin plugin or not 15 * 16 * @var bool 17 */ 18 public $needsAdmin = true; 19 20 /** 21 * Evaluates the given string and outputs the evaluated statement while any 22 * any dumped data gets dumped to the console. 23 * 24 * @return void 25 */ 13 26 public function onDoEval($code) { 27 $user = $this->event->getNick(); 28 14 29 // Check to see if the admin is a hostmask admin only and not an op 15 30 if ($this->fromAdmin(false)) { … … 45 60 } 46 61 } 62 } else { 63 $this->doPrivmsg($this->event->getSource(), $user . ': You do not have permission to use eval.'); 47 64 } 48 65 } 49 66 67 /** 68 * Executes the given string and outputs the last line that exec returns 69 * while the full exec request gets dumped to the console if the-c flag 70 * is specified. 71 * 72 * @return void 73 */ 50 74 public function onDoExec($code) { 75 $user = $this->event->getNick(); 76 51 77 // Check to see if the admin is a hostmask admin only and not an op 52 78 if ($this->fromAdmin(false)) { … … 69 95 } 70 96 } 97 } else { 98 $this->doPrivmsg($this->event->getSource(), $user . ': You do not have permission to use exec.'); 71 99 } 72 100 } trunk/Phergie/Plugin/FeedTicker.php
r182 r194 4 4 * @see Phergie_Plugin_Abstract_Cron 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/Cron.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Cron.php'; 7 7 8 8 /** … … 11 11 class Phergie_Plugin_FeedTicker extends Phergie_Plugin_Abstract_Cron 12 12 { 13 /** 14 * Determines if the plugin is a passive plugin or not 15 * 16 * @var bool 17 */ 18 public $passive = true; 19 13 20 /** 14 21 * Delay in seconds for syndicating feeds, set to 30 minutes … … 119 126 $this->format = $this->getPluginIni('format'); 120 127 } 128 } 129 130 /** 131 * Returns whether or not the plugin's dependencies are met. 132 * 133 * @param Phergie_Driver_Abstract $client Client instance 134 * @param array $plugins List of short names for plugins that the 135 * bootstrap file intends to instantiate 136 * @see Phergie_Plugin_Abstract_Base::checkDependencies() 137 * @return bool TRUE if dependencies are met, FALSE otherwise 138 */ 139 public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 140 { 141 if (!extension_loaded('SimpleXML')) { 142 return false; 143 } 144 145 return true; 121 146 } 122 147 … … 273 298 */ 274 299 protected function decode($str, $trim = null) { 275 $out = $this->decodeTranslit($str);300 $out = $this->decodeTranslit($str); 276 301 if($trim > 0) { 277 302 $out = substr($out, 0, $trim) . (strlen($out) > $trim ? '...' : ''); trunk/Phergie/Plugin/JoinPart.php
r59 r194 2 2 3 3 /** 4 * @see Phergie_Plugin_Abstract_ AdminCommand4 * @see Phergie_Plugin_Abstract_Command 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/AdminCommand.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Command.php'; 7 7 8 8 /** … … 10 10 * specified channel. 11 11 */ 12 class Phergie_Plugin_JoinPart extends Phergie_Plugin_Abstract_ AdminCommand12 class Phergie_Plugin_JoinPart extends Phergie_Plugin_Abstract_Command 13 13 { 14 /** 15 * Flag indicating whether or not the plugin is an admin plugin or not 16 * 17 * @var bool 18 */ 19 public $needsAdmin = true; 20 21 /** 22 * A bool value set to whether the Users plugin is running or not 23 * 24 * @var bool 25 */ 26 protected $usersEnabled = null; 27 14 28 /** 15 29 * Joins the specified channel. … … 19 33 public function onDoJoin($channel) 20 34 { 21 $this->doJoin($channel); 35 if (!empty($channel)) { 36 $this->doJoin(trim($channel)); 37 } 22 38 } 23 39 … … 31 47 public function onDoPart($channel = null) 32 48 { 33 if (empty($channel)) { 34 $this->doPart($this->event->getArgument(0)); 35 } else { 36 $this->doPart($channel); 49 $source = $this->event->getArgument(0); 50 $channel = trim($channel); 51 52 // If the channel is empty, part the current channel where the command was used 53 if (empty($channel) && $source[0] == '#') { 54 $this->doPart($source); 55 // Check whether a channel or multiple channels were given as well as a reason 56 } else if (preg_match('/^([#&][^\s,]+ (?:\s*,+\s* [#&][^\s,]+)* | all | \#)?(?:[\s,]+)?(.*)?$/xis', $channel, $match)) { 57 $channels = preg_replace(array('{\s}', '{,+}'), array('', ','), strtolower($match[1])); 58 if (!empty($channels) || $source[0] == '#') { 59 if (empty($channels) || $channels == '#') { 60 if ($source[0] != '#') return; 61 $channels = $source; 62 } else if ($channels == 'all') { 63 //Check to see if the Users plugin is enabled to retrieve a list of channels 64 if (!isset($this->usersEnabled)) { 65 $this->usersEnabled = $this->pluginLoaded('Users'); 66 } 67 if (!$this->usersEnabled) { 68 // A fallback, most IRC servers cause the user to part all channels if they try to join 0 69 $this->doJoin('0'); 70 } else { 71 $channels = implode(',', Phergie_Plugin_Users::getChannels()); 72 } 73 } 74 75 $reason = trim($match[2]); 76 if(substr($reason, 0, 1) === '(' && substr($reason, -1) === ')') { 77 $reason = trim(substr($reason, 1, -1)); 78 } 79 80 $this->doPart($channels, $reason); 81 } 37 82 } 83 unset($channel, $channels, $reason); 38 84 } 39 85 } trunk/Phergie/Plugin/Karma.php
r179 r194 4 4 * @see Phergie_Plugin_Abstract_Base 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/Base.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Base.php'; 7 7 8 8 /** … … 48 48 */ 49 49 protected $fixedKarma; 50 51 /** 52 * A list of blacklisted values 53 * 54 * @var array 55 */ 56 protected $karmaBlacklist; 50 57 51 58 /** … … 80 87 $this->db = null; 81 88 $this->lastGc = null; 82 $this->log = null;89 $this->log = array(); 83 90 84 91 $this->fixedKarma = array … … 98 105 'mc²' => '%s has karma of e', 99 106 'i' => 'I haz big karma', 100