Changeset 71
- Timestamp:
- 02/25/08 01:38:31 (9 months ago)
- Files:
-
- trunk/Phergie/Bot.php (modified) (1 diff)
- trunk/Phergie/Driver/Streams.php (modified) (3 diffs)
- trunk/Phergie/Plugin/Abstract/AdminCommand.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Abstract/Base.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Abstract/Cron.php (modified) (1 diff)
- trunk/Phergie/Plugin/Acronym.php (modified) (6 diffs)
- trunk/Phergie/Plugin/Altnick.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Autojoin.php (modified) (1 diff)
- trunk/Phergie/Plugin/FeedTicker.php (modified) (1 diff)
- trunk/Phergie/Plugin/Karma.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Nickserv.php (modified) (5 diffs)
- trunk/Phergie/Plugin/Tld.php (modified) (1 diff)
- trunk/Phergie/Plugin/Url.php (modified) (3 diffs)
- trunk/Phergie/phergie.ini (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Bot.php
r68 r71 51 51 trigger_error('Phergie is intended to be run using the CLI SAPI for PHP', E_USER_ERROR); 52 52 } 53 54 /** 55 * Allow the bot to run indefinitely 56 */ 57 set_time_limit(0); 53 58 54 59 /** trunk/Phergie/Driver/Streams.php
r68 r71 116 116 ); 117 117 118 unset($port); 119 118 120 if (!$this->socket) { 119 121 $this->debug(rtrim('Unable to connect to server: socket error ' . $errno . ' ' . $errstr)); … … 121 123 } 122 124 125 unset($errno, $errstr); 126 123 127 $password = $this->getIni('password'); 124 128 if ($password) { … … 126 130 } 127 131 128 $this->send('USER', array($this->getIni('username'), $server, $server, $this->getIni('realname'))); 132 unset($password); 133 134 $params = array( 135 $this->getIni('username'), 136 $server, 137 $server, 138 $this->getIni('realname') 139 ); 140 141 unset($server); 142 143 $this->send('USER', $params); 129 144 $this->doNick($this->getIni('nick')); 130 145 131 unset($ server, $port, $password, $errno, $errstr);146 unset($params); 132 147 133 148 while(true) { trunk/Phergie/Plugin/Abstract/AdminCommand.php
r63 r71 67 67 68 68 // Set ops values 69 $ini = $this->get Ini('ops');69 $ini = $this->getPluginIni('ops'); 70 70 if ($ini===null) { 71 $ini = $this->getIni(' ops', 'admincommand');71 $ini = $this->getIni('admincommand.ops'); 72 72 } 73 73 if ($ini==='true' || $ini==='1') { … … 78 78 79 79 // Set admins values 80 $ini = $this->get Ini('admins');80 $ini = $this->getPluginIni('admins'); 81 81 if ($ini===null) { 82 $ini = $this->getIni('admin s', 'admincommand');82 $ini = $this->getIni('admincommand.admins'); 83 83 } 84 84 if (!empty ($ini)) { trunk/Phergie/Plugin/Abstract/Base.php
r68 r71 97 97 98 98 /** 99 * Returns the value of a configuration setting for a plugin. 100 * 101 * @param string $setting Name of the setting 102 * @param string $plugin Name of the plugin, defaults to the current 103 * plugin (optional) 104 * @return string 105 */ 106 public function getIni($setting, $plugin = null) 107 { 108 if ($plugin === null) { 109 $plugin = $this->getName(); 110 } 111 $value = $this->client->getIni($plugin . '.' . $setting); 112 if (!$value) { 113 $value = $this->client->getIni($setting); 114 } 115 return $value; 116 } 117 118 /** 119 * Sets the value of a configuration setting for a plugin. 120 * 121 * @param string $setting Name of the setting 122 * @param string $value New value for the setting 123 * @param string $plugin Name of the plugin, defaults to the current 124 * plugin (optional) 125 * @return void 126 */ 127 public function setIni($setting, $value, $plugin = null) 128 { 129 if ($plugin === null) { 130 $plugin = $this->getName(); 131 } 132 $this->client->setIni($plugin . '.' . $setting, $value); 99 * Returns the value of a specified configuration setting. 100 * 101 * @param string $setting Full name of the setting including the plugin 102 * name prefix (ex: pluginname.settingname) 103 * @return mixed 104 */ 105 public function getIni($setting) 106 { 107 return $this->client->getIni($setting); 108 } 109 110 /** 111 * Returns the value of a specified configuration setting for the current 112 * plugin. 113 * 114 * @param string $setting Name of the setting without the plugin name 115 * prefix 116 * @return mixed 117 */ 118 public function getPluginIni($setting) 119 { 120 return $this->client->getIni($this->getName() . '.' . $setting); 121 } 122 123 /** 124 * Sets the value of a specified configuration setting. 125 * 126 * @param string $setting Full name of the setting including the plugin 127 * name prefix (ex: pluginname.settingname) 128 * @param mixed $value New value for the setting 129 * @return void 130 */ 131 public function setIni($setting, $value) 132 { 133 $this->client->setIni($setting, $value); 134 } 135 136 /** 137 * Sets the value of a specified configuration setting for the current 138 * plugin. 139 * 140 * @param string $setting Name of the setting without the plugin name 141 * prefix 142 * @param mixed $value New value for the setting 143 * @return void 144 */ 145 public function setPluginIni($setting, $value) 146 { 147 $this->client->setIni($this->getName() . '.' . $setting, $value); 133 148 } 134 149 … … 164 179 { 165 180 if (strlen($url) > 30) { 166 $tiny = @file_get_contents('http://tinyurl.com/api-create.php?url=' . $url);181 $tiny = @file_get_contents('http://tinyurl.com/api-create.php?url=' . urlencode($url)); 167 182 if (empty($tiny)) { 168 183 $tiny = $url; trunk/Phergie/Plugin/Abstract/Cron.php
r68 r71 53 53 { 54 54 if($this->delay === null) { 55 if ((($time = $this->get Ini('delay')) !== null) || $time = $this->defaultDelay) {55 if ((($time = $this->getPluginIni('delay')) !== null) || $time = $this->defaultDelay) { 56 56 $this->delay = $time; 57 57 } trunk/Phergie/Plugin/Acronym.php
r68 r71 14 14 * The limit configuration setting should be set to the maximum number of 15 15 * potential meanings to return for any single given acronym. 16 * 17 * @todo Add a cache to avoid exceeding the acronymfinder.com daily lookup 18 * limit. Cache should be flushed daily. 16 19 */ 17 20 class Phergie_Plugin_Acronym extends Phergie_Plugin_Abstract_Base … … 23 26 */ 24 27 protected $limit; 28 29 /** 30 * List of acronyms for which responses should not be sent 31 * 32 * @var array 33 */ 34 protected $filter; 25 35 26 36 /** … … 45 55 public function init() 46 56 { 47 $limit = $this->get Ini('limit');57 $limit = $this->getPluginIni('limit'); 48 58 if ($limit < 0 || $limit === null) { 49 59 $this->limit = 5; … … 51 61 $this->limit = (int) $limit; 52 62 } 63 64 $this->filter = array_filter(preg_split('/[ ,]/', $this->getPluginIni('filter')), 'strlen'); 53 65 } 54 66 … … 87 99 $message = $this->event->getArgument(1); 88 100 89 if (!preg_match('/((?:[A-Z]\.?){2,})\?/ ', $message, $acronym)) {101 if (!preg_match('/((?:[A-Z]\.?){2,})\?/AD', $message, $acronym)) { 90 102 return; 91 103 } 92 104 93 105 $acronym = str_replace('.', '', $acronym[1]); 106 107 if (in_array($acronym, $this->filter)) { 108 return; 109 } 94 110 95 111 if (in_array($acronym, array('WHO', 'WHAT', 'WHERE', 'WHEN', 'WHY', 'HOW'))) { … … 100 116 $opts = array('http' => 101 117 array( 118 'timeout' => 5, 102 119 'method' => 'GET', 103 120 'header' => 'Content-type: application/x-www-form-urlencoded', trunk/Phergie/Plugin/Altnick.php
r68 r71 38 38 if ($this->event->getCode() == Phergie_Event_Response::ERR_NICKNAMEINUSE) { 39 39 $this->index++; 40 $altnick = $this->get Ini('altnick' . $this->index);40 $altnick = $this->getPluginIni('altnick' . $this->index); 41 41 if ($altnick) { 42 42 $this->doNick($altnick); 43 $this->setIni('nick', $altnick); 43 44 } else { 44 45 $this->doQuit('All specified nicks are in use'); … … 46 47 } 47 48 } 48 49 /**50 * Changes the in-memory configuration setting for the bot nick if it is51 * successfully changed.52 *53 * @return void54 */55 public function onNick()56 {57 if ($this->event->getSource() == $this->getIni('nick')) {58 $this->setIni('nick', $this->event->getArgument(0));59 }60 }61 49 } trunk/Phergie/Plugin/Autojoin.php
r68 r71 26 26 case Phergie_Event_Response::RPL_ENDOFMOTD: 27 27 case Phergie_Event_Response::ERR_NOMOTD: 28 $channels = $this->get Ini('channels');28 $channels = $this->getPluginIni('channels'); 29 29 if (!empty ($channels)) { 30 30 $this->doJoin(implode(' ', preg_split('#[, ]+#', $channels))); trunk/Phergie/Plugin/FeedTicker.php
r59 r71 70 70 $this->feeds = array(); 71 71 do { 72 $feed = $this->get Ini('feed' . $i);73 $chans = $this->get Ini('chans' . $i);72 $feed = $this->getPluginIni('feed' . $i); 73 $chans = $this->getPluginIni('chans' . $i); 74 74 if (!empty($feed) && !empty($chans)) { 75 75 $this->feeds[] = array($feed, preg_split('#[\s\r\n,]+#', $chans)); 76 76 } 77 77 } while (++$i < 10); 78 if($this->get Ini('format') != null) {79 $this->format = $this->get Ini('format');78 if($this->getPluginIni('format') != null) { 79 $this->format = $this->getPluginIni('format'); 80 80 } 81 81 } trunk/Phergie/Plugin/Karma.php
r68 r71 76 76 ); 77 77 78 $static = $this->get Ini('static');78 $static = $this->getPluginIni('static'); 79 79 if ($static) { 80 80 $this->fixedKarma[strtolower($this->getIni('nick'))] = $static; … … 146 146 // Antithrottling check 147 147 $host = $this->event->getHost(); 148 $limit = $this->get Ini('limit');148 $limit = $this->getPluginIni('limit'); 149 149 if (isset ($this->log[$host][$word]) 150 150 && $limit trunk/Phergie/Plugin/Nickserv.php
r66 r71 4 4 * @see Phergie_Plugin_Abstract_AdminCommand 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/ Command.php';6 require_once 'Phergie/Plugin/Abstract/AdminCommand.php'; 7 7 8 8 /** … … 13 13 * with NickServ for the nick used by the bot. 14 14 */ 15 class Phergie_Plugin_Nickserv extends Phergie_Plugin_Abstract_ Command15 class Phergie_Plugin_Nickserv extends Phergie_Plugin_Abstract_AdminCommand 16 16 { 17 17 /** … … 29 29 public function init() 30 30 { 31 parent::init(); 32 31 33 $this->nick = $this->getIni('nick'); 32 34 } … … 44 46 $message = $this->event->getArgument(1); 45 47 if ($message == 'This nickname is owned by someone else') { 46 $password = $this->get Ini('password');48 $password = $this->getPluginIni('password'); 47 49 if (! empty($password)) { 48 50 $this->doPrivmsg('NickServ', 'IDENTIFY ' . $password); … … 74 76 public function onDoGhostbust() 75 77 { 76 $password = $this->getIni('password'); 78 $password = $this->getPluginIni('password'); 79 $this->debug('password = ' . $password); 77 80 78 if (!empty ($password) && $this->index != -1) {81 if (!empty ($password)) { 79 82 $this->doPrivmsg( 80 83 'NickServ', trunk/Phergie/Plugin/Tld.php
r68 r71 9 9 * Responds to a request for a TLD (formatted as .tld where tld is the TLD to 10 10 * be looked up) with its corresponding description. 11 * 12 * @todo Move TLD lookup table to SQLite database created and populated in 13 * init() when needed. Add caching of lookup results, flush it daily. 11 14 */ 12 15 class Phergie_Plugin_Tld extends Phergie_Plugin_Abstract_Base trunk/Phergie/Plugin/Url.php
r68 r71 38 38 public function init() 39 39 { 40 $format = $this->get Ini('format');40 $format = $this->getPluginIni('format'); 41 41 if ($format) { 42 42 $this->format = $format; … … 59 59 if(array_search($url, $this->lastUrl) !== false) 60 60 return; 61 // @todo if image or something, output content type62 61 // Convert url 63 62 $tinyUrl = $this->tinyUrl($url); … … 66 65 return; 67 66 68 $titleLength = $this->get Ini('title_length');67 $titleLength = $this->getPluginIni('title_length'); 69 68 70 69 $opts = array('http' => 71 70 array( 71 'timeout' => 5, 72 72 'method' => 'GET', 73 73 'header' => 'Content-type: application/x-www-form-urlencoded', trunk/Phergie/phergie.ini
r66 r71 59 59 ; an acronym that should be displayed in a given instance (defaults to 5) 60 60 acronym.limit = 61 62 ; acronym.filter : 63 ; comma- or space-delimited list of acronyms for which meanings should not 64 ; be returned 65 acronym.filter = 61 66 62 67 ;-----------------------------------------------------------------------------