Changeset 136

Show
Ignore:
Timestamp:
03/07/08 03:43:21 (5 years ago)
Author:
Slynderdale
Message:
 
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Phergie/Plugin/Karma.php

    r135 r136  
    231231            $res = $this->fetchKarma->fetch(PDO::FETCH_ASSOC); 
    232232 
     233            // Sanity check if someone if someone prefixed their conversation with karma 
     234            if (!$res && substr_count($term, ' ') > 1 && !(substr($m[1], 0, 1) === '(' && substr($m[1], -1) === ')')) 
     235                return; 
     236 
    233237            // Clean the raw term if it was contained within brackets 
    234238            if(substr($m[1], 0, 1) === '(' && substr($m[1], -1) === ')') 
     
    241245            } 
    242246        // Incrementation/decrementation request 
    243         } elseif (preg_match('#^('.$prefix.')?(\S+?|\(.+?\)+)(\+{2,}|-{2,})(?:\s+(.*))?$#i', $message, $m)) { 
    244             $word = strtolower($m[2]); 
     247        } elseif (preg_match('{^(?:'.$prefix.')?(\S+?|\(.+?\)+)(\+{2,}|-{2,})(?:\s+(.*))?$}i', $message, $m)) { 
     248            $word = strtolower($m[1]); 
    245249            // Strip parenthesis grouping multiple words 
    246250            if(substr($word, 0, 1) === '(' && substr($word, -1) === ')') { 
    247251                $word = substr($word, 1, -1); 
    248252            } else { // Add trailing + or -'s 
    249                 if(strlen($m[3]) > 2) { 
    250                     $word .= substr($m[3], 2); 
    251                     $m[3] = substr($m[3], -2); 
     253                if(strlen($m[2]) > 2) { 
     254                    $word .= substr($m[2], 2); 
     255                    $m[2] = substr($m[2], -2); 
    252256                } 
    253257            } 
     
    260264            // Force a decrementation if someone tries to update his own karma 
    261265            if ($word == strtolower($this->event->getNick())) { 
    262                 $m[3] = '--'; 
     266                $m[2] = '--'; 
    263267            } 
    264268            // Antithrottling check 
     
    279283            if ($res) { 
    280284                $args = array( 
    281                     ':karma' => ($res['karma'] + ($m[3]=='++' ? 1 : -1)), 
     285                    ':karma' => ($res['karma'] + ($m[2]=='++' ? 1 : -1)), 
    282286                    ':word' => $word 
    283287                ); 
     
    286290                $args = array( 
    287291                    ':word' => $word, 
    288                     ':karma' => ($m[3]=='++' ? '1' : '-1') 
     292                    ':karma' => ($m[2]=='++' ? '1' : '-1') 
    289293                ); 
    290294                $this->insertKarma->execute($args); 
     
    295299 
    296300            // Add comment 
    297             $comment = preg_replace('{(?:^//(.*)|^#(.*)|^/\*(.*?)\*/$)}', '$1$2$3', $m[4]); 
     301            $comment = preg_replace('{(?:^//(.*)|^#(.*)|^/\*(.*?)\*/$)}', '$1$2$3', $m[3]); 
    298302            if (!empty($comment)) { 
    299303                $this->insertComment->execute(array(':wordid' => $id, ':comment' => $comment));