Assembla home | Assembla project page
 
Show
Ignore:
Timestamp:
04/13/08 23:08:08 (7 months ago)
Author:
Slynderdale
Message:

Made it optional to have a bot prefix for admin commands if a command prefix is set.

Files:

Legend:

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

    r223 r231  
    5151        } 
    5252 
     53        // Get the command prefix 
     54        $commandPrefix = trim($this->getIni('command_prefix')); 
     55 
    5356        // Checks to see if the plugin is an admin plugin 
    54         if ($this->needsAdmin) { 
    55             $ignorePrefix = $forceBotPrefix = true; 
     57        if ($this->needsAdmin && empty($commandPrefix)) { 
     58            $forceBotPrefix = true; 
    5659        } 
    5760 
     
    6164        $bot = $this->getIni('nick'); 
    6265        // The Botprefix regex expression 
    63         $exp = '(?:' . preg_quote($bot) . '\s*[:,>]?\s+)' . (!($source[0] == '#' && $forceBotPrefix) ? '?' : ''); 
     66        $exp = '(' . preg_quote($bot) . '\s*[:,>]?\s+)' . (!($source[0] == '#' && $forceBotPrefix) ? '?' : ''); 
    6467 
    6568        if (preg_match('/^' . $exp . '(\S+)(?:[\s' . chr(240) . ']+(.*))?$/', $message, $match)) { 
    66             $command = strtolower($match[1]); 
    67             $params = isset($match[2]) ? $match[2] : array(); 
     69            $botPrefix = $match[1]; 
     70            $command = strtolower($match[2]); 
     71            $params = isset($match[3]) ? $match[3] : array(); 
    6872 
    6973            // Checks the command for a prefix if one is specified in the config 
    70             $commandPrefix = trim($this->getIni('command_prefix')); 
    71             if ($commandPrefix) { 
     74            if (!empty($commandPrefix)) { 
    7275                if ($hasPrefix = (substr($command, 0, strlen($commandPrefix)) == $commandPrefix)) { 
    7376                    $command = substr($command, strlen($commandPrefix)); 
    7477                } 
    75                 if (strtolower(substr($message, 0, strlen($bot))) == strtolower($bot)) { 
     78                if ($botPrefix) { 
    7679                    $ignorePrefix = true; 
    7780                } 
    7881            } 
    7982 
    80             if ((!$commandPrefix || $hasPrefix || $ignorePrefix) && isset($this->methods[$command])) { 
     83            if ((empty($commandPrefix) || $hasPrefix || $ignorePrefix) && isset($this->methods[$command])) { 
    8184                if ($this->needsAdmin && !$this->fromAdmin()) { 
    8285                    $this->doNotice($user, 'You do not have permission to use the command "' . $command . '."');