Assembla home | Assembla project page
 

Changeset 58

Show
Ignore:
Timestamp:
02/12/08 07:13:09 (10 months ago)
Author:
tobias382
Message:

This is an unstable commit meant only to store work in progress.
* Moved abstract plugin classes to the Plugin/Abstract directory
* Added a new debugging method to the base event handler class
* Updated plugin classes to use the new transparent event passing model:
* Modified the Drink plugin to check for, create, and populate database

tables individually and to return no response when an operation's
corresponding database table is empty from a failed population

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Phergie/Event/Handler.php

    r57 r58  
    133133 
    134134    /** 
     135    * Shorthand for the underlying driver's debugging function. 
     136    * 
     137    * @param string $message Message to log 
     138    * @return void 
     139    */ 
     140    public function debug($message) 
     141    { 
     142        $this->client->debug($this->name . ' -> ' . $message); 
     143    } 
     144 
     145    /** 
    135146    * Initializes the plugin. Should it require initialization, just  
    136147    * override this method. 
  • trunk/Phergie/Plugin/Abstract/Command.php

    r57 r58  
    66require_once 'Phergie/Event/Handler.php'; 
    77 
    8 abstract class Phergie_Plugin_Command extends Phergie_Event_Handler 
     8abstract class Phergie_Plugin_Abstract_Command extends Phergie_Event_Handler 
    99{ 
    1010    protected $cache = array(); 
    1111 
    12     public function onPrivmsg(Phergie_Event_Request $event
     12    public function onPrivmsg(
    1313    { 
    14         $this->processCommand($event->getArgument(1), $event); 
     14        $this->processCommand($this->event->getArgument(1)); 
    1515    } 
    1616 
    17     protected function processCommand($message, $event
     17    protected function processCommand($message
    1818    { 
    1919        preg_match('/^\S+/', $message, $match); 
    2020        $command = 'onDo' . ucfirst(strtolower($match[0])); 
    2121 
    22         $class = get_class($this); 
     22        $class = $this->getName();  
    2323        if (!isset($this->cache[$class])) { 
    2424            $this->cache[$class] = array(); 
     
    2828            $cache  = array('exists' => false); 
    2929            if (method_exists($this, $command)) { 
     30                $cache['exists'] = true; 
    3031                $method = new ReflectionMethod($this, $command); 
    31                 $cache['exists'] = true; 
    32                 $cache['num_args'] = $method->getNumberOfParameters(); 
    33                 $cache['needs_event'] = false;  
    34                 foreach ($method->getParameters() as $key => $param) { 
    35                     $paramClass = $param->getClass(); 
    36                     if ($paramClass && $paramClass->getName() == 'Phergie_Event_Request') { 
    37                         $cache['needs_event'] = true;  
    38                         $cache['event_position'] = $key; 
    39                         break; 
    40                     } 
    41                 } 
     32                $cache['num_args'] = $method->getNumberOfRequiredParameters(); 
    4233            } 
    4334            $this->cache[$class][$command] = $cache; 
     
    4738 
    4839        if ($method['exists']) { 
    49             $split = $method['num_args'] + 1; 
    50             if ($method['needs_event']) { 
    51                 $split--; 
    52             } 
    53             $params = array_slice(preg_split('/\s+/', $message, $split), 1); 
     40            $params = array_slice(preg_split('/\s+/', $message, $method['num_args'] + 1), 1); 
    5441            $paramsCount = count($params); 
    55             if ($method['num_args'] > $paramsCount) { 
    56                 $params += array_fill(0, $method['num_args'] - $paramsCount, null); 
    57             } 
    58             if ($method['needs_event']) { 
    59                 $params[$method['event_position']] = $event; 
    60             } 
    61             if (count($params) == $method['num_args']) { 
     42            if ($method['num_args'] <= $paramsCount) { 
    6243                call_user_func_array(array($this, $command), $params); 
    6344            } 
  • trunk/Phergie/Plugin/Abstract/Cron.php

    r57 r58  
    1212         * overload it with your own value if needed 
    1313         */ 
    14         protected $defaultTTL = 60; 
     14        protected $defaultTtl = 60; 
    1515 
    1616        /** 
     
    3636    { 
    3737                if($this->ttl === null) { 
    38                         if ((($time = $this->getIni('time_to_live')) !== null) || $time = $this->defaultTTL) { 
     38                        if ((($time = $this->getIni('time_to_live')) !== null) || $time = $this->defaultTtl) { 
    3939                                $this->ttl = $time; 
    4040                        } 
     
    4646    } 
    4747 
    48     public function onPing(Phergie_Event_Request $event
     48    public function onPing(
    4949    { 
    5050        $this->check(); 
    5151    } 
    5252 
    53     public function onPrivmsg(Phergie_Event_Request $event
     53    public function onPrivmsg(
    5454    { 
    5555        $this->check(); 
  • trunk/Phergie/Plugin/Autojoin.php

    r57 r58  
    11<?php 
    22 
    3 require_once 'Phergie/Event/Handler/Autojoin.php'; 
     3require_once 'Phergie/Event/Handler.php'; 
    44 
    55class Phergie_Plugin_Autojoin extends Phergie_Event_Handler 
    66{ 
    7     public function onResponse(Phergie_Event_Response $response
     7    public function onResponse(
    88    { 
    99        $channels = $this->getIni('channels'); 
    1010        if (!empty($channels) 
    11             && $response->getCode() == Phergie_Event_Response::RPL_ENDOFMOTD) { 
     11            && $this->event->getCode() == Phergie_Event_Response::RPL_ENDOFMOTD) { 
    1212            $this->doJoin(implode(' ', preg_split('#[, ]+#', $channels))); 
    1313        } 
  • trunk/Phergie/Plugin/DNSLookup.php

    r57 r58  
    88class Phergie_Plugin_DNSLookup extends Phergie_Event_Handler 
    99{ 
    10     public function onPrivmsg(Phergie_Event_Request $event
     10    public function onPrivmsg(
    1111    { 
     12        $source = $this->event->getSource(); 
     13        $text = $this->event->getArgument(1); 
     14 
    1215        // Check if we have [rev]dns IP-address and if the IP is valid 
    13         if (preg_match('#^(?:rev)?dns ((?:[0-9]{1,3}\.){3}[0-9]{1,3})$#i', $event->getArgument(1), $m) && ip2long($m[1]) !== false) { 
    14                 $this->doPrivmsg($event->getArgument(0), $m[1].' resolved as '.gethostbyaddr(long2ip(ip2long($m[1])))); 
    15         } 
     16        if (preg_match('#^(?:rev)?dns ((?:[0-9]{1,3}\.){3}[0-9]{1,3})$#i', $text, $m) && ip2long($m[1]) !== false) { 
     17                $this->doPrivmsg($source, $m[1] . ' resolved as ' . gethostbyaddr(long2ip(ip2long($m[1])))); 
    1618        // Check if we have [rev]dns host 
    17         elseif (preg_match('#^(?:rev)?dns ((?:[a-z0-9]+\.)+[a-z]{2,6})$#i', $event->getArgument(1), $m)) { 
     19        } elseif (preg_match('#^(?:rev)?dns ((?:[a-z0-9]+\.)+[a-z]{2,6})$#i', $text, $m)) { 
    1820                if(($ip = gethostbyname($m[1])) !== $m[1]) { 
    19                 $this->doPrivmsg($event->getArgument(0), $m[1] .' resolved as '.$ip); 
     21                $this->doPrivmsg($source, $m[1] . ' resolved as '.$ip); 
    2022                } else { 
    21                 $this->doPrivmsg($event->getArgument(0), $m[1] .' can not be resolved'); 
     23                $this->doPrivmsg($source, $m[1] . ' can not be resolved'); 
    2224                } 
    2325        } 
  • trunk/Phergie/Plugin/Daddy.php

    r57 r58  
    88class Phergie_Plugin_Daddy extends Phergie_Event_Handler 
    99{ 
    10     public function onPrivmsg(Phergie_Event_Request $event
     10    public function onPrivmsg(
    1111    { 
    1212        $bot = $this->getConnection()->getNick(); 
    13         $msg = $event->getArgument(1); 
    14         if (preg_match('/' . $bot . '\s*:?\s+?who\'?s your daddy\\??/iAD', $msg)) { 
    15             $this->doPrivmsg($event->getArgument(0), 'You\'re my daddy, ' . $event->getNick() . '!'); 
     13        $text = $this->event->getArgument(1); 
     14        if (preg_match('/' . $bot . '\s*:?\s+?who\'?s your daddy\\??/iAD', $text)) { 
     15            $this->doPrivmsg($this->getSource(), 'You\'re my daddy, ' . $this->event->getNick() . '!'); 
    1616        } 
    1717    } 
  • trunk/Phergie/Plugin/Debug.php

    r57 r58  
    22 
    33/** 
    4 * @see Phergie_Plugin_AdminCommand 
     4* @see Phergie_Plugin_Abstract_AdminCommand 
    55*/ 
    6 require_once 'Phergie/Event/Handler/AdminCommand.php'; 
     6require_once 'Phergie/Plugin/Abstract/AdminCommand.php'; 
    77 
    8 class Phergie_Plugin_Debug extends Phergie_Event_Handler_AdminCommand 
     8class Phergie_Plugin_Debug extends Phergie_Plugin_Abstract_AdminCommand 
    99{ 
    10     public function onDoMem(Phergie_Event_Request $event
     10    public function onDoMem(
    1111    { 
    1212        $text = 'current : '.number_format(memory_get_usage() / 1024).'KB / peak : '.number_format(memory_get_peak_usage() / 1024).'KB'; 
    13         $this->doPrivmsg($event->getArgument(0), $text);  
     13        $this->doPrivmsg($this->getSource(), $text);  
    1414    } 
    1515} 
  • trunk/Phergie/Plugin/Drink.php

    r57 r58  
    22 
    33/** 
    4 * @see Phergie_Plugin_Command 
     4* @see Phergie_Plugin_Abstract_Command 
    55*/ 
    6 require_once 'Phergie/Event/Handler/Command.php'; 
    7  
    8 class Phergie_Plugin_Drink extends Phergie_Event_Handler_Command 
     6require_once 'Phergie/Plugin/Abstract/Command.php'; 
     7 
     8class Phergie_Plugin_Drink extends Phergie_Plugin_Abstract_Command 
    99{ 
    1010        /** 
     
    6464    ); 
    6565 
    66     private function createTable($name) 
     66    private function needTable($name) 
     67    { 
     68        $table = $this->db 
     69            ->query('SELECT COUNT(*) FROM sqlite_master WHERE name = ' . $this->db->quote($name)) 
     70            ->fetchColumn(); 
     71 
     72        if (!$table) { 
     73            return true; 
     74        } 
     75 
     76        return !$this->db 
     77            ->query('SELECT COUNT(*) FROM ' . $name) 
     78            ->fetchColumn(); 
     79    } 
     80 
     81    private function populateTable($table, $names) 
    6782    { 
    6883        $this->db->exec(' 
     
    7085            CREATE UNIQUE INDEX ' . $name . ' ON ' . $name . ' (name); 
    7186        '); 
    72     } 
    73  
    74     private function populateTable($table, $names) 
    75     { 
     87 
    7688        $stmt = $this->db->prepare('INSERT INTO ' . $table . ' (name) VALUES (:name)'); 
    7789        $this->db->beginTransaction(); 
     
    7991            foreach ($this->filter as $filter) { 
    8092                if (preg_match('/(^|[^a-z])' . $filter . '([^a-z]|$)/i', $name)) { 
    81                     echo 'Filtered out ' . $name . ' because it contains ' . $filter . "\n"
     93                    $this->debug('Filtered out ' . $name . ' because it contains ' . $filter)
    8294                    continue 2; 
    8395                } 
    8496            } 
    85             echo 'Inserted ' . $name . "\n"
     97            $this->debug('Inserted ' . $name)
    8698            $stmt->execute(array('name' => $name)); 
    8799        } 
     
    115127 
    116128        // Initialize the database connection 
    117         $db = $dir . '/drink.db'; 
    118         $populate = !file_exists($db); 
    119         $this->db = new PDO('sqlite:' . $db); 
     129        $this->db = new PDO('sqlite:' . $dir . '/drink.db'); 
    120130 
    121131        // Populate the database if necessary 
    122         if ($populate) { 
    123             $this->createTable('beer'); 
    124             $contents = file_get_contents('http://beerme.com/beerlist.php'); 
    125             preg_match_all('/brewery\.php\?[0-9]+#[0-9]+\'>([^<]+)/', $contents, $matches); 
    126             $names = array(); 
    127             foreach ($matches[1] as $key => $name) { 
    128                 if ($this->hasBadChars($name) 
    129                     || strpos($name, '(discontinued)') !== false) { 
    130                     continue; 
    131                 } 
    132                 $name = trim(array_shift(explode('/', preg_replace('/\([^)]+\)/', '', $name)))); 
    133                 if (!empty($name)) { 
    134                     $name = html_entity_decode($name); 
    135                     $names[] = $name; 
    136                 } 
    137             } 
    138             $this->populateTable('beer', $names); 
    139             unset($names); 
    140  
    141             $this->createTable('cocktail'); 
     132        if ($this->needTable('beer')) { 
     133            $contents = @file_get_contents('http://beerme.com/beerlist.php'); 
     134            if ($contents !== false) { 
     135                preg_match_all('/brewery\.php\?[0-9]+#[0-9]+\'>([^<]+)/', $contents, $matches); 
     136                $names = array(); 
     137                foreach ($matches[1] as $key => $name) { 
     138                    if ($this->hasBadChars($name) 
     139                        || strpos($name, '(discontinued)') !== false) { 
     140                        continue; 
     141                    } 
     142                    $name = trim(array_shift(explode('/', preg_replace('/\([^)]+\)/', '', $name)))); 
     143                    if (!empty($name)) { 
     144                        $name = html_entity_decode($name); 
     145                        $names[] = $name; 
     146                    } 
     147                } 
     148                $this->populateTable('beer', $names); 
     149                unset($names); 
     150            } 
     151        } 
     152 
     153        if ($this->needTable('cocktail')) { 
    142154            $limit = 2; 
    143155            $names = array(); 
    144156            for ($i = 1; $i <= $limit; $i += 150) { 
    145                 $contents = file_get_contents('http://www.webtender.com/db/browse?level=2&dir=drinks&char=%2A&start=' . $i); 
     157                $contents = @file_get_contents('http://www.webtender.com/db/browse?level=2&dir=drinks&char=%2A&start=' . $i); 
     158                if ($contents === false) { 
     159                    break; 
     160                } 
    146161                if ($i == 1) { 
    147162                    preg_match('/>([0-9]+) found\\.</', $contents, $match); 
     
    157172                } 
    158173            } 
    159             $this->populateTable('cocktail', $names); 
     174            if ($contents) { 
     175                $this->populateTable('cocktail', $names); 
     176            } 
    160177            unset($names); 
    161  
    162             $this->createTable('coke'); 
    163             $contents = file_get_contents('http://www.energyfiend.com/huge-caffeine-database/'); 
    164             $start = stripos($contents, 'id="caffeinedb"'); 
    165             $end = stripos($contents, '</table>', $start); 
    166             $contents = substr($contents, $start, $end - $start); 
    167             preg_match_all('/<tr[^>]*><td>(<[^>]+>)?([^<]+)/is', $contents, $matches); 
    168             $names = array(); 
    169             foreach ($matches[2] as $name) { 
    170                 $name = html_entity_decode(trim(preg_replace('/ \\([^)]+\\)| - .*$/', '', $name))); 
    171                 $names[] = $name; 
    172             } 
    173             $this->populateTable('coke', $names); 
    174                         unset($names); 
    175  
    176                         $this->createTable('tea'); 
    177                         $names = file('http://www.midnight-labs.org/tea.txt'); 
    178                         $names = array_map('trim', $names); 
    179                         $this->populateTable('tea', $names); 
    180                         unset($names); 
    181         } 
    182     } 
    183  
    184     protected function throwDrink($type, $target, Phergie_Event_Request $event) 
     178        } 
     179 
     180        if ($this->needTable('coke')) { 
     181            $contents = @file_get_contents('http://www.energyfiend.com/huge-caffeine-database/'); 
     182            if ($contents) { 
     183                $start = stripos($contents, 'id="caffeinedb"'); 
     184                $end = stripos($contents, '</table>', $start); 
     185                $contents = substr($contents, $start, $end - $start); 
     186                preg_match_all('/<tr[^>]*><td>(<[^>]+>)?([^<]+)/is', $contents, $matches); 
     187                $names = array(); 
     188                foreach ($matches[2] as $name) { 
     189                    $name = html_entity_decode(trim(preg_replace('/ \\([^)]+\\)| - .*$/', '', $name))); 
     190                    if (!preg_match('/(?:^|\s+)tea(?:\s+|$)/', $name)) { 
     191                        $names[] = $name; 
     192                    } 
     193                } 
     194                $this->populateTable('coke', $names); 
     195                unset($names); 
     196            } 
     197        } 
     198 
     199        if ($this->needTable('tea')) { 
     200                        $names = @file('http://www.midnight-labs.org/tea.txt'); 
     201            if ($names) { 
     202                foreach ($names as $key => $value) {  
     203                    $names[$key] = ucwords(rtrim($value)); 
     204                } 
     205                $this->populateTable('tea', $names); 
     206                unset($names); 
     207            } 
     208        } 
     209    } 
     210 
     211    protected function throwDrink($type, $target) 
    185212    { 
    186213        if (!$this->db) { 
     
    189216 
    190217        if (preg_match('/^me(\s|$)/', $target)) { 
    191             $target = preg_replace('/^me/', $event->getNick(), $target); 
     218            $target = preg_replace('/^me/', $this->event->getNick(), $target); 
    192219        } else if ($target == $this->getConnection()->getNick()) { 
    193220            $gender = $this->getIni('gender'); 
     
    198225            } 
    199226        } 
    200         $channel = $event->getArgument(0); 
     227         
    201228        $drink = $this->getRandomRecord($type); 
    202229 
    203                 if ($type != 'tea') { 
    204                         $text = 'throws ' . $target . ' a'; 
    205                         if (preg_match('/^[aeoiu]/i', $drink)) { 
    206                                 $text .= 'n'; 
    207             } 
    208                         $text .= ' ' . $drink; 
    209                 } else { 
    210                         // One must be gentle with tea 
    211                         $text = 'pours '.$target.' a cup of '.$drink.' tea'; 
    212                 } 
    213  
    214         $this->doCtcpAction($channel, $text); 
    215     } 
    216  
    217     public function onDoBeer($target, Phergie_Event_Request $event) 
    218     { 
    219         $this->throwDrink('beer', $target, $event); 
    220     } 
    221  
    222     public function onDoCocktail($target, Phergie_Event_Request $event) 
    223     { 
    224         $this->throwDrink('cocktail', $target, $event); 
    225     } 
    226  
    227     public function onDoCoke($target, Phergie_Event_Request $event) 
    228     { 
    229         $this->throwDrink('coke', $target, $event); 
    230     } 
    231  
    232     public function onDoTea( $target, Phergie_Event_Request $event ) 
    233     { 
    234                 $this->throwDrink('tea', $target, $event); 
     230        if ($drink) { 
     231            if ($type != 'tea') { 
     232                $text = 'throws ' . $target . ' a'; 
     233                if (preg_match('/^[aeoiu]/i', $drink)) { 
     234                    $text .= 'n'; 
     235                } 
     236                $text .= ' ' . $drink; 
     237            } else { 
     238                // One must be gentle with tea 
     239                $text = 'pours '.$target.' a cup of '.$drink.' tea'; 
     240            } 
     241            $this->doCtcpAction($this->event->getSource(), $text); 
     242        } 
     243    } 
     244 
     245    public function onDoBeer($target) 
     246    { 
     247        $this->throwDrink('beer', $target); 
     248    } 
     249 
     250    public function onDoCocktail($target) 
     251    { 
     252        $this->throwDrink('cocktail', $target); 
     253    } 
     254 
     255    public function onDoCoke($target) 
     256    { 
     257        $this->throwDrink('coke', $target); 
     258    } 
     259 
     260    public function onDoTea( $target ) 
     261    { 
     262                $this->throwDrink('tea', $target); 
    235263    } 
    236264} 
  • trunk/Phergie/Plugin/JoinPart.php

    r57 r58  
    22 
    33/** 
    4 * @see Phergie_Plugin_AdminCommand 
     4* @see Phergie_Plugin_Abstract_AdminCommand 
    55*/ 
    6 require_once 'Phergie/Event/Handler/AdminCommand.php'; 
     6require_once 'Phergie/Plugin/Abstract/AdminCommand.php'; 
    77 
    8 class Phergie_Plugin_JoinPart extends Phergie_Event_Handler_AdminCommand 
     8class Phergie_Plugin_JoinPart extends Phergie_Plugin_Abstract_AdminCommand 
    99{ 
    1010    /** 
     
    2525    * @param Phergie_Event_Request $event Intercepted event 
    2626    */ 
    27     public function onDoPart($channel = null, Phergie_Event_Request $event
     27    public function onDoPart($channel = null
    2828    { 
    2929        if (empty($channel)) { 
    30             $this->doPart($event->getArgument(0)); 
     30            $this->doPart($this->event->getArgument(0)); 
    3131        } else { 
    3232            $this->doPart($channel); 
  • trunk/Phergie/Plugin/Karma.php

    r57 r58  
    1616         * Retains the last garbage collection date 
    1717         */ 
    18         protected $lastGC = null; 
     18        protected $lastGc = null; 
    1919 
    2020        /** 
     
    3333        public function init() 
    3434        { 
     35        $this->db = null; 
     36        $this->lastGc = null; 
     37        $this->log = null; 
     38 
    3539                $this->fixedKarma = array 
    3640                ( 
     
    7882         * Plugin code, handles requests 
    7983         */ 
    80     public function onPrivmsg(Phergie_Event_Request $event
     84    public function onPrivmsg(
    8185    { 
    8286        if ($this->db === null) { 
    8387                return; 
    8488        } 
     89        $target = $this->getSource(); 
     90        $message = $this->event->getArgument(1); 
    8591        // Karma status request 
    86         if (preg_match('#^karma (\S+?)$#i', $event->getArgument(1), $m)) { 
     92        if (preg_match('#^karma (\S+?)$#i', $message, $m)) { 
    8793                // Return fixed value if set 
    8894                if(isset($this->fixedKarma[strtolower($m[1])])) { 
    89                         $this->doPrivmsg($event->getArgument(0), $m[1] . ' ' . $this->fixedKarma[strtolower($m[1])]); 
     95                        $this->doPrivmsg($source, $m[1] . ' ' . $this->fixedKarma[strtolower($m[1])]); 
    9096                        return; 
    9197                } 
     
    9399                        $res = $this->db->query('SELECT karma FROM karmas WHERE word = \''.sqlite_escape_string(strtolower($m[1])).'\' LIMIT 1', SQLITE_NUM); 
    94100                        if ($res->numRows() && $res->column(0) != 0) { 
    95                         $this->doPrivmsg($event->getArgument(0), $m[1].' has karma of '.$res->column(0)); 
     101                        $this->doPrivmsg($source, $m[1].' has karma of '.$res->column(0)); 
    96102                        } else { 
    97                         $this->doPrivmsg($event->getArgument(0), $m[1].' has neutral karma'); 
     103                        $this->doPrivmsg($source, $m[1].' has neutral karma'); 
    98104                        } 
    99         } 
    100105        // Incrementation/decrementation request 
    101         elseif (preg_match('#^(\S+?)(\+\+|--)\s*(.*)$#i', $event->getArgument(1), $m)) { 
     106        } elseif (preg_match('#^(\S+?)(\+\+|--)\s*(.*)$#i', $message, $m)) { 
    102107                        $word = strtolower($m[1]); 
    103108                        // Do nothing if it's fixed 
     
    106111                        } 
    107112                        // Forces a decrementation if someone tries to update his own karma 
    108                         if ($word == strtolower($event->getNick())) { 
     113                        if ($word == strtolower($this->event->getNick())) { 
    109114                                $m[2] = '--'; 
    110115                        } 
    111116                        // Flood check 
    112                         if (isset($this->log[$event->getHost()][$word]) && $this->log[$event->getHost()][$word] > time()) { 
     117            $host = $this->event->getHost(); 
     118                        if (isset($this->log[$host][$word]) && $this->log[$host][$word] > time()) { 
    113119                                return; 
    114120                        } 
    115                         $this->log[$event->getHost()][$word] = time() + 86400; 
     121                        $this->log[$host][$word] = time() + 86400; 
    116122                        // Get the current value then update or create entry 
    117123                        $res = $this->db->query('SELECT karma, ROWID FROM karmas WHERE word = \''.sqlite_escape_string($word).'\' LIMIT 1', SQLITE_NUM); 
     
    129135                        } 
    130136                        // Collect garbage off the anti-flood log once a day 
    131                         if (date('d') !== $this->lastGC) { 
    132                                 $this->doGC(); 
     137                        if (date('d') !== $this->lastGc) { 
     138                                $this->doGc(); 
    133139                        } 
    134140        } 
     
    138144         * Performs garbage collection on the anti-flood log 
    139145         */ 
    140     public function doGC() 
     146    public function doGc() 
    141147        { 
    142148                $now = time(); 
     
    151157                        } 
    152158                } 
    153                 $this->lastGC = date('d'); 
     159                $this->lastGc = date('d'); 
    154160        } 
    155161} 
  • trunk/Phergie/Plugin/Lart.php

    r57 r58  
    9494    } 
    9595 
    96     public function onPrivmsg(Phergie_Event_Request $event
     96    public function onPrivmsg(
    9797    { 
    98         $channel = $event->getArgument(0); 
    9998        $message = $event->getArgument(1); 
    10099        $nick = $this->getConnection()->getNick(); 
     
    133132            } while($redirect); 
    134133            if ($definition) { 
    135                 $this->doPrivmsg($channel, $definition); 
     134                $this->doPrivmsg($this->event->getSource(), $definition); 
    136135            } 
    137136        } 
  • trunk/Phergie/Plugin/Logging.php

    r57 r58  
    6868 
    6969                // Create plugin dir if not there yet 
    70                 if (!file_exists(dirname(__FILE__).'/Logging')) 
    71                         mkdir(dirname(__FILE__).'/Logging'); 
     70        $dir = dirname(__FILE__) . '/Logging'; 
     71                if (!file_exists($dir)) { 
     72                        mkdir($dir); 
     73        } 
    7274 
    7375                // Load or initialize de logging database 
    74                 $db = dirname(__FILE__).'/Logging/logging.db'; 
     76                $db = $dir . '/logging.db'; 
    7577                if (!file_exists($db)) { 
    7678                        $this->db = new SQLiteDatabase($db); 
     
    8890         * Tracks text and answers requests 
    8991         */ 
    90         public function onPrivmsg(Phergie_Event_Request $event) { 
     92        public function onPrivmsg() 
     93    { 
    9194                if (preg_match('#^search (\S+)$#', $event->getArgument(1), $m)) { 
    9295                        // Search DB 
  • trunk/Phergie/Plugin/Users.php

    r57 r58  
    88class Phergie_Plugin_Users extends Phergie_Event_Handler 
    99{ 
    10         protected static $list = array(); 
    11         const OP = 8; 
    12         const HALFOP = 4; 
    13         const VOICE = 2; 
    14         const REGULAR = 1; 
    15  
    16         /** 
    17          * Tracks mode changes 
    18          */ 
    19         public function onMode(Phergie_Event_Request $event) 
    20         { 
    21                 if (preg_match('{(\S+)\s((?:\+|-)[hov+-]+)\s((?:\s*\S+)+)$}i', $event->getArgument(0), $m)) { 
    22                         $chan = $m[1]; 
    23                         $modes = str_split($m[2], 1); 
    24                         $nicks = explode(' ', $m[3]); 
    25                         while ($char = array_shift($modes)) { 
    26                                 switch($char) { 
    27                                         case '+': 
    28                                                 $mode = '+'; 
    29                                                 break; 
    30                                         case '-': 
    31                                                 $mode = '-'; 
    32                                                 break; 
    33                                         case 'o': 
    34                                                 $nick = array_shift($nicks); 
    35                                                 if ($mode == '+') { 
    36                                                         self::$list[$chan][$nick] |= self::OP; 
    37                                                 } elseif ($mode == '-') { 
    38                                                         self::$list[$chan][$nick] ^= self::OP; 
    39                                                 } 
    40                                                 break; 
    41                                         case 'h': 
    42                                                 $nick = array_shift($nicks); 
    43                                                 if ($mode == '+') { 
    44                                                         self::$list[$chan][$nick] |= self::OP; 
    45                                                 } elseif ($mode == '-') { 
    46                                                         self::$list[$chan][$nick] ^= self::OP; 
    47                                                 } 
    48                                                 break; 
    49                                         case 'v': 
    50                                                 $nick = array_shift($nicks); 
    51                                                 if ($mode == '+') { 
    52                                                         self::$list[$chan][$nick] |= self::OP; 
    53                                                 } elseif ($mode == '-') { 
    54                                                         self::$list[$chan][$nick] ^= self::OP; 
    55                                                 } 
    56                                                 break; 
    57                                 } 
    58                         } 
    59                 } 
    60         } 
    61  
    62         /* DEBUG Func * / 
    63         public function onPrivmsg(Phergie_Event_Request $event) { 
    64                 if(preg_match('#^ishere (\S+)$#', $event->getArgument(1), $m)) { 
    65                         $this->doPrivmsg($event->getArgument(0), self::isIn($m[1], $event->getArgument(0)) ? 'true':'false'); 
    66                 } 
    67                 if(preg_match('#^isop (\S+)$#', $event->getArgument(1), $m)) { 
    68                         $this->doPrivmsg($event->getArgument(0), self::isOp($m[1], $event->getArgument(0)) ? 'true':'false'); 
    69                 } 
    70                 if(preg_match('#^isvoice (\S+)$#', $event->getArgument(1), $m)) { 
    71                         $this->doPrivmsg($event->getArgument(0), self::isVoice($m[1], $event->getArgument(0)) ? 'true':'false'); 
    72                 } 
    73         } 
    74         //*/ 
    75  
    76         /** 
    77          * Tracks users joining 
    78          */ 
    79         public function onJoin(Phergie_Event_Request $event) 
    80         { 
    81                 self::$list[$event->getArgument(0)][$event->getNick()] = self::REGULAR; 
    82         } 
    83  
    84         /** 
    85          * Tracks users parting 
    86          */ 
    87         public function onPart(Phergie_Event_Request $event) 
    88         { 
    89                 if (isset(self::$list[$event->getArgument(0)][$event->getNick()])) { 
    90                         unset(self::$list[$event->getArgument(0)][$event->getNick()]); 
    91                 } 
    92         } 
    93  
    94         /** 
    95          * Tracks users quitting 
    96          */ 
    97         public function onQuit(Phergie_Event_Request $event) 
    98         { 
    99                 $nick = $event->getNick(); 
    100                 foreach (self::$list as $channame=>$chan) { 
    101                         if (isset($chan[$nick])) { 
    102                                 unset(self::$list[$channame][$nick]); 
    103                         } 
    104                 } 
    105         } 
    106  
    107         /** 
    108          * Tracks users changing nick 
    109          */ 
    110         public function onNick(Phergie_Event_Request $event) 
    111         { 
    112                 $nick = $event->getNick(); 
    113                 $newNick = $event->getArgument(0); 
    114                 echo "\n$nick => $newNick\n\n"; 
    115                 foreach (self::$list as $channame=>$chan) { 
    116                         if (isset($chan[$nick])) { 
    117                                 self::$list[$channame][$newNick] = $chan[$nick]; 
    118                                 unset(self::$list[$channame][$nick]); 
    119                         } 
    120                 } 
    121         } 
    122  
    123         /** 
    124          * Populates the list of a channel when the bot joins it 
    125          */ 
    126     public function onResponse(Phergie_Event_Response $event) 
    127     { 
    128                 if ($event->getCode() == Phergie_Event_Response::RPL_NAMREPLY) { 
    129                         $desc = $event->getDescription(); 
    130                         $desc = substr($desc, strpos($desc, '=')+2); 
    131                         list($chan, $users) = explode(' :', $desc); 
    132                         $users = explode(' ', $users); 
    133                         foreach ($users as $user) { 
    134                                 $flag = self::REGULAR; 
    135                                 if (substr($user, 0, 1) === '@') { 
    136                                         $user = substr($user, 1); 
    137                                         $flag |= self::OP; 
    138                                 } 
    139                                 if (substr($user, 0, 1) === '%') { 
    140                                         $user = substr($user, 1); 
    141                                         $flag |= self::HALFOP; 
    142                                 } 
    143                                 if (substr($user, 0, 1) === '+') { 
    144                                         $user = substr($user, 1); 
    145                                         $flag |= self::VOICE; 
    146                                 } 
    147                                 self::$list[$chan][$user] = $flag; 
    148                         } 
    149                 } 
    150     } 
    151  
    152         /** 
    153          * Checks whether someone has op (@) status 
    154          * 
    155          * @param string $nick The nick to check 
    156          * @param string $chan The chan where to check 
    157          * @return bool 
    158          */ 
    159         public static function isOp($nick, $chan) 
    160         { 
    161                 return isset(self::$list[$chan][$nick]) && (self::$list[$chan][$nick] & self::OP) != 0; 
    162         } 
    163  
    164         /** 
    165          * Checks whether someone has voice (+) status 
    166          * 
    167          * @param string $nick The nick to check 
    168          * @param string $chan The chan where to check 
    169