Changeset 106
- Timestamp:
- 03/03/08 01:36:28 (9 months ago)
- Files:
-
- trunk/Phergie/Bot.php (modified) (1 diff)
- trunk/Phergie/Plugin/Abstract/AdminCommand.php (modified) (1 diff)
- trunk/Phergie/Plugin/Abstract/Base.php (modified) (1 diff)
- trunk/Phergie/Plugin/Acronym.php (modified) (1 diff)
- trunk/Phergie/Plugin/Drink.php (modified) (1 diff)
- trunk/Phergie/Plugin/Karma.php (modified) (1 diff)
- trunk/Phergie/Plugin/Lart.php (modified) (1 diff)
- trunk/Phergie/Plugin/Logging.php (modified) (6 diffs)
- trunk/Phergie/Plugin/Nickserv.php (modified) (1 diff)
- trunk/Phergie/Plugin/Weather.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Bot.php
r102 r106 154 154 require_once 'Phergie/Plugin/' . $plugin . '.php'; 155 155 $class = 'Phergie_Plugin_' . $plugin; 156 if (call_user_func(array($class, 'checkDependencies'), $ plugins)) {156 if (call_user_func(array($class, 'checkDependencies'), $client, $plugins)) { 157 157 $instance = new $class($client); 158 158 $instance->enabled = $enabled; trunk/Phergie/Plugin/Abstract/AdminCommand.php
r103 r106 90 90 * Returns whether or not the plugin's dependencies are met. 91 91 * 92 * @param Phergie_Driver_Abstract $client Client instance 92 93 * @param array $plugins List of short names for plugins that the 93 94 * bootstrap file intends to instantiate 94 * @return bool TRUE if the plugins dependencies are met, FALSE otherwise95 95 * @see Phergie_Plugin_Abstract_Base::checkDependencies() 96 96 * @return bool TRUE if dependencies are met, FALSE otherwise 97 97 */ 98 public static function checkDependencies( array $plugins)98 public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 99 99 { 100 100 if (! in_array('Users', $plugins) 101 || ! Phergie_Plugin_Users::checkDependencies($ plugins)) {101 || ! Phergie_Plugin_Users::checkDependencies($client, $plugins)) { 102 102 return false; 103 103 } trunk/Phergie/Plugin/Abstract/Base.php
r82 r106 219 219 * Plugins with such requirements should override this method. 220 220 * 221 * @param Phergie_Driver_Abstract $client Client instance 221 222 * @param array $plugins List of short names for plugins that the 222 223 * bootstrap file intends to instantiate 223 224 * @return bool TRUE if dependencies are met, FALSE otherwise 224 225 */ 225 public static function checkDependencies( array $plugins)226 public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 226 227 { 227 228 return true; trunk/Phergie/Plugin/Acronym.php
r85 r106 73 73 * Returns whether or not the plugin's dependencies are met. 74 74 * 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 76 77 * bootstrap file intends to instantiate 77 * @return bool TRUE if the plugins dependencies are met, FALSE otherwise78 78 * @see Phergie_Plugin_Abstract_Base::checkDependencies() 79 79 * @return bool TRUE if dependencies are met, FALSE otherwise 80 80 */ 81 public static function checkDependencies( array $plugins)81 public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 82 82 { 83 83 if (! in_array('Users', $plugins) 84 || ! Phergie_Plugin_Users::checkDependencies($ plugins)) {84 || ! Phergie_Plugin_Users::checkDependencies($client, $plugins)) { 85 85 return false; 86 86 } trunk/Phergie/Plugin/Drink.php
r78 r106 186 186 * Returns whether or not the plugin's dependencies are met. 187 187 * 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 189 190 * bootstrap file intends to instantiate 190 * @return bool TRUE if the plugins dependencies are met, FALSE otherwise191 191 * @see Phergie_Plugin_Abstract_Base::checkDependencies() 192 192 * @return bool TRUE if dependencies are met, FALSE otherwise 193 193 */ 194 public static function checkDependencies( array $plugins)194 public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 195 195 { 196 196 if (!extension_loaded('PDO') trunk/Phergie/Plugin/Karma.php
r90 r106 147 147 * Returns whether or not the plugin's dependencies are met. 148 148 * 149 * @param Phergie_Driver_Abstract $client Client instance 149 150 * @param array $plugins List of short names for plugins that the 150 151 * bootstrap file intends to instantiate 151 * @return bool TRUE if the plugins dependencies are met, FALSE otherwise152 152 * @see Phergie_Plugin_Abstract_Base::checkDependencies() 153 153 * @return bool TRUE if dependencies are met, FALSE otherwise 154 154 */ 155 public static function checkDependencies( array $plugins)155 public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 156 156 { 157 157 if (!extension_loaded('PDO') trunk/Phergie/Plugin/Lart.php
r91 r106 101 101 * Returns whether or not the plugin's dependencies are met. 102 102 * 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 104 105 * bootstrap file intends to instantiate 105 * @return bool TRUE if the plugins dependencies are met, FALSE otherwise106 106 * @see Phergie_Plugin_Abstract_Base::checkDependencies() 107 107 * @return bool TRUE if dependencies are met, FALSE otherwise 108 108 */ 109 public static function checkDependencies( array $plugins)109 public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 110 110 { 111 111 if (!extension_loaded('PDO') trunk/Phergie/Plugin/Logging.php
r78 r106 118 118 */ 119 119 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; 120 129 121 130 /** … … 185 194 $result = $this->db->exec(' 186 195 CREATE TABLE logs ( 187 tstamp VARCHAR(1 4),196 tstamp VARCHAR(19), 188 197 type SHORTINT, 189 198 chan VARCHAR(45), … … 222 231 AND chan = :chan 223 232 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 224 244 LIMIT 1 225 245 '); … … 247 267 * Returns whether or not the plugin's dependencies are met. 248 268 * 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 250 271 * bootstrap file intends to instantiate 251 * @return bool TRUE if the plugins dependencies are met, FALSE otherwise252 272 * @see Phergie_Plugin_Abstract_Base::checkDependencies() 253 273 * @return bool TRUE if dependencies are met, FALSE otherwise 254 274 */ 255 public static function checkDependencies( array $plugins)275 public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 256 276 { 257 277 if (! in_array('Users', $plugins) 258 || ! Phergie_Plugin_Users::checkDependencies($ plugins)) {278 || ! Phergie_Plugin_Users::checkDependencies($client, $plugins)) { 259 279 return false; 260 280 } … … 320 340 321 341 $params = array( 322 ':tstamp' => date('Y mdHis'),342 ':tstamp' => date('Y-m-d H:i:s'), 323 343 ':type' => $type, 324 344 ':chan' => $chan, … … 642 662 } 643 663 } 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 } 644 730 } trunk/Phergie/Plugin/Nickserv.php
r88 r106 42 42 * Returns whether or not the plugin's dependencies are met. 43 43 * 44 * @param Phergie_Driver_Abstract $client Client instance 44 45 * @param array $plugins List of short names for plugins that the 45 46 * bootstrap file intends to instantiate 46 * @return bool TRUE if the plugins dependencies are met, FALSE otherwise47 47 * @see Phergie_Plugin_Abstract_Base::checkDependencies() 48 48 * @return bool TRUE if dependencies are met, FALSE otherwise 49 49 */ 50 public static function checkDependencies( array $plugins)50 public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) 51 51 { 52 // Only the ghostbust command requires being an admin 52 53 return true; 53 54 } trunk/Phergie/Plugin/Weather.php
r100 r106 9 9 * Detects and responds to requests for current weather conditions in a 10 10 * 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. 12 14 * 13 15 * @see http://www.weather.com/services/xmloap.html … … 15 17 class Phergie_Plugin_Weather extends Phergie_Plugin_Abstract_Command 16 18 { 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 17 65 public function onDoWeather($where) 18 66 { 19 $partnerId = $this->getPluginIni('partner_id');20 $licenseKey = $this->getPluginIni('license_key');21 22 if (!$partnerId || !$licenseKey) {23 return;24 }25 26 67 $context = stream_context_create(array('http' => array('timeout' => 3))); 27 68 … … 35 76 if(count($xml->loc) != 0) { 36 77 $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; 38 79 $contents = @file_get_contents($feed, null, $context); 39 80 if (!$contents) {