Assembla home | Assembla project page
 

Changeset 135

Show
Ignore:
Timestamp:
03/07/08 03:14:47 (9 months ago)
Author:
Slynderdale
Message:

Added support for custom command prefixes as defined in the config file.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Phergie/Plugin/Abstract/AdminCommand.php

    r106 r135  
    8383        } 
    8484        if (!empty ($ini)) { 
    85             $this->admins[$class] = $this->hostmasksToRegex($ini);  
     85            $this->admins[$class] = $this->hostmasksToRegex($ini); 
    8686        } 
    8787    } 
     
    144144                '/^(?:' . $this->getIni('nick') . '\s*:?\s+)?(.*)$/'; 
    145145            if (preg_match($exp, $this->event->getArgument(1), $m)) { 
    146                 $this->processCommand($m[1]); 
     146                $this->processCommand($m[1], true); 
    147147            } 
    148148        } 
  • trunk/Phergie/Plugin/Abstract/Command.php

    r112 r135  
    3838    * @return void 
    3939    */ 
    40     protected final function processCommand($message
     40    protected final function processCommand($message, $ignorePrefix = false
    4141    { 
    4242        if (!$this->methods) { 
     
    5858            $params = isset ($match[2]) ? $match[2] : array(); 
    5959 
    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])) { 
    6168                $method = 'onDo' . ucfirst($command); 
    6269                if (empty ($params)) { 
  • trunk/Phergie/Plugin/Karma.php

    r116 r135  
    209209        $message = $this->event->getArgument(1); 
    210210 
     211        // Command prefix check 
     212        $commandPrefix = trim($this->getIni('command_prefix')); 
     213        $prefix = preg_quote($commandPrefix ? $commandPrefix : ''); 
     214 
    211215        // Karma status request 
    212         if (preg_match('#^karma\s+(.+)$#i', $message, $m)) { 
     216        if (preg_match('#^'.$prefix.'karma\s+(.+)$#i', $message, $m)) { 
    213217            // Return user's value if "me" is requested 
    214218            if (strtolower($m[1]) === 'me') { 
     
    216220            } 
    217221                  // Clean the term 
    218             $term = $this->doCleanWord($m[1]);                
     222            $term = $this->doCleanWord($m[1]); 
    219223            // Return fixed value if set 
    220224            if (isset ($this->fixedKarma[$term])) { 
     
    222226                return; 
    223227            } 
    224              
     228 
    225229            // Return current karma or neutral if not set yet 
    226230            $this->fetchKarma->execute(array(':word'=>$term)); 
    227231            $res = $this->fetchKarma->fetch(PDO::FETCH_ASSOC); 
    228              
     232 
    229233            // Clean the raw term if it was contained within brackets 
    230234            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 
    233237            if ($res && $res['karma'] != 0) { 
    234238                $this->doPrivmsg($source, $m[1].' has karma of '.$res['karma'].'.'); 
     
    237241            } 
    238242        // 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]); 
    241245            // Strip parenthesis grouping multiple words 
    242246            if(substr($word, 0, 1) === '(' && substr($word, -1) === ')') { 
    243247                $word = substr($word, 1, -1); 
    244248            } 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); 
    248252                } 
    249253            } 
     
    256260            // Force a decrementation if someone tries to update his own karma 
    257261            if ($word == strtolower($this->event->getNick())) { 
    258                 $m[2] = '--'; 
     262                $m[3] = '--'; 
    259263            } 
    260264            // Antithrottling check 
     
    275279            if ($res) { 
    276280                $args = array( 
    277                     ':karma' => ($res['karma'] + ($m[2]=='++' ? 1 : -1)), 
     281                    ':karma' => ($res['karma'] + ($m[3]=='++' ? 1 : -1)), 
    278282                    ':word' => $word 
    279283                ); 
     
    282286                $args = array( 
    283287                    ':word' => $word, 
    284                     ':karma' => ($m[2]=='++' ? '1' : '-1') 
     288                    ':karma' => ($m[3]=='++' ? '1' : '-1') 
    285289                ); 
    286290                $this->insertKarma->execute($args); 
     
    291295 
    292296            // Add comment 
    293             $comment = preg_replace('{(?:^//(.*)|^#(.*)|^/\*(.*?)\*/$)}', '$1$2$3', $m[3]); 
     297            $comment = preg_replace('{(?:^//(.*)|^#(.*)|^/\*(.*?)\*/$)}', '$1$2$3', $m[4]); 
    294298            if (!empty($comment)) { 
    295299                $this->insertComment->execute(array(':wordid' => $id, ':comment' => $comment)); 
     
    356360  protected function doCleanWord($word) { 
    357361    if(substr($word, 0, 1) === '(' && substr($word, -1) === ')') 
    358        $word = substr($word, 1, -1);                     
     362       $word = substr($word, 1, -1); 
    359363    $word = preg_replace('#\s+#', ' ', strtolower(trim($word))); 
    360364    return $word; 
  • trunk/Phergie/phergie.ini

    r130 r135  
    22; Core settings 
    33;------------------------ 
     4 
     5; command_prefix : 
     6;    The prefix used for the onDo commands in plugins 
     7command_prefix = "" 
    48 
    59; server : 
     
    187191; feedticker.filter_article0 : 
    188192;    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 
    190194;    different number. (i.e. filter_article1, filter_article2, etc.) 
    191195feedticker.filter_article0 = ""