Assembla home | Assembla project page
 

Changeset 141

Show
Ignore:
Timestamp:
03/09/08 02:45:08 (9 months ago)
Author:
Slynderdale
Message:

Added support for calling bots directly by prefixing the command with the bot's name like Phergie: beer me. Prefixing the bots name is optional but is still required by AdminCommand?.

Files:

Legend:

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

    r135 r141  
    138138    public function onPrivmsg() 
    139139    { 
    140         if ($this->fromAdmin()) { 
    141             $target = $this->event->getArgument(0); 
    142             $exp = $target[0] == '#' ? 
    143                 '/^' . $this->getIni('nick') . '\s*:?\s+(.*)$/' : 
    144                 '/^(?:' . $this->getIni('nick') . '\s*:?\s+)?(.*)$/'; 
    145             if (preg_match($exp, $this->event->getArgument(1), $m)) { 
    146                 $this->processCommand($m[1], true); 
    147             } 
     140        if ($this->fromAdmin()) { 
     141            $this->processCommand($this->event->getArgument(1), true, true); 
    148142        } 
    149143    } 
  • trunk/Phergie/Plugin/Abstract/Command.php

    r137 r141  
    3838    * @return void 
    3939    */ 
    40     protected final function processCommand($message, $ignorePrefix = false
     40    protected final function processCommand($message, $ignorePrefix = false, $adminCommand = false
    4141    { 
    4242        if (!$this->methods) { 
     
    5454        } 
    5555 
    56         if (preg_match('/^(\S+)(?:[\s\0xa0]+(.*))?$/', $message, $match)) { 
     56        // Checks to see if the command was prefixed with the bot's name 
     57        $target = $this->event->getArgument(0); 
     58        $exp = ($target[0] == '#' && $adminCommand) ? 
     59                '(?:' . $this->getIni('nick') . '\s*:?\s+)' : 
     60                '(?:' . $this->getIni('nick') . '\s*:?\s+)?'; 
     61 
     62        if (preg_match('/^'.$exp.'(\S+)(?:[\s\0xa0]+(.*))?$/', $message, $match)) { 
    5763            $command = strtolower($match[1]); 
    5864            $params = isset ($match[2]) ? $match[2] : array(); 
  • trunk/Phergie/Plugin/Karma.php

    r136 r141  
    210210 
    211211        // Command prefix check 
    212         $commandPrefix = trim($this->getIni('command_prefix')); 
    213         $prefix = preg_quote($commandPrefix ? $commandPrefix : '')
     212        $commandPrefix = preg_quote(trim($this->getIni('command_prefix'))); 
     213        $prefix = ($commandPrefix ? $commandPrefix . '|' : '').'(?:' . $this->getIni('nick') . '\s*:?\s+)?'
    214214 
    215215        // Karma status request 
    216         if (preg_match('#^'.$prefix.'karma\s+(.+)$#i', $message, $m)) { 
     216        if (preg_match('#^(?:'.$prefix.')karma\s+(.+)$#i', $message, $m)) { 
    217217            // Return user's value if "me" is requested 
    218218            if (strtolower($m[1]) === 'me') {