Assembla home | Assembla project page
 

Changeset 179

Show
Ignore:
Timestamp:
03/21/08 22:40:41 (8 months ago)
Author:
Slynderdale
Message:

Some minor bug fixes and code improvements as well as some added debug info if debug mode is enabled.

Files:

Legend:

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

    r173 r179  
    397397        } 
    398398 
    399                 if ($time > 0) { 
     399                if ($time > 0 || count($return) <= 0) { 
    400400                        $return[] = $time . 's'; 
    401401                } 
  • trunk/Phergie/Plugin/Abstract/Command.php

    r151 r179  
    3838    * @return void 
    3939    */ 
    40     protected final function processCommand($message, $ignorePrefix = false, $adminCommand = false) 
     40    protected final function processCommand($message, $ignorePrefix = false, $forceBotPrefix = false) 
    4141    { 
    4242        if (!$this->methods) { 
     
    5656        // Checks to see if the command was prefixed with the bot's name 
    5757        $target = $this->event->getArgument(0); 
    58         $exp = ($target[0] == '#' && $adminCommand) ? 
    59                 '(?:' . $this->getIni('nick') . '\s*:?\s+)' : 
    60                 '(?:' . $this->getIni('nick') . '\s*:?\s+)?'; 
     58        $bot = $this->getIni('nick'); 
     59        $exp = '(?:'.preg_quote($bot).'\s*:?\s+)' . (!($target[0] == '#' && $forceBotPrefix) ? '?': ''); 
    6160 
    6261        if (preg_match('/^'.$exp.'(\S+)(?:[\s'.chr(240).']+(.*))?$/', $message, $match)) { 
     
    6665            // Checks the command for a prefix if one is specified in the config 
    6766            $commandPrefix = trim($this->getIni('command_prefix')); 
    68             $hasPrefix = ($commandPrefix && substr($command, 0, strlen($commandPrefix)) == $commandPrefix); 
    69             if ($hasPrefix) { 
    70                 $command = substr($command, strlen($commandPrefix)); 
     67            if ($commandPrefix) { 
     68                if ($hasPrefix = (substr($command, 0, strlen($commandPrefix)) == $commandPrefix)) { 
     69                    $command = substr($command, strlen($commandPrefix)); 
     70                } 
     71                if (strtolower(substr($message, 0, strlen($bot))) == strtolower($bot)) { 
     72                    $ignorePrefix = true; 
     73                } 
    7174            } 
    7275 
  • trunk/Phergie/Plugin/ChuckNorris.php

    r157 r179  
    173173        // Checks to see if the chuckfacts table exists 
    174174        $table = $this->db 
    175             ->query("SELECT COUNT(*) FROM sqlite_master WHERE name = 'chuckfacts'"
     175            ->query('SELECT COUNT(*) FROM sqlite_master WHERE name = ' . $this->db->quote('chuckfacts')
    176176            ->fetchColumn(); 
    177177 
    178178        // If the table doesn't exist, create them and return true for the next step 
    179179        if (!$table) { 
    180                   $this->debug('Creating tables.'); 
     180                $this->debug('Creating the database schema'); 
    181181            $this->db->exec('CREATE TABLE chuckfacts (facts VARCHAR(255))'); 
    182182            $this->db->exec('CREATE UNIQUE INDEX chuckfacts_name ON chuckfacts (facts)'); 
  • trunk/Phergie/Plugin/Convert.php

    r108 r179  
    77 
    88/** 
    9 * Performs and responds with messages containing the results of conversions  
     9* Performs and responds with messages containing the results of conversions 
    1010* between different units. 
    1111*/ 
     
    2525        ))); 
    2626 
    27         $url = 'http://www.google.com/search?q=' . urlencode($convert) . '&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a'; 
     27        $url = 'http://www.google.com/search?q=' . urlencode($convert) . '&btnG=Google+Search&aq=f'; 
    2828        $contents = @file_get_contents($url, null, $context); 
    2929        if (empty($contents)) { 
  • trunk/Phergie/Plugin/Drink.php

    r121 r179  
    9595            // Populate the database if necessary 
    9696            if ($this->needTable('beer')) { 
     97                $this->debug('Retrieving data for: Beer'); 
    9798                $contents = @file_get_contents('http://beerme.com/beerlist.php'); 
    9899                if ($contents !== false) { 
     100                        $this->debug('Parsing data for: Beer'); 
    99101                    preg_match_all('/brewery\.php\?[0-9]+#[0-9]+\'>([^<]+)/', $contents, $matches); 
    100102                    $names = array(); 
     
    119121                $limit = 2; 
    120122                $names = array(); 
     123                $this->debug('Retrieving data for: Cocktail'); 
    121124                for ($i = 1; $i <= $limit; $i += 150) { 
    122125                    $contents = @file_get_contents('http://www.webtender.com/db/browse?level=2&dir=drinks&char=%2A&start=' . $i); 
     
    124127                        break; 
    125128                    } 
     129                    $this->debug('Parsing data for: Cocktail (' . $i . ' - ' . ($i + 150) . ')'); 
    126130                    if ($i == 1) { 
    127131                        preg_match('/>([0-9]+) found\\.</', $contents, $match); 
     
    144148 
    145149            if ($this->needTable('coke')) { 
     150                $this->debug('Retrieving data for: Coke'); 
    146151                $contents = @file_get_contents('http://www.energyfiend.com/huge-caffeine-database/'); 
    147152                if ($contents) { 
     153                        $this->debug('Parsing data for: Coke'); 
    148154                    // List of drinks to filter out 
    149155                    $filter = array( 
     
    169175 
    170176            if ($this->needTable('tea')) { 
     177                $this->debug('Retrieving data for: Tea'); 
    171178                $names = @file('http://www.midnight-labs.org/tea.txt'); 
    172179                if ($names) { 
     180                        $this->debug('Parsing data for: Tea'); 
    173181                    foreach ($names as $key => $value) { 
    174182                        $names[$key] = ucwords(rtrim($value)); 
     
    233241    private function populateTable($table, $names) 
    234242    { 
     243        $this->debug('Creating the database schema for: ' . ucfirst($table)); 
    235244        $this->db->exec('CREATE TABLE ' . $table . ' (name VARCHAR(255))'); 
    236245        $this->db->exec('CREATE UNIQUE INDEX ' . $table . '_name ON ' . $table . ' (name)'); 
  • trunk/Phergie/Plugin/Karma.php

    r161 r179  
    132132        if (!file_exists($db)) { 
    133133            $this->db = new PDO('sqlite:' . $db); 
     134 
     135            $this->debug('Creating the database schema'); 
    134136            $this->db->query(' 
    135137                CREATE TABLE karmas ( word VARCHAR ( 255 ) , karma MEDIUMINT ) ; 
     
    169171 
    170172        $this->fetchKarma = $this->db->prepare(' 
    171             SELECT karma, ROWID id FROM karmas WHERE word = :word LIMIT 1 
     173            SELECT karma, ROWID id FROM karmas WHERE LOWER(word) = LOWER(:word) LIMIT 1 
    172174        '); 
    173175 
    174176        $this->updateKarma = $this->db->prepare(' 
    175             UPDATE karmas SET karma = :karma WHERE word = :word 
     177            UPDATE karmas SET karma = :karma WHERE LOWER(word) = LOWER(:word) 
    176178        '); 
    177179    } 
     
    211213 
    212214        // Command prefix check 
    213         $commandPrefix = preg_quote(trim($this->getIni('command_prefix'))); 
    214         $prefix = ($commandPrefix ? $commandPrefix . '|' : '').'(?:' . $this->getIni('nick') . '\s*:?\s+)?'; 
     215        $prefix = preg_quote(trim($this->getIni('command_prefix'))); 
     216        $bot    = preg_quote($this->getIni('nick')); 
     217        $exp = '(?:(?:'.$bot.'\s*:?\s+(?:'.$prefix.')?)|(?:'.$prefix.'))'; 
    215218 
    216219        // Karma status request 
    217         if (preg_match('#^(?:'.$prefix.')karma\s+(.+)$#i', $message, $m)) { 
     220        if (preg_match('#^'.$exp.'karma\s+(.+)$#i', $message, $m)) { 
    218221            // Return user's value if "me" is requested 
    219222            if (strtolower($m[1]) === 'me') { 
     
    246249            } 
    247250        // Incrementation/decrementation request 
    248         } elseif (preg_match('{^(?:'.$prefix.')?(\S+?|\(.+?\)+)(\+{2,}|-{2,})(?:\s+(.*))?$}i', $message, $m)) { 
     251        } elseif (preg_match('{^'.$exp.'?(\S+?|\(.+?\)+)(\+{2,}|-{2,})(?:\s+(.*))?$}i', $message, $m)) { 
    249252            $word = strtolower($m[1]); 
    250253            // Strip parenthesis grouping multiple words 
     
    287290                    ':word' => $word 
    288291                ); 
     292                $this->debug('Updated karma: '. $word . ' = ' . ($res['karma'] + ($m[2]=='++' ? 1 : -1))); 
    289293                $this->updateKarma->execute($args); 
    290294            } else { 
     
    293297                    ':karma' => ($m[2]=='++' ? '1' : '-1') 
    294298                ); 
     299                $this->debug('Inserted karma: '. $word . ' = ' . ($m[2]=='++' ? '1' : '-1')); 
    295300                $this->insertKarma->execute($args); 
    296301                $this->fetchKarma->execute(array(':word'=>$word)); 
     
    302307            $comment = preg_replace('{(?:^//(.*)|^#(.*)|^/\*(.*?)\*/$)}', '$1$2$3', $m[3]); 
    303308            if (!empty($comment)) { 
     309                $this->debug('Inserted comment: '. $comment); 
    304310                $this->insertComment->execute(array(':wordid' => $id, ':comment' => $comment)); 
    305311            } 
  • trunk/Phergie/Plugin/Toggle.php

    r153 r179  
    6060                                } 
    6161 
     62 
    6263                                // Plugin file was found, check if it can be loaded 
    6364                                if (isset($target)) { 
     
    8182        public function onDoMute($plugin, $target='') 
    8283        { 
    83                 $target = trim((!empty($target) && $this->fromAdmin(false)) ? $target : $this->event->getSource()); 
     84                $target = strtolower(trim((!empty($target) && $this->fromAdmin(false)) ? $target : $this->event->getSource())); 
    8485                if (!empty($target)) { 
    8586                if ($instance = $this->getPlugin($plugin)) { 
    8687                        $instance->muted[$target] = true; 
    87                         $this->doPrivmsg($this->event->getSource(), 'Muted '.$plugin.' for '.$target.'.'); 
     88                        $target = ($target==strtolower($this->event->getSource())?'for this channel':($target=='global'?'globally':'for '.$target)); 
     89                        $this->doPrivmsg($this->event->getSource(), 'Muted '.$plugin.' '.$target.'.'); 
    8890                } else { 
    8991                        $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not mute.'); 
     
    98100                    if ($instance = $this->getPlugin($plugin)) { 
    99101                        $instance->muted[$target] = false; 
    100                         $this->doPrivmsg($this->event->getSource(), 'Unmuted '.$plugin.' for '.$target.'.'); 
     102                        $target = ($target==strtolower($this->event->getSource())?'for this channel':($target=='global'?'globally':'for '.$target)); 
     103                        $this->doPrivmsg($this->event->getSource(), 'Unmuted '.$plugin.' '.$target.'.'); 
    101104                } else { 
    102105                        $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not unmute.');