Changeset 71

Show
Ignore:
Timestamp:
02/25/08 01:38:31 (5 years ago)
Author:
tobias382
Message:

* Added support to the Acronym plugin for filtering responses to certain acronyms
* Modified the Acronym plugin to restrict lookups to instances where the acronym takes up the entire post
* Modified the Acronym and Url plugins to add a lookup timeout
* Modified the Nickserv plugin to extend AdminCommand? instead of Command
* Fixed an issue in the tinyUrl method of the base plugin class where lack of URL encoding of the passed URL resulted in truncation of the original URL when computing its TinyURL equivalent
* Modified getIni and setIni methods in and added getPluginIni and setPluginIni to the base plugin case to allow for easier access to both core and plugin-specific settings and modified existing plugins to use the new methods where appropriate

Location:
trunk/Phergie
Files:
14 modified

Legend:

Unmodified
Added
Removed
  • trunk/Phergie/Bot.php

    r68 r71  
    5151    trigger_error('Phergie is intended to be run using the CLI SAPI for PHP', E_USER_ERROR); 
    5252} 
     53 
     54/** 
     55* Allow the bot to run indefinitely 
     56*/ 
     57set_time_limit(0); 
    5358 
    5459/** 
  • trunk/Phergie/Driver/Streams.php

    r68 r71  
    116116        ); 
    117117 
     118        unset($port); 
     119 
    118120        if (!$this->socket) { 
    119121            $this->debug(rtrim('Unable to connect to server: socket error ' . $errno . ' ' . $errstr)); 
     
    121123        } 
    122124 
     125        unset($errno, $errstr); 
     126 
    123127        $password = $this->getIni('password'); 
    124128        if ($password) { 
     
    126130        } 
    127131 
    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); 
    129144        $this->doNick($this->getIni('nick')); 
    130145 
    131         unset($server, $port, $password, $errno, $errstr); 
     146        unset($params); 
    132147 
    133148        while(true) { 
  • trunk/Phergie/Plugin/Abstract/AdminCommand.php

    r63 r71  
    6767 
    6868        // Set ops values 
    69         $ini = $this->getIni('ops'); 
     69        $ini = $this->getPluginIni('ops'); 
    7070        if ($ini===null) { 
    71             $ini = $this->getIni('ops', 'admincommand'); 
     71            $ini = $this->getIni('admincommand.ops'); 
    7272        } 
    7373        if ($ini==='true' || $ini==='1') { 
     
    7878 
    7979        // Set admins values 
    80         $ini = $this->getIni('admins'); 
     80        $ini = $this->getPluginIni('admins'); 
    8181        if ($ini===null) { 
    82             $ini = $this->getIni('admins', 'admincommand'); 
     82            $ini = $this->getIni('admincommand.admins'); 
    8383        } 
    8484        if (!empty ($ini)) { 
  • trunk/Phergie/Plugin/Abstract/Base.php

    r68 r71  
    9797 
    9898    /** 
    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); 
    133148    } 
    134149 
     
    164179    { 
    165180        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)); 
    167182            if (empty($tiny)) { 
    168183                $tiny = $url; 
  • trunk/Phergie/Plugin/Abstract/Cron.php

    r68 r71  
    5353    { 
    5454        if($this->delay === null) { 
    55             if ((($time = $this->getIni('delay')) !== null) || $time = $this->defaultDelay) { 
     55            if ((($time = $this->getPluginIni('delay')) !== null) || $time = $this->defaultDelay) { 
    5656                $this->delay = $time; 
    5757            } 
  • trunk/Phergie/Plugin/Acronym.php

    r68 r71  
    1414* The limit configuration setting should be set to the maximum number of 
    1515* 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. 
    1619*/ 
    1720class Phergie_Plugin_Acronym extends Phergie_Plugin_Abstract_Base 
     
    2326    */ 
    2427    protected $limit; 
     28 
     29    /** 
     30    * List of acronyms for which responses should not be sent 
     31    * 
     32    * @var array 
     33    */ 
     34    protected $filter; 
    2535 
    2636    /** 
     
    4555    public function init() 
    4656    { 
    47         $limit = $this->getIni('limit'); 
     57        $limit = $this->getPluginIni('limit'); 
    4858        if ($limit < 0 || $limit === null) { 
    4959            $this->limit = 5; 
     
    5161            $this->limit = (int) $limit; 
    5262        } 
     63 
     64        $this->filter = array_filter(preg_split('/[ ,]/', $this->getPluginIni('filter')), 'strlen'); 
    5365    } 
    5466 
     
    8799        $message = $this->event->getArgument(1); 
    88100 
    89         if (!preg_match('/((?:[A-Z]\.?){2,})\?/', $message, $acronym)) { 
     101        if (!preg_match('/((?:[A-Z]\.?){2,})\?/AD', $message, $acronym)) { 
    90102            return; 
    91103        } 
    92104 
    93105        $acronym = str_replace('.', '', $acronym[1]); 
     106 
     107        if (in_array($acronym, $this->filter)) { 
     108            return; 
     109        } 
    94110 
    95111        if (in_array($acronym, array('WHO', 'WHAT', 'WHERE', 'WHEN', 'WHY', 'HOW'))) { 
     
    100116        $opts = array('http' => 
    101117            array( 
     118                'timeout' => 5, 
    102119                'method' => 'GET', 
    103120                'header' => 'Content-type: application/x-www-form-urlencoded', 
  • trunk/Phergie/Plugin/Altnick.php

    r68 r71  
    3838        if ($this->event->getCode() == Phergie_Event_Response::ERR_NICKNAMEINUSE) { 
    3939            $this->index++; 
    40             $altnick = $this->getIni('altnick' . $this->index); 
     40            $altnick = $this->getPluginIni('altnick' . $this->index); 
    4141            if ($altnick) { 
    4242                $this->doNick($altnick); 
     43                $this->setIni('nick', $altnick); 
    4344            } else { 
    4445                $this->doQuit('All specified nicks are in use'); 
     
    4647        } 
    4748    } 
    48  
    49     /** 
    50     * Changes the in-memory configuration setting for the bot nick if it is 
    51     * successfully changed. 
    52     * 
    53     * @return void 
    54     */ 
    55     public function onNick() 
    56     { 
    57         if ($this->event->getSource() == $this->getIni('nick')) { 
    58             $this->setIni('nick', $this->event->getArgument(0)); 
    59         } 
    60     } 
    6149} 
  • trunk/Phergie/Plugin/Autojoin.php

    r68 r71  
    2626            case Phergie_Event_Response::RPL_ENDOFMOTD: 
    2727            case Phergie_Event_Response::ERR_NOMOTD: 
    28                 $channels = $this->getIni('channels'); 
     28                $channels = $this->getPluginIni('channels'); 
    2929                if (!empty ($channels)) { 
    3030                    $this->doJoin(implode(' ', preg_split('#[, ]+#', $channels))); 
  • trunk/Phergie/Plugin/FeedTicker.php

    r59 r71  
    7070        $this->feeds = array(); 
    7171        do { 
    72             $feed = $this->getIni('feed' . $i); 
    73             $chans = $this->getIni('chans' . $i); 
     72            $feed = $this->getPluginIni('feed' . $i); 
     73            $chans = $this->getPluginIni('chans' . $i); 
    7474            if (!empty($feed) && !empty($chans)) { 
    7575                $this->feeds[] = array($feed, preg_split('#[\s\r\n,]+#', $chans)); 
    7676            } 
    7777        } while (++$i < 10); 
    78         if($this->getIni('format') != null) { 
    79             $this->format = $this->getIni('format'); 
     78        if($this->getPluginIni('format') != null) { 
     79            $this->format = $this->getPluginIni('format'); 
    8080        } 
    8181    } 
  • trunk/Phergie/Plugin/Karma.php

    r68 r71  
    7676        ); 
    7777 
    78         $static = $this->getIni('static'); 
     78        $static = $this->getPluginIni('static'); 
    7979        if ($static) { 
    8080            $this->fixedKarma[strtolower($this->getIni('nick'))] = $static; 
     
    146146            // Antithrottling check 
    147147            $host = $this->event->getHost(); 
    148             $limit = $this->getIni('limit'); 
     148            $limit = $this->getPluginIni('limit'); 
    149149            if (isset ($this->log[$host][$word]) 
    150150                && $limit 
  • trunk/Phergie/Plugin/Nickserv.php

    r66 r71  
    44* @see Phergie_Plugin_Abstract_AdminCommand 
    55*/ 
    6 require_once 'Phergie/Plugin/Abstract/Command.php'; 
     6require_once 'Phergie/Plugin/Abstract/AdminCommand.php'; 
    77 
    88/** 
     
    1313* with NickServ for the nick used by the bot. 
    1414*/ 
    15 class Phergie_Plugin_Nickserv extends Phergie_Plugin_Abstract_Command 
     15class Phergie_Plugin_Nickserv extends Phergie_Plugin_Abstract_AdminCommand 
    1616{ 
    1717    /** 
     
    2929    public function init() 
    3030    { 
     31        parent::init(); 
     32 
    3133        $this->nick = $this->getIni('nick'); 
    3234    } 
     
    4446            $message = $this->event->getArgument(1); 
    4547            if ($message == 'This nickname is owned by someone else') { 
    46                 $password = $this->getIni('password'); 
     48                $password = $this->getPluginIni('password'); 
    4749                if (! empty($password)) { 
    4850                    $this->doPrivmsg('NickServ', 'IDENTIFY ' . $password); 
     
    7476    public function onDoGhostbust() 
    7577    { 
    76         $password = $this->getIni('password'); 
     78        $password = $this->getPluginIni('password'); 
     79        $this->debug('password = ' . $password); 
    7780 
    78         if (!empty ($password) && $this->index != -1) { 
     81        if (!empty ($password)) { 
    7982            $this->doPrivmsg( 
    8083                'NickServ', 
  • trunk/Phergie/Plugin/Tld.php

    r68 r71  
    99* Responds to a request for a TLD (formatted as .tld where tld is the TLD to 
    1010* 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. 
    1114*/ 
    1215class Phergie_Plugin_Tld extends Phergie_Plugin_Abstract_Base 
  • trunk/Phergie/Plugin/Url.php

    r68 r71  
    3838    public function init() 
    3939    { 
    40         $format = $this->getIni('format'); 
     40        $format = $this->getPluginIni('format'); 
    4141        if ($format) { 
    4242            $this->format = $format; 
     
    5959                        if(array_search($url, $this->lastUrl) !== false) 
    6060                                return; 
    61             // @todo if image or something, output content type 
    6261            // Convert url 
    6362            $tinyUrl = $this->tinyUrl($url); 
     
    6665                                return; 
    6766 
    68             $titleLength = $this->getIni('title_length'); 
     67            $titleLength = $this->getPluginIni('title_length'); 
    6968 
    7069            $opts = array('http' => 
    7170                array( 
     71                    'timeout' => 5, 
    7272                    'method' => 'GET', 
    7373                    'header' => 'Content-type: application/x-www-form-urlencoded', 
  • trunk/Phergie/phergie.ini

    r66 r71  
    5959;    an acronym that should be displayed in a given instance (defaults to 5) 
    6060acronym.limit = 
     61 
     62; acronym.filter : 
     63;    comma- or space-delimited list of acronyms for which meanings should not 
     64;    be returned 
     65acronym.filter = 
    6166 
    6267;-----------------------------------------------------------------------------