Assembla home | Assembla project page
 

Changeset 106

Show
Ignore:
Timestamp:
03/03/08 01:36:28 (9 months ago)
Author:
tobias382
Message:

* Modified all declarations and uses of checkDependencies to include the current client instance
* Modified the Weather plugin to check for authentication-related configuration settings as part of its dependencies check

Files:

Legend:

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

    r102 r106  
    154154            require_once 'Phergie/Plugin/' . $plugin . '.php'; 
    155155            $class = 'Phergie_Plugin_' . $plugin; 
    156             if (call_user_func(array($class, 'checkDependencies'), $plugins)) { 
     156            if (call_user_func(array($class, 'checkDependencies'), $client, $plugins)) { 
    157157                $instance = new $class($client); 
    158158                $instance->enabled = $enabled; 
  • trunk/Phergie/Plugin/Abstract/AdminCommand.php

    r103 r106  
    9090    * Returns whether or not the plugin's dependencies are met. 
    9191    * 
     92    * @param Phergie_Driver_Abstract $client Client instance 
    9293    * @param array $plugins List of short names for plugins that the 
    9394    *                       bootstrap file intends to instantiate 
    94     * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
    9595    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
    9696    * @return bool TRUE if dependencies are met, FALSE otherwise 
    9797    */ 
    98     public static function checkDependencies(array $plugins) 
     98    public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 
    9999    { 
    100100        if (! in_array('Users', $plugins) 
    101             || ! Phergie_Plugin_Users::checkDependencies($plugins)) { 
     101            || ! Phergie_Plugin_Users::checkDependencies($client, $plugins)) { 
    102102            return false; 
    103103        } 
  • trunk/Phergie/Plugin/Abstract/Base.php

    r82 r106  
    219219    * Plugins with such requirements should override this method. 
    220220    * 
     221    * @param Phergie_Driver_Abstract $client Client instance 
    221222    * @param array $plugins List of short names for plugins that the 
    222223    *                       bootstrap file intends to instantiate 
    223224    * @return bool TRUE if dependencies are met, FALSE otherwise 
    224225    */ 
    225     public static function checkDependencies(array $plugins) 
     226    public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 
    226227    { 
    227228        return true; 
  • trunk/Phergie/Plugin/Acronym.php

    r85 r106  
    7373    * Returns whether or not the plugin's dependencies are met. 
    7474    * 
    75     * @param array $plugins List of short names for plugins that the  
     75    * @param Phergie_Driver_Abstract $client Client instance 
     76    * @param array $plugins List of short names for plugins that the 
    7677    *                       bootstrap file intends to instantiate 
    77     * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
    7878    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
    7979    * @return bool TRUE if dependencies are met, FALSE otherwise 
    8080    */ 
    81     public static function checkDependencies(array $plugins) 
     81    public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 
    8282    { 
    8383        if (! in_array('Users', $plugins) 
    84             || ! Phergie_Plugin_Users::checkDependencies($plugins)) { 
     84            || ! Phergie_Plugin_Users::checkDependencies($client, $plugins)) { 
    8585            return false; 
    8686        } 
  • trunk/Phergie/Plugin/Drink.php

    r78 r106  
    186186    * Returns whether or not the plugin's dependencies are met. 
    187187    * 
    188     * @param array $plugins List of short names for plugins that the  
     188    * @param Phergie_Driver_Abstract $client Client instance 
     189    * @param array $plugins List of short names for plugins that the 
    189190    *                       bootstrap file intends to instantiate 
    190     * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
    191191    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
    192192    * @return bool TRUE if dependencies are met, FALSE otherwise 
    193193    */ 
    194     public static function checkDependencies(array $plugins) 
     194    public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 
    195195    { 
    196196        if (!extension_loaded('PDO')  
  • trunk/Phergie/Plugin/Karma.php

    r90 r106  
    147147    * Returns whether or not the plugin's dependencies are met. 
    148148    * 
     149    * @param Phergie_Driver_Abstract $client Client instance 
    149150    * @param array $plugins List of short names for plugins that the 
    150151    *                       bootstrap file intends to instantiate 
    151     * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
    152152    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
    153153    * @return bool TRUE if dependencies are met, FALSE otherwise 
    154154    */ 
    155     public static function checkDependencies(array $plugins) 
     155    public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 
    156156    { 
    157157        if (!extension_loaded('PDO') 
  • trunk/Phergie/Plugin/Lart.php

    r91 r106  
    101101    * Returns whether or not the plugin's dependencies are met. 
    102102    * 
    103     * @param array $plugins List of short names for plugins that the  
     103    * @param Phergie_Driver_Abstract $client Client instance 
     104    * @param array $plugins List of short names for plugins that the 
    104105    *                       bootstrap file intends to instantiate 
    105     * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
    106106    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
    107107    * @return bool TRUE if dependencies are met, FALSE otherwise 
    108108    */ 
    109     public static function checkDependencies(array $plugins) 
     109    public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 
    110110    { 
    111111        if (!extension_loaded('PDO')  
  • trunk/Phergie/Plugin/Logging.php

    r78 r106  
    118118    */ 
    119119    protected $heard; 
     120 
     121    /** 
     122    * PRepared statement for searching for one or more time ranges during  
     123    * which a particular user is most likely to be present in a particular  
     124    * channel  
     125    * 
     126    * @var PDOStatement 
     127    */ 
     128    protected $willsee; 
    120129 
    121130    /** 
     
    185194                $result = $this->db->exec(' 
    186195                    CREATE TABLE logs ( 
    187                         tstamp VARCHAR(14), 
     196                        tstamp VARCHAR(19), 
    188197                        type SHORTINT, 
    189198                        chan VARCHAR(45), 
     
    222231                AND chan = :chan 
    223232                ORDER BY tstamp DESC 
     233                LIMIT 1 
     234            '); 
     235 
     236            $this->willsee = $this->db->prepare(' 
     237                SELECT strftime("%H", tstamp) post_hour, COUNT(*) post_count 
     238                FROM logs 
     239                WHERE type IN (' . self::PRIVMSG . ', ' . self::ACTION . ') 
     240                AND nick = :nick 
     241                AND chan = :chan 
     242                GROUP BY strftime("%H", tstamp) 
     243                ORDER BY 2 DESC, 1 
    224244                LIMIT 1 
    225245            '); 
     
    247267    * Returns whether or not the plugin's dependencies are met. 
    248268    * 
    249     * @param array $plugins List of short names for plugins that the  
     269    * @param Phergie_Driver_Abstract $client Client instance 
     270    * @param array $plugins List of short names for plugins that the 
    250271    *                       bootstrap file intends to instantiate 
    251     * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
    252272    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
    253273    * @return bool TRUE if dependencies are met, FALSE otherwise 
    254274    */ 
    255     public static function checkDependencies(array $plugins) 
     275    public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 
    256276    { 
    257277        if (! in_array('Users', $plugins) 
    258             || ! Phergie_Plugin_Users::checkDependencies($plugins)) { 
     278            || ! Phergie_Plugin_Users::checkDependencies($client, $plugins)) { 
    259279            return false; 
    260280        } 
     
    320340 
    321341        $params = array( 
    322             ':tstamp' => date('YmdHis'), 
     342            ':tstamp' => date('Y-m-d H:i:s'), 
    323343            ':type' => $type, 
    324344            ':chan' => $chan, 
     
    642662        } 
    643663    } 
     664 
     665    /** 
     666    * Responds to requests for a time range during which a particular user  
     667    * is most likely to be present in the channel from which the request  
     668    * originates. 
     669    * 
     670    * @param string $user Nick of the user to search for 
     671    * @return void 
     672    */ 
     673    public function onDoWillsee($user) 
     674    { 
     675        if (!$this->db) { 
     676            return; 
     677        } 
     678         
     679        // Check to make sure the request came from a channel 
     680        $source = $this->event->getSource(); 
     681        if ($source[0] != '#') { 
     682            return; 
     683        } 
     684 
     685        // Handle cases where the bot is the subject 
     686        if ($user == $this->getIni('nick')) { 
     687            $this->doPrivmsg($source, 'What are you talking about? I\'m always here!'); 
     688            return; 
     689        } 
     690 
     691        // Handle 'me' alias 
     692        if ($user == 'me') { 
     693            $user = $this->event->getNick(); 
     694        } 
     695 
     696        // Perform the search 
     697        $params = array( 
     698            ':nick' => $user, 
     699            ':chan' => $source 
     700        ); 
     701 
     702        $this->willsee->execute($params); 
     703        $prediction = $this->willsee->fetchColumn(); 
     704 
     705        // Return if no results are found 
     706        if ($prediction === false) { 
     707            $this->doPrivmsg($source, $user . ' ' . $this->randomMissing()); 
     708            return; 
     709        } 
     710 
     711        // Calculate a predicted time of arrival  
     712        $hour = date('H'); 
     713        if ($hour > $prediction) { 
     714            $prediction = 24 - ($hour - $prediction); 
     715        } else { 
     716            $prediction = $prediction - $hour; 
     717        } 
     718 
     719        // Return with a message including the prediction 
     720        $message = $user . ' is most likely to be online '; 
     721        if ($prediction == 0) { 
     722            $message .= 'now!'; 
     723        } elseif ($prediction == 1) { 
     724            $message .= 'in 1 hour.'; 
     725        } else { 
     726            $message .= 'in ' . $prediction . ' hours.'; 
     727        } 
     728        $this->doPrivmsg($source, $message); 
     729    } 
    644730} 
  • trunk/Phergie/Plugin/Nickserv.php

    r88 r106  
    4242    * Returns whether or not the plugin's dependencies are met. 
    4343    * 
     44    * @param Phergie_Driver_Abstract $client Client instance 
    4445    * @param array $plugins List of short names for plugins that the 
    4546    *                       bootstrap file intends to instantiate 
    46     * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
    4747    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
    4848    * @return bool TRUE if dependencies are met, FALSE otherwise 
    4949    */ 
    50     public static function checkDependencies(array $plugins) 
     50    public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 
    5151    { 
     52        // Only the ghostbust command requires being an admin 
    5253        return true; 
    5354    } 
  • trunk/Phergie/Plugin/Weather.php

    r100 r106  
    99* Detects and responds to requests for current weather conditions in a  
    1010* particular location using data from a web service. Requires registering  
    11 * with weather.com to obtained authentication credentials. 
     11* with weather.com to obtain authentication credentials, which must be  
     12* stored in the configuration settings partner_id and license_key for the  
     13* plugin to function. 
    1214* 
    1315* @see http://www.weather.com/services/xmloap.html 
     
    1517class Phergie_Plugin_Weather extends Phergie_Plugin_Abstract_Command 
    1618{ 
     19    /** 
     20    * Partner ID for web service authentication 
     21    * 
     22    * @var string 
     23    */ 
     24    protected $partnerId; 
     25 
     26    /** 
     27    * License Key for web service authentication 
     28    * 
     29    * @var string 
     30    */ 
     31    protected $licenseKey; 
     32 
     33    /** 
     34    * Obtains configuration settings used for web service authentication. 
     35    * 
     36    * @return void 
     37    */ 
     38    public function init() 
     39    { 
     40        $this->partnerId = $this->getPluginIni('partner_id'); 
     41        $this->licenseKey = $this->getPluginIni('license_key'); 
     42    } 
     43 
     44    /** 
     45    * Returns whether or not the plugin's dependencies are met. 
     46    * 
     47    * @param Phergie_Driver_Abstract $client Client instance 
     48    * @param array $plugins List of short names for plugins that the 
     49    *                       bootstrap file intends to instantiate 
     50    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
     51    * @return bool TRUE if dependencies are met, FALSE otherwise 
     52    */ 
     53    public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 
     54    { 
     55        $partnerId = $client->getIni('weather.partner_id'); 
     56        $licenseKey = $client->getIni('weather.license_key'); 
     57 
     58        if (!$partnerId || !$licenseKey) { 
     59            return false; 
     60        } 
     61         
     62        return true; 
     63    } 
     64 
    1765        public function onDoWeather($where) 
    1866        { 
    19         $partnerId = $this->getPluginIni('partner_id'); 
    20         $licenseKey = $this->getPluginIni('license_key'); 
    21  
    22         if (!$partnerId || !$licenseKey) { 
    23             return; 
    24         } 
    25  
    2667        $context = stream_context_create(array('http' => array('timeout' => 3))); 
    2768 
     
    3576                if(count($xml->loc) != 0) { 
    3677                        $where = $xml->loc[0]['id']; 
    37                         $feed = 'http://xoap.weather.com/weather/local/' . $where . '?cc=*&prod=xoap&par=' . $partnerId . '&key=' . $licenseKey;  
     78                        $feed = 'http://xoap.weather.com/weather/local/' . $where . '?cc=*&prod=xoap&par=' . $this->partnerId . '&key=' . $this->licenseKey;  
    3879            $contents = @file_get_contents($feed, null, $context); 
    3980            if (!$contents) {