Changeset 215
- Timestamp:
- 04/08/08 01:18:52 (8 months ago)
- Files:
-
- trunk/Phergie/Bot.php (modified) (12 diffs)
- trunk/Phergie/Driver/Abstract.php (modified) (9 diffs)
- trunk/Phergie/Driver/Streams.php (modified) (37 diffs)
- trunk/Phergie/Event/Request.php (modified) (20 diffs)
- trunk/Phergie/Event/Response.php (modified) (6 diffs)
- trunk/Phergie/Plugin/Abstract/Base.php (modified) (24 diffs)
- trunk/Phergie/Plugin/Abstract/Command.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Abstract/Cron.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Acronym.php (modified) (8 diffs)
- trunk/Phergie/Plugin/Altnick.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Autojoin.php (modified) (3 diffs)
- trunk/Phergie/Plugin/ChuckNorris.php (modified) (12 diffs)
- trunk/Phergie/Plugin/Convert.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Ctcp.php (modified) (5 diffs)
- trunk/Phergie/Plugin/Daddy.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Debug.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Dice.php (modified) (10 diffs)
- trunk/Phergie/Plugin/Dns.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Drink.php (modified) (23 diffs)
- trunk/Phergie/Plugin/Eval.php (modified) (4 diffs)
- trunk/Phergie/Plugin/FeedTicker.php (modified) (12 diffs)
- trunk/Phergie/Plugin/JoinPart.php (modified) (5 diffs)
- trunk/Phergie/Plugin/Karma.php (modified) (18 diffs)
- trunk/Phergie/Plugin/Lart.php (modified) (19 diffs)
- trunk/Phergie/Plugin/Logging.php (modified) (14 diffs)
- trunk/Phergie/Plugin/Math.php (modified) (10 diffs)
- trunk/Phergie/Plugin/ModuleList.php (modified) (7 diffs)
- trunk/Phergie/Plugin/Nickserv.php (modified) (9 diffs)
- trunk/Phergie/Plugin/Php.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Pong.php (modified) (1 diff)
- trunk/Phergie/Plugin/Puppet.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Quit.php (modified) (15 diffs)
- trunk/Phergie/Plugin/Sed.php (modified) (6 diffs)
- trunk/Phergie/Plugin/Seen.php (modified) (13 diffs)
- trunk/Phergie/Plugin/Set.php (modified) (6 diffs)
- trunk/Phergie/Plugin/Spellcheck.php (modified) (4 diffs)
- trunk/Phergie/Plugin/Tld.php (modified) (10 diffs)
- trunk/Phergie/Plugin/Toggle.php (modified) (15 diffs)
- trunk/Phergie/Plugin/UrbanDictionary.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Url.php (modified) (24 diffs)
- trunk/Phergie/Plugin/Users.php (modified) (19 diffs)
- trunk/Phergie/Plugin/Weather.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Bot.php
r212 r215 2 2 3 3 /** 4 * This file functions as a daemon process used to bootstrap and execute the5 * client by loading its configuration file, instantiating it and event6 * handlers for it, configuring it, and executing its event handling loop.7 */8 9 /** 10 * Check to see if the version of PHP meets the minimum requirement11 */4 * This file functions as a daemon process used to bootstrap and execute the 5 * client by loading its configuration file, instantiating it and event 6 * handlers for it, configuring it, and executing its event handling loop. 7 */ 8 9 /** 10 * Check to see if the version of PHP meets the minimum requirement 11 */ 12 12 if (version_compare('5.1.2', PHP_VERSION, '>')) { 13 13 trigger_error('Fatal error: PHP 5.1.2+ is required, current version: ' . PHP_VERSION, E_USER_ERROR); 14 14 15 /**16 * Backwards compatibility check to see if the PHP version is lower than 5.217 */15 /** 16 * Backwards compatibility check to see if the PHP version is lower than 5.2 17 */ 18 18 } elseif (version_compare('5.2', PHP_VERSION, '>')) { 19 19 trigger_error('Warning: PHP 5.2+ is recommended, current version: ' . PHP_VERSION, E_USER_WARNING); … … 21 21 22 22 /** 23 * Code base version24 *25 * @const string26 */23 * Code base version 24 * 25 * @const string 26 */ 27 27 define('PHERGIE_VERSION', '1.0.3'); 28 28 29 29 /** 30 * Path to the configuration file used by default when one is not specified or31 * register_argc_argv is disabled in php.ini32 *33 * @const string34 */30 * Path to the configuration file used by default when one is not specified or 31 * register_argc_argv is disabled in php.ini 32 * 33 * @const string 34 */ 35 35 define('PHERGIE_DEFAULT_INI', 'phergie.ini'); 36 36 37 37 /** 38 * Path to the directory containing the Phergie directory39 *40 * @const string41 */38 * Path to the directory containing the Phergie directory 39 * 40 * @const string 41 */ 42 42 define('PHERGIE_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); 43 43 44 44 /** 45 * Path to the directory containing the plugins46 *47 * @const string48 */45 * Path to the directory containing the plugins 46 * 47 * @const string 48 */ 49 49 define('PHERGIE_PLUGIN_DIR', PHERGIE_DIR . 'Plugin' . DIRECTORY_SEPARATOR); 50 50 51 51 /** 52 * Add the Phergie directory to the include path 53 */ 54 set_include_path( 55 get_include_path() 56 . PATH_SEPARATOR . 57 dirname(PHERGIE_DIR) 58 ); 59 60 /** 61 * Check to make sure the CLI SAPI is being used 62 */ 52 * Add the Phergie directory to the include path 53 */ 54 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(PHERGIE_DIR)); 55 56 /** 57 * Check to make sure the CLI SAPI is being used 58 */ 63 59 if (strtolower(php_sapi_name()) != 'cli') { 64 60 trigger_error('Phergie requires the CLI SAPI in order to run', E_USER_ERROR); … … 66 62 67 63 /** 68 * Allow the bot to run indefinitely69 */64 * Allow the bot to run indefinitely 65 */ 70 66 set_time_limit(0); 71 67 72 68 /** 73 * Determine what configuration file should be used74 */69 * Determine what configuration file should be used 70 */ 75 71 if (!ini_get('register_argc_argv')) { 76 72 echo 'The register_argc_argv setting in php.ini is disabled, defaulting to ' . PHERGIE_DEFAULT_INI . PHP_EOL; … … 88 84 89 85 /** 90 * Name of the configuration file currently in use91 *92 * @const string93 */86 * Name of the configuration file currently in use 87 * 88 * @const string 89 */ 94 90 define('PHERGIE_INI', basename($ini)); 95 91 96 92 /** 97 * Path to the configuration file98 *99 * @const string100 */93 * Path to the configuration file 94 * 95 * @const string 96 */ 101 97 define('PHERGIE_INI_PATH', realpath($ini)); 102 98 103 99 /** 104 * Loader to automate inclusion of classes based on directory structure and 105 * class naming conventions. 106 * 107 * @param string $class Class name to check and attempt to load 108 * @return void 109 */ 110 function phergieAutoLoader($class) { 100 * Loader to automate inclusion of classes based on directory structure and 101 * class naming conventions. 102 * 103 * @param string $class Class name to check and attempt to load 104 * @return void 105 */ 106 function phergieAutoLoader($class) 107 { 111 108 $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; 112 require_once ($file);109 require_once ($file); 113 110 if (class_exists($class)) { 114 111 return; … … 120 117 121 118 /** 122 * Start a runtime loop that will reload all settings from the configuration123 * file if the bot disconnects and reconnects, allowing for flushing of the124 * configuration without a full shutdown of the bot125 */119 * Start a runtime loop that will reload all settings from the configuration 120 * file if the bot disconnects and reconnects, allowing for flushing of the 121 * configuration without a full shutdown of the bot 122 */ 126 123 while (true) { 127 124 /** 128 * Obtain and validate the contents of the configuration file129 */125 * Obtain and validate the contents of the configuration file 126 */ 130 127 $required = array('server', 'username', 'nick'); 131 128 $config = parse_ini_file(PHERGIE_INI_PATH); … … 136 133 137 134 $missing = array(); 138 foreach ($required as $value) {135 foreach($required as $value) { 139 136 if (empty($config[$value])) { 140 137 $missing[] = $value; … … 147 144 148 145 /** 149 * Set error reporting to display errors if debug mode is enabled150 */146 * Set error reporting to display errors if debug mode is enabled 147 */ 151 148 if ($config['debug']) { 152 error_reporting(E_ALL |E_STRICT);149 error_reporting(E_ALL|E_STRICT); 153 150 ini_set('display_errors', true); 154 151 ini_set('ignore_repeated_errors', true); … … 156 153 157 154 /** 158 * Configure the client159 */155 * Configure the client 156 */ 160 157 if (isset($config['driver'])) { 161 158 $driver = ucfirst(strtolower($config['driver'])); … … 168 165 $client = new $class(); 169 166 170 foreach ($config as $setting => $value) {167 foreach($config as $setting => $value) { 171 168 $client->setIni($setting, $value); 172 169 } 173 174 unset ($setting, $value, $driver, $class); 175 176 /** 177 * Determine which plugins should be loaded 178 */ 170 unset($setting, $value, $driver, $class); 171 172 /** 173 * Determine which plugins should be loaded 174 */ 179 175 $all = true; 180 176 $include = array(); 181 if (!empty($config['plugins']) 182 &&preg_match('/(all|none)(?:\s*except\s*(.+))?/ADi', $config['plugins'], $match)) {177 if (!empty($config['plugins']) && 178 preg_match('/(all|none)(?:\s*except\s*(.+))?/ADi', $config['plugins'], $match)) { 183 179 $all = trim(strtolower($match[1])) != 'none'; 184 180 if (!empty($match[2])) { … … 186 182 } 187 183 } 188 189 unset ($config, $match); 190 191 /** 192 * Set up plugins 193 */ 184 unset($config, $match); 185 186 /** 187 * Set up plugins 188 */ 194 189 $iterator = new DirectoryIterator(PHERGIE_PLUGIN_DIR); 195 190 $plugins = array(); 196 foreach ($iterator as $entry) {191 foreach($iterator as $entry) { 197 192 if ($iterator->isFile() && pathinfo($entry, PATHINFO_EXTENSION) == 'php') { 198 193 $name = basename($entry, '.php'); … … 202 197 } 203 198 } 204 205 199 ksort($plugins); 206 200 207 unset ($iterator, $entry, $name, $all, $include);208 209 foreach ($plugins as $plugin) {201 unset($iterator, $entry, $name, $all, $include); 202 203 foreach($plugins as $plugin) { 210 204 $class = 'Phergie_Plugin_' . $plugin; 211 205 /** 212 * @todo When PHP 5.3 is a stable release, change this to213 * $class::checkDependencies($client, $plugins);214 */206 * @todo When PHP 5.3 is a stable release, change this to 207 * $class::checkDependencies($client, $plugins); 208 */ 215 209 if (call_user_func(array($class, 'checkDependencies'), $client, $plugins)) { 216 210 $instance = new $class($client); … … 221 215 } 222 216 } 223 224 unset ($plugins, $plugin, $class, $instance); 225 226 /** 227 * Execute the event handling loop for the client 228 */ 217 unset($plugins, $plugin, $class, $instance); 218 219 /** 220 * Execute the event handling loop for the client 221 */ 229 222 $state = $client->run(); 230 223 unset($client); 231 224 232 switch($state) 233 { 225 switch ($state) { 234 226 case Phergie_Driver_Abstract::RETURN_RECONNECT: 235 227 sleep(1); 236 break;228 break; 237 229 case Phergie_Driver_Abstract::RETURN_KEEPALIVE: 238 230 sleep(15); 239 break;231 break; 240 232 case Phergie_Driver_Abstract::RETURN_END: 241 break 2;242 } 243 } 233 break 2; 234 } 235 } trunk/Phergie/Driver/Abstract.php
r213 r215 2 2 3 3 /** 4 * Handles reception, transmission, and processing of data sent to and5 * from IRC server.6 */4 * Handles reception, transmission, and processing of data sent to and 5 * from IRC server. 6 */ 7 7 abstract class Phergie_Driver_Abstract 8 8 { 9 /** #@+9 /** 10 10 * Return codes for the run function, that tells the Bot script whether 11 11 * it should re-run or not … … 14 14 const RETURN_KEEPALIVE = "keepalive"; 15 15 const RETURN_END = "end"; 16 /** #@-*/17 18 /**19 * Associative array mapping configuration setting names to their20 * respective values21 *22 * @var array23 */16 /** 17 18 /** 19 * Associative array mapping configuration setting names to their 20 * respective values 21 * 22 * @var array 23 */ 24 24 protected $config = array(); 25 25 26 26 /** 27 * List of plugin instances28 *29 * @var array30 */27 * List of plugin instances 28 * 29 * @var array 30 */ 31 31 protected $plugins; 32 32 33 33 /** 34 * Returns the value associated with a specified configuration setting.35 *36 * @param string $name Name of the setting37 * @return string Value of the setting, or NULL if the setting is not set38 */34 * Returns the value associated with a specified configuration setting. 35 * 36 * @param string $name Name of the setting 37 * @return string Value of the setting, or NULL if the setting is not set 38 */ 39 39 public final function getIni($name) 40 40 { 41 41 $name = strtolower($name); 42 if (!isset ($this->config[$name])) {42 if (!isset($this->config[$name])) { 43 43 return null; 44 44 } … … 47 47 48 48 /** 49 * Sets the value of a specified configuration setting, overwriting any50 * existing value for that setting.51 *52 * @param string $name Name of the setting53 * @param string $value New value for the setting54 * @return void55 */49 * Sets the value of a specified configuration setting, overwriting any 50 * existing value for that setting. 51 * 52 * @param string $name Name of the setting 53 * @param string $value New value for the setting 54 * @return void 55 */ 56 56 public final function setIni($name, $value) 57 57 { 58 $this->config[strtolower($name) ] = $value;59 } 60 61 /** 62 * Parses a IRC hostmask and sets nick, user and host bits.63 *64 * @param string $hostmask Hostmask to parse65 * @param string $nick Container for the nick66 * @param string $user Container for the username67 * @param string $host Container for the hostname68 * @return void69 */58 $this->config[strtolower($name) ] = $value; 59 } 60 61 /** 62 * Parses a IRC hostmask and sets nick, user and host bits. 63 * 64 * @param string $hostmask Hostmask to parse 65 * @param string $nick Container for the nick 66 * @param string $user Container for the username 67 * @param string $host Container for the hostname 68 * @return void 69 */ 70 70 public function parseHostmask($hostmask, &$nick, &$user, &$host) 71 71 { 72 72 if (preg_match('/^([^!@]+)!([^@]+)@(.*)$/', $hostmask, $match) > 0) { 73 list (, $nick, $user, $host) = array_pad($match, 4, null);73 list(, $nick, $user, $host) = array_pad($match, 4, null); 74 74 } else { 75 75 $host = $hostmask; … … 78 78 79 79 /** 80 * Converts a delimited string of hostmasks into a regular expression81 * that will match any hostmask in the original string.82 *83 * @param string $list Delimited string of hostmasks84 * @return string Regular expression85 */80 * Converts a delimited string of hostmasks into a regular expression 81 * that will match any hostmask in the original string. 82 * 83 * @param string $list Delimited string of hostmasks 84 * @return string Regular expression 85 */ 86 86 public function hostmasksToRegex($list) 87 87 { 88 88 $patterns = array(); 89 89 90 foreach (preg_split('#[\s\r\n,]+#', $list) as $hostmask) {90 foreach(preg_split('#[\s\r\n,]+#', $list) as $hostmask) { 91 91 // Find out which chars are present in the config mask and exclude them from the regex match 92 92 $excluded = ''; 93 if (strpos($hostmask, '!') !==false) {94 $excluded .= '!';93 if (strpos($hostmask, '!') !== false) { 94 $excluded.= '!'; 95 95 } 96 if (strpos($hostmask, '@') !==false) {97 $excluded .= '@';96 if (strpos($hostmask, '@') !== false) { 97 $excluded.= '@'; 98 98 } 99 99 100 100 // Escape regex meta characters 101 101 $hostmask = str_replace( 102 array('\\', '^', '$', '.', '[', ']', '|', '(', ')', '?', '+', '{', '}'),103 array('\\\\', '\\^', '\\$', '\\.', '\\[', '\\]', '\\|', '\\(', '\\)', '\\?', '\\+', '\\{', '\\}'),104 $hostmask102 array('\\', '^', '$', '.', '[', ']', '|', '(', ')', '?', '+', '{', '}'), 103 array('\\\\', '\\^', '\\$', '\\.', '\\[', '\\]', '\\|', '\\(', '\\)', '\\?', '\\+', '\\{', '\\}'), 104 $hostmask 105 105 ); 106 106 107 107 // Replace * so that they match correctly in a regex 108 $patterns[] = str_replace('*', ($excluded === '' ? '.*' : '[^' .$excluded.']*'), $hostmask);108 $patterns[] = str_replace('*', ($excluded === '' ? '.*' : '[^' . $excluded . ']*'), $hostmask); 109 109 } 110 110 … … 113 113 114 114 /** 115 * Sends a debugging message to stdout if the debug configuration setting116 * is enabled.117 *118 * @param string $message Debugging message119 * @return void120 */115 * Sends a debugging message to stdout if the debug configuration setting 116 * is enabled. 117 * 118 * @param string $message Debugging message 119 * @return void 120 */ 121 121 public function debug($message) 122 122 { … … 131 131 132 132 /** 133 * Adds a set of callbacks for events received from the server.134 *135 * @param Phergie_Plugin_Abstract_Base $plugin136 */133 * Adds a set of callbacks for events received from the server. 134 * 135 * @param Phergie_Plugin_Abstract_Base $plugin 136 */ 137 137 public function addPlugin(Phergie_Plugin_Abstract_Base $plugin) 138 138 { 139 $this->plugins[strtolower($plugin->getName()) ] = $plugin;140 } 141 142 /** 143 * Returns all the plugins.144 *145 * @return Phergie_Plugin_Abstract_Base146 */139 $this->plugins[strtolower($plugin->getName()) ] = $plugin; 140 } 141 142 /** 143 * Returns all the plugins. 144 * 145 * @return Phergie_Plugin_Abstract_Base 146 */ 147 147 public function getPlugins() 148 148 { … … 151 151 152 152 /** 153 * Returns a list of all the plugins either currently loaded or within the154 * plugin directory.155 *156 * @param $plugin $dirList If true, scan the Plugin directory for the list157 * @return array158 */153 * Returns a list of all the plugins either currently loaded or within the 154 * plugin directory. 155 * 156 * @param $plugin $dirList If true, scan the Plugin directory for the list 157 * @return array 158 */ 159 159 public function getPluginList($dirList = false, $preserveExt = false) 160 160 { … … 165 165 $plugins = array(); 166 166 167 foreach ($iterator as $filename) {167 foreach($iterator as $filename) { 168 168 if ($iterator->isFile() && pathinfo($filename, PATHINFO_EXTENSION) == 'php') { 169 $plugins[] = ($preserveExt ? (string) $filename : basename($filename, '.php'));169 $plugins[] = ($preserveExt ? (string)$filename : basename($filename, '.php')); 170 170 } 171 171 } … … 177 177 178 178 /** 179 * Returns a plugin instance.180 *181 * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix)182 * @return Phergie_Plugin_Abstract_Base183 */179 * Returns a plugin instance. 180 * 181 * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix) 182 * @return Phergie_Plugin_Abstract_Base 183 */ 184 184 public function getPlugin($plugin) 185 185 { 186 186 $plugin = strtolower($plugin); 187 if (isset($this->plugins[$plugin])) 187 if (isset($this->plugins[$plugin])) { 188 188 return $this->plugins[$plugin]; 189 } 189 190 return false; 190 191 } 191 192 192 193 /** 193 * Executes a continuous loop in which the client listens for events from194 * the server and processes them until the connection is terminated.195 *196 * @return void197 */194 * Executes a continuous loop in which the client listens for events from 195 * the server and processes them until the connection is terminated. 196 * 197 * @return void 198 */ 198 199 public abstract function run(); 199 200 200 201 /** 201 * Terminates the connection with the server.202 *203 * @param string $reason Reason for connection termination (optional)204 * @param bool $reconnect if true, the bot will reconnect to the server205 * @return void206 */202 * Terminates the connection with the server. 203 * 204 * @param string $reason Reason for connection termination (optional) 205 * @param bool $reconnect if true, the bot will reconnect to the server 206 * @return void 207 */ 207 208 public abstract function doQuit($reason = null, $reconnect = false); 208 209 209 210 /** 210 * Joins a channel.211 *212 * @param string $channel Name of the channel to join213 * @param string $keys Channel key if needed (optional)214 * @return void215 */211 * Joins a channel. 212 * 213 * @param string $channel Name of the channel to join 214 * @param string $keys Channel key if needed (optional) 215 * @return void 216 */ 216 217 public abstract function doJoin($channel, $key = null); 217 218 218 219 /** 219 * Leaves a channel.220 *221 * @param string $channel Name of the channel to leave222 * @return void223 */220 * Leaves a channel. 221 * 222 * @param string $channel Name of the channel to leave 223 * @return void 224 */ 224 225 public abstract function doPart($channel); 225 226 226 227 /** 227 * Invites a user to an invite-only channel.228 *229 * @param string $nick Nick of the user to invite230 * @param string $channel Name of the channel231 * @return void232 */228 * Invites a user to an invite-only channel. 229 * 230 * @param string $nick Nick of the user to invite 231 * @param string $channel Name of the channel 232 * @return void 233 */ 233 234 public abstract function doInvite($nick, $channel); 234 235 235 236 /** 236 * Obtains a list of nicks of usrs in currently joined channels.237 *238 * @param string $channels Comma-delimited list of one or more channels239 * @return void240 */237 * Obtains a list of nicks of usrs in currently joined channels. 238 * 239 * @param string $channels Comma-delimited list of one or more channels 240 * @return void 241 */ 241 242 public abstract function doNames($channels); 242 243 243 244 /** 244 * Obtains a list of channel names and topics.245 *246 * @param string $channels Comma-delimited list of one or more channels247 * to which the response should be restricted248 * (optional)249 * @return void250 */245 * Obtains a list of channel names and topics. 246 * 247 * @param string $channels Comma-delimited list of one or more channels 248 * to which the response should be restricted 249 * (optional) 250 * @return void 251 */ 251 252 public abstract function doList($channels = null); 252 253 253 254 /** 254 * Retrieves or changes a channel topic.255 *256 * @param string $channel Name of the channel257 * @param string $topic New topic to assign (optional)258 * @return void259 */255 * Retrieves or changes a channel topic. 256 * 257 * @param string $channel Name of the channel 258 * @param string $topic New topic to assign (optional) 259 * @return void 260 */ 260 261 public abstract function doTopic($channel, $topic = null); 261 262 262 263 /** 263 * Retrieves or changes a channel or user mode.264 *265 * @param string $target Channel name or user nick266 * @param string $mode New mode to assign (optional)267 * @return void268 */264 * Retrieves or changes a channel or user mode. 265 * 266 * @param string $target Channel name or user nick 267 * @param string $mode New mode to assign (optional) 268 * @return void 269 */ 269 270 public abstract function doMode($target, $mode = null); 270 271 271 272 /** 272 * Changes the client nick.273 *274 * @param string $nick New nick to assign275 * @return void276 */273 * Changes the client nick. 274 * 275 * @param string $nick New nick to assign 276 * @return void 277 */ 277 278 public abstract function doNick($nick); 278 279 279 280 /** 280 * Retrieves information about a nick.281 *282 * @param string $nick283 * @return void284 */281 * Retrieves information about a nick. 282 * 283 * @param string $nick 284 * @return void 285 */ 285 286 public abstract function doWhois($nick); 286 287 287 288 /** 288 * Sends a message to a nick or channel.289 *290 * @param string $target Channel name or user nick291 * @param string $text Text of the message to send292 * @return void293 */289 * Sends a message to a nick or channel. 290 * 291 * @param string $target Channel name or user nick 292 * @param string $text Text of the message to send 293 * @return void 294 */ 294 295 public abstract function doPrivmsg($target, $text); 295 296 296 297 /** 297 * Sends a notice to a nick or channel.298 *299 * @param string $target Channel name or user nick300 * @param string $text Text of the notice to send301 * @return void302 */298 * Sends a notice to a nick or channel. 299 * 300 * @param string $target Channel name or user nick 301 * @param string $text Text of the notice to send 302 * @return void 303 */ 303 304 public abstract function doNotice($target, $text); 304 305 305 306 /** 306 * Kicks a user from a channel.307 *308 * @param string $nick Nick of the user309 * @param string $channel Channel name310 * @param string $reason Reason for the kick (optional)311 * @return void312 */307 * Kicks a user from a channel. 308 * 309 * @param string $nick Nick of the user 310 * @param string $channel Channel name 311 * @param string $reason Reason for the kick (optional) 312 * @return void 313 */ 313 314 public abstract function doKick($nick, $channel, $reason = null); 314 315 315 316 /** 316 * Responds to a server test of client responsiveness.317 *318 * @param string $daemon Daemon from which the original request originates319 * @return void320 */317 * Responds to a server test of client responsiveness. 318 * 319 * @param string $daemon Daemon from which the original request originates 320 * @return void 321 */ 321 322 public abstract function doPong($daemon); 322 323 323 324 /** 324 * Sends a CTCP ACTION (/me) command to a nick or channel.325 *326 * @param string $target Channel name or user nick327 * @param string $text Text of the action to perform328 * @return void329 */325 * Sends a CTCP ACTION (/me) command to a nick or channel. 326 * 327 * @param string $target Channel name or user nick 328 * @param string $text Text of the action to perform 329 * @return void 330 */ 330 331 public abstract function doAction($target, $text); 331 332 } trunk/Phergie/Driver/Streams.php
r214 r215 1 1 <?php 2 3 2 /** 4 * Provides a socket-based client driver.5 */3 * Provides a socket-based client driver. 4 */ 6 5 class Phergie_Driver_Streams extends Phergie_Driver_Abstract 7 6 { 8 7 /** 9 * Names of commands that can be issued by callbacks ordered by10 * priority of execution11 *12 * @var array13 */8 * Names of commands that can be issued by callbacks ordered by 9 * priority of execution 10 * 11 * @var array 12 */ 14 13 protected $priority = array( 15 14 'raw', … … 41 40 42 41 /** 43 * Names of destructive commands that get queued up last44 *45 * @var array46 */42 * Names of destructive commands that get queued up last 43 * 44 * @var array 45 */ 47 46 protected $destuctive = array( 48 47 'nick', … … 53 52 54 53 /** 55 * Socket handler56 *57 * @var resource58 */54 * Socket handler 55 * 56 * @var resource 57 */ 59 58 protected $socket; 60 59 61 60 /** 62 * Flag to indicate whether or not the callbacks are currently being63 * queued for execution rather than executed outright64 *65 * @var bool66 */61 * Flag to indicate whether or not the callbacks are currently being 62 * queued for execution rather than executed outright 63 * 64 * @var bool 65 */ 67 66 protected $queueing; 68 67 69 68 /** 70 * Associative array mapping command names to queued sets of arguments71 * from commands queued by callbacks72 *73 * @var array74 */69 * Associative array mapping command names to queued sets of arguments 70 * from commands queued by callbacks 71 * 72 * @var array 73 */ 75 74 protected $queue; 76 75 77 76 /** 78 * The time the bot started79 *80 * @var int81 */77 * The time the bot started 78 * 79 * @var int 80 */ 82 81 protected $startTime; 83 82 84 83 /** 85 * Constructor to initialize instance properties.86 */84 * Constructor to initialize instance properties. 85 */ 87 86 public function __construct() 88 87 { … … 93 92 94 93 /** 95 * Returns the start time.96 *97 * @return int98 */94 * Returns the start time. 95 * 96 * @return int 97 */ 99 98 public function getStartTime() 100 99 { … … 103 102 104 103 /** 105 * Executes a continuous loop in which the client listens for events from106 * the server and processes them until the connection is terminated.107 *108 * @return void109 */104 * Executes a continuous loop in which the client listens for events from 105 * the server and processes them until the connection is terminated. 106 * 107 * @return void 108 */ 110 109 public function run() 111 110 { … … 118 117 } 119 118 120 $this->socket = @stream_socket_client( 121 'tcp://' . $server . ':' . $port, 122 $errno, 123 $errstr 124 ); 125 119 $this->socket = @stream_socket_client('tcp://' . $server . ':' . $port, $errno, $errstr); 126 120 if (!$this->socket) { 127 121 $this->debug(rtrim('Unable to connect to server: socket error ' . $errno . ' ' . $errstr)); … … 165 159 166 160 // Run the onConnect handler since we successfully connected to the server 167 foreach ($this->plugins as $plugin) {161 foreach($this->plugins as $plugin) { 168 162 $plugin->onConnect(); 169 163 } 170 164 171 while (true) {165 while (true) { 172 166 $this->queue = array(); 173 167 $this->queueing = true; 174 168 175 169 // Clear the old event handler for every plugin 176 foreach ($this->plugins as $plugin) {170 foreach($this->plugins as $plugin) { 177 171 $plugin->setEvent(NULL); 178 172 }