Changeset 135
- Timestamp:
- 03/07/08 03:14:47 (9 months ago)
- Files:
-
- trunk/Phergie/Plugin/Abstract/AdminCommand.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Abstract/Command.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Karma.php (modified) (9 diffs)
- trunk/Phergie/phergie.ini (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Plugin/Abstract/AdminCommand.php
r106 r135 83 83 } 84 84 if (!empty ($ini)) { 85 $this->admins[$class] = $this->hostmasksToRegex($ini); 85 $this->admins[$class] = $this->hostmasksToRegex($ini); 86 86 } 87 87 } … … 144 144 '/^(?:' . $this->getIni('nick') . '\s*:?\s+)?(.*)$/'; 145 145 if (preg_match($exp, $this->event->getArgument(1), $m)) { 146 $this->processCommand($m[1] );146 $this->processCommand($m[1], true); 147 147 } 148 148 } trunk/Phergie/Plugin/Abstract/Command.php
r112 r135 38 38 * @return void 39 39 */ 40 protected final function processCommand($message )40 protected final function processCommand($message, $ignorePrefix = false) 41 41 { 42 42 if (!$this->methods) { … … 58 58 $params = isset ($match[2]) ? $match[2] : array(); 59 59 60 if (isset ($this->methods[$command])) { 60 // Checks the command for a prefix if one is specified in the config 61 $commandPrefix = trim($this->getIni('command_prefix')); 62 $hasPrefix = ($commandPrefix && substr($command, 0, strlen($commandPrefix)) == $commandPrefix); 63 if ($hasPrefix) { 64 $command = substr($command, strlen($commandPrefix)); 65 } 66 67 if ((!$commandPrefix || $hasPrefix || $ignorePrefix) && isset($this->methods[$command])) { 61 68 $method = 'onDo' . ucfirst($command); 62 69 if (empty ($params)) { trunk/Phergie/Plugin/Karma.php
r116 r135 209 209 $message = $this->event->getArgument(1); 210 210 211 // Command prefix check 212 $commandPrefix = trim($this->getIni('command_prefix')); 213 $prefix = preg_quote($commandPrefix ? $commandPrefix : ''); 214 211 215 // Karma status request 212 if (preg_match('#^ karma\s+(.+)$#i', $message, $m)) {216 if (preg_match('#^'.$prefix.'karma\s+(.+)$#i', $message, $m)) { 213 217 // Return user's value if "me" is requested 214 218 if (strtolower($m[1]) === 'me') { … … 216 220 } 217 221 // Clean the term 218 $term = $this->doCleanWord($m[1]); 222 $term = $this->doCleanWord($m[1]); 219 223 // Return fixed value if set 220 224 if (isset ($this->fixedKarma[$term])) { … … 222 226 return; 223 227 } 224 228 225 229 // Return current karma or neutral if not set yet 226 230 $this->fetchKarma->execute(array(':word'=>$term)); 227 231 $res = $this->fetchKarma->fetch(PDO::FETCH_ASSOC); 228 232 229 233 // Clean the raw term if it was contained within brackets 230 234 if(substr($m[1], 0, 1) === '(' && substr($m[1], -1) === ')') 231 $m[1] = substr($m[1], 1, -1); 232 235 $m[1] = substr($m[1], 1, -1); 236 233 237 if ($res && $res['karma'] != 0) { 234 238 $this->doPrivmsg($source, $m[1].' has karma of '.$res['karma'].'.'); … … 237 241 } 238 242 // Incrementation/decrementation request 239 } elseif (preg_match('#^( \S+?|\(.+?\)+)(\+{2,}|-{2,})(?:\s+(.*))?$#i', $message, $m)) {240 $word = strtolower($m[ 1]);243 } elseif (preg_match('#^('.$prefix.')?(\S+?|\(.+?\)+)(\+{2,}|-{2,})(?:\s+(.*))?$#i', $message, $m)) { 244 $word = strtolower($m[2]); 241 245 // Strip parenthesis grouping multiple words 242 246 if(substr($word, 0, 1) === '(' && substr($word, -1) === ')') { 243 247 $word = substr($word, 1, -1); 244 248 } else { // Add trailing + or -'s 245 if(strlen($m[ 2]) > 2) {246 $word .= substr($m[ 2], 2);247 $m[ 2] = substr($m[2], -2);249 if(strlen($m[3]) > 2) { 250 $word .= substr($m[3], 2); 251 $m[3] = substr($m[3], -2); 248 252 } 249 253 } … … 256 260 // Force a decrementation if someone tries to update his own karma 257 261 if ($word == strtolower($this->event->getNick())) { 258 $m[ 2] = '--';262 $m[3] = '--'; 259 263 } 260 264 // Antithrottling check … … 275 279 if ($res) { 276 280 $args = array( 277 ':karma' => ($res['karma'] + ($m[ 2]=='++' ? 1 : -1)),281 ':karma' => ($res['karma'] + ($m[3]=='++' ? 1 : -1)), 278 282 ':word' => $word 279 283 ); … … 282 286 $args = array( 283 287 ':word' => $word, 284 ':karma' => ($m[ 2]=='++' ? '1' : '-1')288 ':karma' => ($m[3]=='++' ? '1' : '-1') 285 289 ); 286 290 $this->insertKarma->execute($args); … … 291 295 292 296 // Add comment 293 $comment = preg_replace('{(?:^//(.*)|^#(.*)|^/\*(.*?)\*/$)}', '$1$2$3', $m[ 3]);297 $comment = preg_replace('{(?:^//(.*)|^#(.*)|^/\*(.*?)\*/$)}', '$1$2$3', $m[4]); 294 298 if (!empty($comment)) { 295 299 $this->insertComment->execute(array(':wordid' => $id, ':comment' => $comment)); … … 356 360 protected function doCleanWord($word) { 357 361 if(substr($word, 0, 1) === '(' && substr($word, -1) === ')') 358 $word = substr($word, 1, -1); 362 $word = substr($word, 1, -1); 359 363 $word = preg_replace('#\s+#', ' ', strtolower(trim($word))); 360 364 return $word; trunk/Phergie/phergie.ini
r130 r135 2 2 ; Core settings 3 3 ;------------------------ 4 5 ; command_prefix : 6 ; The prefix used for the onDo commands in plugins 7 command_prefix = "" 4 8 5 9 ; server : … … 187 191 ; feedticker.filter_article0 : 188 192 ; a double quote-enclosed regex string filter; this setting allows you to 189 ; filter each article title independently and may be repeated with a 193 ; filter each article title independently and may be repeated with a 190 194 ; different number. (i.e. filter_article1, filter_article2, etc.) 191 195 feedticker.filter_article0 = ""