Changeset 102
- Timestamp:
- 03/01/08 23:10:48 (5 years ago)
- Location:
- trunk/Phergie
- Files:
-
- 2 modified
-
Bot.php (modified) (1 diff)
-
phergie.ini (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Phergie/Bot.php
r99 r102 72 72 73 73 /** 74 * Obtain and validate the contents of the configuration file 75 */ 76 $required = array('server', 'username', 'nick'); 77 $config = @parse_ini_file(PHERGIE_DIR . 'Phergie' . DIRECTORY_SEPARATOR . $ini); 74 * Start a runtime loop, if the bot disconnects and reconnects it will reload 75 * all settings from the ini file, allowing you to modify it without really shutting 76 * it down 77 */ 78 while (true) { 78 79 79 if (count($config) == 0) { 80 echo 'Configuration file inaccessible or empty: ' . $ini . "\n"; 81 return; 82 } 80 /** 81 * Obtain and validate the contents of the configuration file 82 */ 83 $required = array('server', 'username', 'nick'); 84 $config = @parse_ini_file(PHERGIE_DIR . 'Phergie' . DIRECTORY_SEPARATOR . $ini); 83 85 84 foreach ($required as $setting) { 85 if (!isset($config[$setting]) || empty($config[$setting])) { 86 echo 'Required configuration setting missing: ' . $setting . "\n"; 87 return; 88 } 89 } 86 if (count($config) == 0) { 87 echo 'Configuration file inaccessible or empty: ' . $ini . "\n"; 88 return; 89 } 90 90 91 unset ($required); 91 foreach ($required as $setting) { 92 if (!isset($config[$setting]) || empty($config[$setting])) { 93 echo 'Required configuration setting missing: ' . $setting . "\n"; 94 return; 95 } 96 } 92 97 93 /** 94 * Configure the client 95 */ 96 if (isset($config['driver'])) { 97 $driver = ucfirst(strtolower($config['driver'])); 98 } else { 99 $driver = 'Streams'; 100 } 101 require_once 'Phergie/Driver/' . $driver . '.php'; 102 $class = 'Phergie_Driver_' . $driver; 103 $client = new $class(); 98 unset ($required); 104 99 105 foreach ($config as $setting => $value) { 106 $client->setIni($setting, $value); 107 } 100 /** 101 * Configure the client 102 */ 103 if (isset($config['driver'])) { 104 $driver = ucfirst(strtolower($config['driver'])); 105 } else { 106 $driver = 'Streams'; 107 } 108 require_once 'Phergie/Driver/' . $driver . '.php'; 109 $class = 'Phergie_Driver_' . $driver; 110 $client = new $class(); 108 111 109 unset ($setting, $value, $driver, $class); 112 foreach ($config as $setting => $value) { 113 $client->setIni($setting, $value); 114 } 110 115 111 /** 112 * Determine which plugins should be loaded 113 */ 114 $all = true; 115 $include = array(); 116 if (isset($config['plugins']) 117 && preg_match('/(all|none)(?: except (.+))?/ADi', $config['plugins'], $match)) { 118 $all = $match[1] != 'none'; 119 if (isset($match[2])) { 120 $include = array_map('strtolower', preg_split('/[, ]+/', $match[2])); 121 } 122 } 116 unset ($setting, $value, $driver, $class); 123 117 124 unset ($config); 118 /** 119 * Determine which plugins should be loaded 120 */ 121 $all = true; 122 $include = array(); 123 if (isset($config['plugins']) 124 && preg_match('/(all|none)(?: except (.+))?/ADi', $config['plugins'], $match)) { 125 $all = $match[1] != 'none'; 126 if (isset($match[2])) { 127 $include = array_map('strtolower', preg_split('/[, ]+/', $match[2])); 128 } 129 } 125 130 126 /** 127 * Set up plugins 128 */ 129 $iterator = new DirectoryIterator(PHERGIE_DIR . '/Phergie/Plugin'); 130 $plugins = array(); 131 foreach ($iterator as $entry) { 132 if ($iterator->isFile()) { 133 $name = substr($entry, 0, -4); 134 if ($all xor in_array(strtolower($name), $include)) { 135 $plugins[$name] = true; 136 } else { 137 $plugins[$name] = false; 138 } 139 } 140 } 131 unset ($config); 141 132 142 ksort($plugins); 133 /** 134 * Set up plugins 135 */ 136 $iterator = new DirectoryIterator(PHERGIE_DIR . '/Phergie/Plugin'); 137 $plugins = array(); 138 foreach ($iterator as $entry) { 139 if ($iterator->isFile()) { 140 $name = substr($entry, 0, -4); 141 if ($all xor in_array(strtolower($name), $include)) { 142 $plugins[$name] = true; 143 } else { 144 $plugins[$name] = false; 145 } 146 } 147 } 143 148 144 unset ($iterator, $entry, $name, $all, $include);149 ksort($plugins); 145 150 146 foreach ($plugins as $plugin=>$enabled) { 147 require_once 'Phergie/Plugin/' . $plugin . '.php'; 148 $class = 'Phergie_Plugin_' . $plugin; 149 if (call_user_func(array($class, 'checkDependencies'), $plugins)) { 150 $instance = new $class($client); 151 $instance->enabled = $enabled; 152 $client->addPlugin($instance); 153 $client->debug('Loaded ' . $plugin . ($enabled ? '':' [Disabled]')); 154 } else { 155 $client->debug('Unable to load ' . $plugin); 156 } 157 } 151 unset ($iterator, $entry, $name, $all, $include); 158 152 159 unset ($plugins, $plugin, $class, $instance); 153 foreach ($plugins as $plugin=>$enabled) { 154 require_once 'Phergie/Plugin/' . $plugin . '.php'; 155 $class = 'Phergie_Plugin_' . $plugin; 156 if (call_user_func(array($class, 'checkDependencies'), $plugins)) { 157 $instance = new $class($client); 158 $instance->enabled = $enabled; 159 $client->addPlugin($instance); 160 $client->debug('Loaded ' . $plugin . ($enabled ? '':' [Disabled]')); 161 } else { 162 $client->debug('Unable to load ' . $plugin); 163 } 164 } 160 165 161 /** 162 * Execute the event handling loop for the client 163 */ 164 while(true) { 166 unset ($plugins, $plugin, $class, $instance); 167 168 /** 169 * Execute the event handling loop for the client 170 */ 165 171 $state = $client->run(); 166 172 -
trunk/Phergie/phergie.ini
r99 r102 31 31 ; keepalive : 32 32 ; boolean flag indicating whether or not the bot should reconnect when it 33 ; gets disconnected from the server, defaults to false. 33 ; gets disconnected from the server, defaults to false if not set, but 34 ; setting it to true is recommended. 34 35 ; if this is set to true, you should set timeout value to 6 or above. 36 ; if not, timeout would better be set to zero or a high number such as 15. 35 37 keepalive = true 36 38 … … 195 197 196 198 ;----------------------------------------------------------------------------- 197 ; Weather 199 ; Weather 198 200 ;----------------------------------------------------------------------------- 199 201 … … 201 203 ; Partner ID provided by weather.com 202 204 ; see http://www.weather.com/services/xmloap.html for more details 203 weather.partner_id = 205 weather.partner_id = 204 206 205 207 ; weather.license_key 206 208 ; License Key provided by weather.com 207 209 ; see http://www.weather.com/services/xmloap.html for more details 208 weather.license_key = 210 weather.license_key =