Changeset 179
- Timestamp:
- 03/21/08 22:40:41 (8 months ago)
- Files:
-
- trunk/Phergie/Plugin/Abstract/Base.php (modified) (1 diff)
- trunk/Phergie/Plugin/Abstract/Command.php (modified) (3 diffs)
- trunk/Phergie/Plugin/ChuckNorris.php (modified) (1 diff)
- trunk/Phergie/Plugin/Convert.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Drink.php (modified) (6 diffs)
- trunk/Phergie/Plugin/Karma.php (modified) (7 diffs)
- trunk/Phergie/Plugin/Toggle.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Plugin/Abstract/Base.php
r173 r179 397 397 } 398 398 399 if ($time > 0 ) {399 if ($time > 0 || count($return) <= 0) { 400 400 $return[] = $time . 's'; 401 401 } trunk/Phergie/Plugin/Abstract/Command.php
r151 r179 38 38 * @return void 39 39 */ 40 protected final function processCommand($message, $ignorePrefix = false, $ adminCommand= false)40 protected final function processCommand($message, $ignorePrefix = false, $forceBotPrefix = false) 41 41 { 42 42 if (!$this->methods) { … … 56 56 // Checks to see if the command was prefixed with the bot's name 57 57 $target = $this->event->getArgument(0); 58 $exp = ($target[0] == '#' && $adminCommand) ? 59 '(?:' . $this->getIni('nick') . '\s*:?\s+)' : 60 '(?:' . $this->getIni('nick') . '\s*:?\s+)?'; 58 $bot = $this->getIni('nick'); 59 $exp = '(?:'.preg_quote($bot).'\s*:?\s+)' . (!($target[0] == '#' && $forceBotPrefix) ? '?': ''); 61 60 62 61 if (preg_match('/^'.$exp.'(\S+)(?:[\s'.chr(240).']+(.*))?$/', $message, $match)) { … … 66 65 // Checks the command for a prefix if one is specified in the config 67 66 $commandPrefix = trim($this->getIni('command_prefix')); 68 $hasPrefix = ($commandPrefix && substr($command, 0, strlen($commandPrefix)) == $commandPrefix); 69 if ($hasPrefix) { 70 $command = substr($command, strlen($commandPrefix)); 67 if ($commandPrefix) { 68 if ($hasPrefix = (substr($command, 0, strlen($commandPrefix)) == $commandPrefix)) { 69 $command = substr($command, strlen($commandPrefix)); 70 } 71 if (strtolower(substr($message, 0, strlen($bot))) == strtolower($bot)) { 72 $ignorePrefix = true; 73 } 71 74 } 72 75 trunk/Phergie/Plugin/ChuckNorris.php
r157 r179 173 173 // Checks to see if the chuckfacts table exists 174 174 $table = $this->db 175 ->query( "SELECT COUNT(*) FROM sqlite_master WHERE name = 'chuckfacts'")175 ->query('SELECT COUNT(*) FROM sqlite_master WHERE name = ' . $this->db->quote('chuckfacts')) 176 176 ->fetchColumn(); 177 177 178 178 // If the table doesn't exist, create them and return true for the next step 179 179 if (!$table) { 180 $this->debug('Creating tables.');180 $this->debug('Creating the database schema'); 181 181 $this->db->exec('CREATE TABLE chuckfacts (facts VARCHAR(255))'); 182 182 $this->db->exec('CREATE UNIQUE INDEX chuckfacts_name ON chuckfacts (facts)'); trunk/Phergie/Plugin/Convert.php
r108 r179 7 7 8 8 /** 9 * Performs and responds with messages containing the results of conversions 9 * Performs and responds with messages containing the results of conversions 10 10 * between different units. 11 11 */ … … 25 25 ))); 26 26 27 $url = 'http://www.google.com/search?q=' . urlencode($convert) . '& ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a';27 $url = 'http://www.google.com/search?q=' . urlencode($convert) . '&btnG=Google+Search&aq=f'; 28 28 $contents = @file_get_contents($url, null, $context); 29 29 if (empty($contents)) { trunk/Phergie/Plugin/Drink.php
r121 r179 95 95 // Populate the database if necessary 96 96 if ($this->needTable('beer')) { 97 $this->debug('Retrieving data for: Beer'); 97 98 $contents = @file_get_contents('http://beerme.com/beerlist.php'); 98 99 if ($contents !== false) { 100 $this->debug('Parsing data for: Beer'); 99 101 preg_match_all('/brewery\.php\?[0-9]+#[0-9]+\'>([^<]+)/', $contents, $matches); 100 102 $names = array(); … … 119 121 $limit = 2; 120 122 $names = array(); 123 $this->debug('Retrieving data for: Cocktail'); 121 124 for ($i = 1; $i <= $limit; $i += 150) { 122 125 $contents = @file_get_contents('http://www.webtender.com/db/browse?level=2&dir=drinks&char=%2A&start=' . $i); … … 124 127 break; 125 128 } 129 $this->debug('Parsing data for: Cocktail (' . $i . ' - ' . ($i + 150) . ')'); 126 130 if ($i == 1) { 127 131 preg_match('/>([0-9]+) found\\.</', $contents, $match); … … 144 148 145 149 if ($this->needTable('coke')) { 150 $this->debug('Retrieving data for: Coke'); 146 151 $contents = @file_get_contents('http://www.energyfiend.com/huge-caffeine-database/'); 147 152 if ($contents) { 153 $this->debug('Parsing data for: Coke'); 148 154 // List of drinks to filter out 149 155 $filter = array( … … 169 175 170 176 if ($this->needTable('tea')) { 177 $this->debug('Retrieving data for: Tea'); 171 178 $names = @file('http://www.midnight-labs.org/tea.txt'); 172 179 if ($names) { 180 $this->debug('Parsing data for: Tea'); 173 181 foreach ($names as $key => $value) { 174 182 $names[$key] = ucwords(rtrim($value)); … … 233 241 private function populateTable($table, $names) 234 242 { 243 $this->debug('Creating the database schema for: ' . ucfirst($table)); 235 244 $this->db->exec('CREATE TABLE ' . $table . ' (name VARCHAR(255))'); 236 245 $this->db->exec('CREATE UNIQUE INDEX ' . $table . '_name ON ' . $table . ' (name)'); trunk/Phergie/Plugin/Karma.php
r161 r179 132 132 if (!file_exists($db)) { 133 133 $this->db = new PDO('sqlite:' . $db); 134 135 $this->debug('Creating the database schema'); 134 136 $this->db->query(' 135 137 CREATE TABLE karmas ( word VARCHAR ( 255 ) , karma MEDIUMINT ) ; … … 169 171 170 172 $this->fetchKarma = $this->db->prepare(' 171 SELECT karma, ROWID id FROM karmas WHERE word = :wordLIMIT 1173 SELECT karma, ROWID id FROM karmas WHERE LOWER(word) = LOWER(:word) LIMIT 1 172 174 '); 173 175 174 176 $this->updateKarma = $this->db->prepare(' 175 UPDATE karmas SET karma = :karma WHERE word = :word177 UPDATE karmas SET karma = :karma WHERE LOWER(word) = LOWER(:word) 176 178 '); 177 179 } … … 211 213 212 214 // Command prefix check 213 $commandPrefix = preg_quote(trim($this->getIni('command_prefix'))); 214 $prefix = ($commandPrefix ? $commandPrefix . '|' : '').'(?:' . $this->getIni('nick') . '\s*:?\s+)?'; 215 $prefix = preg_quote(trim($this->getIni('command_prefix'))); 216 $bot = preg_quote($this->getIni('nick')); 217 $exp = '(?:(?:'.$bot.'\s*:?\s+(?:'.$prefix.')?)|(?:'.$prefix.'))'; 215 218 216 219 // Karma status request 217 if (preg_match('#^ (?:'.$prefix.')karma\s+(.+)$#i', $message, $m)) {220 if (preg_match('#^'.$exp.'karma\s+(.+)$#i', $message, $m)) { 218 221 // Return user's value if "me" is requested 219 222 if (strtolower($m[1]) === 'me') { … … 246 249 } 247 250 // Incrementation/decrementation request 248 } elseif (preg_match('{^ (?:'.$prefix.')?(\S+?|\(.+?\)+)(\+{2,}|-{2,})(?:\s+(.*))?$}i', $message, $m)) {251 } elseif (preg_match('{^'.$exp.'?(\S+?|\(.+?\)+)(\+{2,}|-{2,})(?:\s+(.*))?$}i', $message, $m)) { 249 252 $word = strtolower($m[1]); 250 253 // Strip parenthesis grouping multiple words … … 287 290 ':word' => $word 288 291 ); 292 $this->debug('Updated karma: '. $word . ' = ' . ($res['karma'] + ($m[2]=='++' ? 1 : -1))); 289 293 $this->updateKarma->execute($args); 290 294 } else { … … 293 297 ':karma' => ($m[2]=='++' ? '1' : '-1') 294 298 ); 299 $this->debug('Inserted karma: '. $word . ' = ' . ($m[2]=='++' ? '1' : '-1')); 295 300 $this->insertKarma->execute($args); 296 301 $this->fetchKarma->execute(array(':word'=>$word)); … … 302 307 $comment = preg_replace('{(?:^//(.*)|^#(.*)|^/\*(.*?)\*/$)}', '$1$2$3', $m[3]); 303 308 if (!empty($comment)) { 309 $this->debug('Inserted comment: '. $comment); 304 310 $this->insertComment->execute(array(':wordid' => $id, ':comment' => $comment)); 305 311 } trunk/Phergie/Plugin/Toggle.php
r153 r179 60 60 } 61 61 62 62 63 // Plugin file was found, check if it can be loaded 63 64 if (isset($target)) { … … 81 82 public function onDoMute($plugin, $target='') 82 83 { 83 $target = trim((!empty($target) && $this->fromAdmin(false)) ? $target : $this->event->getSource());84 $target = strtolower(trim((!empty($target) && $this->fromAdmin(false)) ? $target : $this->event->getSource())); 84 85 if (!empty($target)) { 85 86 if ($instance = $this->getPlugin($plugin)) { 86 87 $instance->muted[$target] = true; 87 $this->doPrivmsg($this->event->getSource(), 'Muted '.$plugin.' for '.$target.'.'); 88 $target = ($target==strtolower($this->event->getSource())?'for this channel':($target=='global'?'globally':'for '.$target)); 89 $this->doPrivmsg($this->event->getSource(), 'Muted '.$plugin.' '.$target.'.'); 88 90 } else { 89 91 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not mute.'); … … 98 100 if ($instance = $this->getPlugin($plugin)) { 99 101 $instance->muted[$target] = false; 100 $this->doPrivmsg($this->event->getSource(), 'Unmuted '.$plugin.' for '.$target.'.'); 102 $target = ($target==strtolower($this->event->getSource())?'for this channel':($target=='global'?'globally':'for '.$target)); 103 $this->doPrivmsg($this->event->getSource(), 'Unmuted '.$plugin.' '.$target.'.'); 101 104 } else { 102 105 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not unmute.');