Assembla home | Assembla project page
 

Changeset 134

Show
Ignore:
Timestamp:
03/07/08 02:46:57 (9 months ago)
Author:
tobias382
Message:

Logging: Removed responses when the user is online or no result is found from the seen and search commands and removed the heard command

Files:

Legend:

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

    r126 r134  
    134134    */ 
    135135    protected $insert; 
    136  
    137     /** 
    138     * Answers for seen when the user is present 
    139     * 
    140     * @var array 
    141     */ 
    142     protected $present = array 
    143     ( 
    144         'Open your eyes already!', 
    145         'Are you blind?', 
    146         'Behind you!', 
    147         'Over there!', 
    148     ); 
    149  
    150     /** 
    151     * Answers for when record of a user cannot be found 
    152     * 
    153     * @var array 
    154     */ 
    155     protected $missing = array 
    156     ( 
    157         'must be mute, or one of your imaginary friends?', 
    158         'was never heard from... a first time.', 
    159         'was never heard from... to begin with.', 
    160         'must have eluded my ubiquity.', 
    161     ); 
    162136 
    163137    /** 
     
    219193                FROM logs 
    220194                WHERE nick = :name 
    221                 AND chan = :chan 
    222                 ORDER BY tstamp DESC 
    223                 LIMIT 1 
    224             '); 
    225  
    226             $this->heard = $this->db->prepare(' 
    227                 SELECT tstamp, type, message 
    228                 FROM logs 
    229                 WHERE type IN (' . self::PRIVMSG . ', ' . self::ACTION . ') 
    230                 AND nick = :nick 
    231195                AND chan = :chan 
    232196                ORDER BY tstamp DESC 
     
    304268 
    305269    /** 
    306     * Returns a random message used when a user is currently present. 
    307     * 
    308     * @return string 
    309     */ 
    310     protected function randomPresent() 
    311     { 
    312         return $this->present[array_rand($this->present)]; 
    313     } 
    314  
    315     /** 
    316     * Returns a random message used when no logged record of a user exists. 
    317     * 
    318     * @return string 
    319     */ 
    320     protected function randomMissing() 
    321     { 
    322         return $this->missing[array_rand($this->missing)]; 
    323     } 
    324  
    325     /** 
    326270    * Inserts a new entry in the log database. 
    327271    * 
     
    562506        } 
    563507 
    564         // Person is online, send a random prank answer 
    565         if (Phergie_Plugin_Users::isIn($user, $source)) { 
    566             $this->doPrivmsg( 
    567                 $source, 
    568                 sprintf( 
    569                     '%s: %s', 
    570                     $target, 
    571                     $this->randomPresent() 
    572                 ) 
    573             ); 
    574  
    575         // Person is offline 
    576         } else { 
    577             $params = array( 
    578                 ':name' => $user, 
    579                 ':chan' => $source 
    580             ); 
    581  
    582             $this->seen->execute($params); 
    583             $row = $this->seen->fetch(PDO::FETCH_ASSOC); 
    584  
    585             // Send the last action if available 
    586             if ($row) { 
    587                 $this->doPrivmsg( 
    588                     $source, 
    589                     sprintf( 
    590                         '%s: %s was last seen %s: %s (on %s)', 
    591                         $target, 
    592                         $user, 
    593                         $this->actions[$row['type']], 
    594                         $row['message'], 
    595                         $this->formatTimestamp($row['tstamp']) 
    596                     ) 
    597                 ); 
    598  
    599             // Send a prank answer if no last action is found 
    600             } else { 
    601                 $this->doPrivmsg( 
    602                     $source, 
    603                     sprintf( 
    604                         '%s: %s %s', 
    605                         $target, 
    606                         $user, 
    607                         $this->randomMissing() 
    608                     ) 
    609                 ); 
    610             } 
    611         } 
    612     } 
    613  
    614     /** 
    615     * Responds to requests for the last logged PRIVMSG action or CTCP ACTION 
    616     * command originating from a particular user. 
    617     * 
    618     * @param string $user Nick of the user to search for 
    619     * @return void 
    620     */ 
    621     public function onDoHeard($user) 
    622     { 
    623         if (!$this->db) { 
    624             return; 
    625         } 
    626  
    627         // Don't match if user has a space (obviously it's not a nick) 
    628         if (strpos($user, ' ') !== false) { 
    629                 return; 
    630         } 
    631  
    632         $source = $this->event->getSource(); 
    633         $target = $this->event->getNick(); 
    634  
    635         // Handle 'me' alias 
    636         if ($user == 'me') { 
    637             $user = $target; 
    638         } 
    639  
    640         // Search for the last recorded action 
    641         $params = array( 
    642             ':nick' => $user, 
    643             ':chan' => $source 
    644         ); 
    645  
    646         $this->heard->execute($params); 
    647         $row = $this->heard->fetch(PDO::FETCH_ASSOC); 
    648  
    649         // Send the last action if available 
    650         if($row) { 
    651             $this->doPrivmsg( 
    652                 $source, 
    653                 sprintf( 
    654                     '%s: %s\'s last words were: %s (on %s)', 
    655                     $target, 
    656                     $user, 
    657                     $row['message'], 
    658                     $this->formatTimestamp($row['tstamp']) 
    659                 ) 
    660             ); 
    661  
    662         // Send a prank answer if no last action is found 
    663         } else { 
    664             $this->doPrivmsg( 
    665                 $source, 
    666                 sprintf( 
    667                     '%s: %s %s', 
    668                     $target, 
    669                     $user, 
    670                     $this->randomMissing() 
    671                 ) 
    672             ); 
    673         } 
     508                // Get the last event from the specified user 
     509                $params = array( 
     510                        ':name' => $user, 
     511                        ':chan' => $source 
     512                ); 
     513 
     514                $this->seen->execute($params); 
     515                $row = $this->seen->fetch(PDO::FETCH_ASSOC); 
     516 
     517                // Send the last action if available 
     518                if ($row) { 
     519                        $this->doPrivmsg( 
     520                                $source, 
     521                                sprintf( 
     522                                        '%s: %s was last seen %s: %s (on %s)', 
     523                                        $target, 
     524                                        $user, 
     525                                        $this->actions[$row['type']], 
     526                                        $row['message'], 
     527                                        $this->formatTimestamp($row['tstamp']) 
     528                                ) 
     529                        ); 
     530                } 
    674531    } 
    675532 
     
    716573        // Return if no results are found 
    717574        if ($prediction === false) { 
    718             $this->doPrivmsg($source, $user . ' ' . $this->randomMissing()); 
    719575            return; 
    720576        }