Assembla home | Assembla project page
 

Changeset 196

Show
Ignore:
Timestamp:
03/30/08 01:01:51 (8 months ago)
Author:
Slynderdale
Message:

Merged the Reconnect and Quit plugins together and added the reconnect command to Quit

Files:

Legend:

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

    r194 r196  
    2020 
    2121    /** 
     22     * Random reconnect messages used if a quit message isn't given 
     23     * 
     24     * @var array 
     25     */ 
     26        protected $messages = array 
     27        ( 
     28                'I\'ll be back.', 
     29                'I shall return.', 
     30                'Look to my coming at first light on the fifth day. At dawn look to the East.', 
     31                'kthx, brb.', 
     32                'Beam me up, Scotty!', 
     33        ); 
     34 
     35    /** 
    2236    * Processes requests for the bot to disconnect from the server. 
    2337    * 
     
    3044    * @return void 
    3145    */ 
    32     public function handleQuit($message = ''
     46    public function handleQuit($message = '', $reconnect = false
    3347    { 
    3448        if ($this->fromAdmin(true)) { 
    35             $reason = trim(!empty($message) ? $message : $this->getPluginIni('reason')); 
    36             if(substr($reason, 0, 1) === '(' && substr($reason, -1) === ')') { 
    37                 $reason = substr($reason, 1, -1); 
     49            $message = trim(!empty($message) || $reconnect ? $message : $this->getPluginIni('reason')); 
     50            if(substr($message, 0, 1) === '(' && substr($message, -1) === ')') { 
     51              $message = substr($message, 1, -1); 
    3852            } 
    39             if (empty($reason)) { 
    40                 $reason = 'by request of %nick%'; 
     53            if (!$reconnect && empty($message)) { 
     54                $message = 'by request of %nick%'; 
    4155            } 
    42             $reason = str_replace('%nick%', $this->event->getNick(), trim($reason)); 
    43             $this->doQuit($reason); 
     56            $message = str_replace('%nick%', $this->event->getNick(), trim($message)); 
     57            if (empty($message)) { 
     58                $message = $this->messages[array_rand($this->messages, 1)]; 
     59            } 
     60            $this->doQuit($message, $reconnect); 
    4461        } 
    4562    } 
     
    6481        $this->handleQuit($message); 
    6582    } 
     83 
     84        /** 
     85         * Reconnects to the server and rehashes the ini data 
     86         */ 
     87    public function onDoReconnect($message='') 
     88    { 
     89        $this->handleQuit($message, true); 
     90    } 
    6691}