Assembla home | Assembla project page
 

Changeset 214

Show
Ignore:
Timestamp:
04/05/08 07:30:06 (8 months ago)
Author:
Slynderdale
Message:

Added temporary real time support for the do methods. By default all messages get sent in real time except for the destructive ones listed in $destructive in Streams.php. These are nick, kill, part and quit. Also added a toggle to all the do methods that allow them to switch to using the queue when needed and also to make the destructive commands work in real time.

This should make the bot appear more responsive while keeping things from being messed up by calling destructive methods. This is only a temporary addon till a better event handler is made.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Phergie/Driver/Streams.php

    r211 r214  
    3232        'whowas', 
    3333        'mode', 
     34        'privmsg', 
    3435        'nick', 
    35         'privmsg', 
    3636        'topic', 
    3737        'invite', 
    3838        'kill', 
    3939        'part' 
     40    ); 
     41 
     42    /** 
     43    * Names of destructive commands that get queued up last 
     44    * 
     45    * @var array 
     46    */ 
     47    protected $destuctive = array( 
     48        'nick', 
     49        'kill', 
     50        'part', 
     51        'quit' 
    4052    ); 
    4153 
     
    356368    *                         (optional) 
    357369    */ 
    358     public function send($command, array $arguments = array()
     370    public function send($command, array $arguments = array(), $priority = false
    359371    { 
    360372        $command = strtolower($command); 
    361         if ($this->queueing) { 
     373        if ($this->queueing && (in_array($command, $this->destuctive) xor $priority)) { 
    362374            if (!isset($this->queue[$command])) { 
    363375                $this->queue[$command] = array(); 
     
    388400    * @param bool $reconnect if true, the bot will reconnect to the server 
    389401    */ 
    390     public function doQuit($reason = null, $reconnect = false
     402    public function doQuit($reason = null, $reconnect = false, $priority = false
    391403    { 
    392404        if ($this->queueing) { 
    393             $this->send(Phergie_Event_Request::TYPE_QUIT, array($reason, $reconnect)); 
     405            $this->send(Phergie_Event_Request::TYPE_QUIT, array($reason, $reconnect), $priority); 
    394406        } else { 
    395             $this->send(Phergie_Event_Request::TYPE_QUIT, array($reason)); 
     407            $this->send(Phergie_Event_Request::TYPE_QUIT, array($reason), $priority); 
    396408        } 
    397409    } 
     
    403415    * @param string $keys Channel key if needed (optional) 
    404416    */ 
    405     public function doJoin($channel, $key = null
     417    public function doJoin($channel, $key = null, $priority = false
    406418    { 
    407419        $arguments = array($channel); 
     
    411423        } 
    412424 
    413         $this->send(Phergie_Event_Request::TYPE_JOIN, $arguments); 
     425        $this->send(Phergie_Event_Request::TYPE_JOIN, $arguments, $priority); 
    414426    } 
    415427 
     
    419431    * @param string $channel Name of the channel to leave 
    420432    */ 
    421     public function doPart($channel, $reason = null
    422     { 
    423         $this->send(Phergie_Event_Request::TYPE_PART, array($channel, $reason)); 
     433    public function doPart($channel, $reason = null, $priority = false
     434    { 
     435        $this->send(Phergie_Event_Request::TYPE_PART, array($channel, $reason), $priority); 
    424436    } 
    425437 
     
    430442    * @param string $channel Name of the channel 
    431443    */ 
    432     public function doInvite($nick, $channel
    433     { 
    434         $this->send(Phergie_Event_Request::TYPE_INVITE, array($nick, $channel)); 
     444    public function doInvite($nick, $channel, $priority = false
     445    { 
     446        $this->send(Phergie_Event_Request::TYPE_INVITE, array($nick, $channel), $priority); 
    435447    } 
    436448 
     
    440452    * @param string $channels Comma-delimited list of one or more channels 
    441453    */ 
    442     public function doNames($channels
    443     { 
    444         $this->send(Phergie_Event_Request::TYPE_NAMES, array($channels)); 
     454    public function doNames($channels, $priority = false
     455    { 
     456        $this->send(Phergie_Event_Request::TYPE_NAMES, array($channels), $priority); 
    445457    } 
    446458 
     
    452464    *                         (optional) 
    453465    */ 
    454     public function doList($channels = null
     466    public function doList($channels = null, $priority = false
    455467    { 
    456468        $arguments = array(); 
     
    460472        } 
    461473 
    462         $this->send(Phergie_Event_Request::TYPE_LIST, $arguments); 
     474        $this->send(Phergie_Event_Request::TYPE_LIST, $arguments, $priority); 
    463475    } 
    464476 
     
    469481    * @param string $topic New topic to assign (optional) 
    470482    */ 
    471     public function doTopic($channel, $topic = null
     483    public function doTopic($channel, $topic = null, $priority = false
    472484    { 
    473485        $arguments = array($channel); 
     
    477489        } 
    478490 
    479         $this->send(Phergie_Event_Request::TYPE_TOPIC, $arguments); 
     491        $this->send(Phergie_Event_Request::TYPE_TOPIC, $arguments, $priority); 
    480492    } 
    481493 
     
    486498    * @param string $mode New mode to assign (optional) 
    487499    */ 
    488     public function doMode($target, $mode = null
     500    public function doMode($target, $mode = null, $priority = false
    489501    { 
    490502        $arguments = array($target); 
     
    494506        } 
    495507 
    496         $this->send(Phergie_Event_Request::TYPE_MODE, $arguments); 
     508        $this->send(Phergie_Event_Request::TYPE_MODE, $arguments, $priority); 
    497509    } 
    498510 
     
    502514    * @param string $nick New nick to assign 
    503515    */ 
    504     public function doNick($nick
    505     { 
    506         $this->send(Phergie_Event_Request::TYPE_NICK, array($nick)); 
     516    public function doNick($nick, $priority = false
     517    { 
     518        $this->send(Phergie_Event_Request::TYPE_NICK, array($nick), $priority); 
    507519    } 
    508520 
     
    512524    * @param string $nick 
    513525    */ 
    514     public function doWhois($nick
    515     { 
    516         $this->send(Phergie_Event_Request::TYPE_WHOIS, array($nick)); 
     526    public function doWhois($nick, $priority = false
     527    { 
     528        $this->send(Phergie_Event_Request::TYPE_WHOIS, array($nick), $priority); 
    517529    } 
    518530 
     
    523535    * @param string $text Text of the message to send 
    524536    */ 
    525     public function doPrivmsg($target, $text
    526     { 
    527         $this->send(Phergie_Event_Request::TYPE_PRIVMSG, array($target, $text)); 
     537    public function doPrivmsg($target, $text, $priority = false
     538    { 
     539        $this->send(Phergie_Event_Request::TYPE_PRIVMSG, array($target, $text), $priority); 
    528540    } 
    529541 
     
    534546    * @param string $text Text of the notice to send 
    535547    */ 
    536     public function doNotice($target, $text
    537     { 
    538         $this->send(Phergie_Event_Request::TYPE_NOTICE, array($target, $text)); 
     548    public function doNotice($target, $text, $priority = false
     549    { 
     550        $this->send(Phergie_Event_Request::TYPE_NOTICE, array($target, $text), $priority); 
    539551    } 
    540552 
     
    546558    * @param string $reason Reason for the kick (optional) 
    547559    */ 
    548     public function doKick($nick, $channel, $reason = null
     560    public function doKick($nick, $channel, $reason = null, $priority = false
    549561    { 
    550562        $arguments = array($nick, $channel); 
     
    554566        } 
    555567 
    556         $this->send(Phergie_Event_Request::TYPE_KICK, $arguments); 
     568        $this->send(Phergie_Event_Request::TYPE_KICK, $arguments, $priority); 
    557569    } 
    558570 
     
    562574    * @param string $daemon Daemon from which the original request originates 
    563575    */ 
    564     public function doPong($daemon
    565     { 
    566         $this->send(Phergie_Event_Request::TYPE_PONG, array($daemon)); 
     576    public function doPong($daemon, $priority = false
     577    { 
     578        $this->send(Phergie_Event_Request::TYPE_PONG, array($daemon), $priority); 
    567579    } 
    568580 
     
    575587    *                         (optional) 
    576588    */ 
    577     public function doCtcp($target, $command, $arguments = ''
     589    public function doCtcp($target, $command, $arguments = '', $priority = false
    578590    { 
    579591        if (is_array($arguments)) { 
     
    589601    * @param string $text Text of the action to perform 
    590602    */ 
    591     public function doAction($target, $text
    592     { 
    593         $this->doCtcp($target, Phergie_Event_Request::TYPE_ACTION, array($text)); 
     603    public function doAction($target, $text, $priority = false
     604    { 
     605        $this->doCtcp($target, Phergie_Event_Request::TYPE_ACTION, array($text), $priority); 
    594606    } 
    595607 
     
    600612    * @param string $hash The ping hash to use in the handshake 
    601613    */ 
    602     public function doPingReply($target, $hash
    603     { 
    604         $this->doCtcpReply($target, 'ping', $hash); 
     614    public function doPingReply($target, $hash, $priority = false
     615    { 
     616        $this->doCtcpReply($target, 'ping', $hash, $priority); 
    605617    } 
    606618 
     
    611623    * @param string $version The version to send 
    612624    */ 
    613     public function doVersionReply($target, $version = ''
     625    public function doVersionReply($target, $version = '', $priority = false
    614626    { 
    615627        $version = trim($version); 
     
    617629            $version = 'Phergie '.PHERGIE_VERSION.' - An IRC bot written in PHP (http://www.phergie.com)'; 
    618630        } 
    619         $this->doCtcpReply($target, 'version', $version); 
     631        $this->doCtcpReply($target, 'version', $version, $priority); 
    620632    } 
    621633 
     
    626638    * @param string $time The time to send 
    627639    */ 
    628     public function doTimeReply($target, $time = ''
     640    public function doTimeReply($target, $time = '', $priority = false
    629641    { 
    630642        $time = trim($time); 
     
    633645            $time = date('D M d H:i:s o', $time); 
    634646        } 
    635         $this->doCtcpReply($target, 'time', $time); 
     647        $this->doCtcpReply($target, 'time', $time, $priority); 
    636648    } 
    637649 
     
    642654    * @param string $reply The CTCP reply to send 
    643655    */ 
    644     public function doCtcpReply($target, $command, $reply = ''
     656    public function doCtcpReply($target, $command, $reply = '', $priority = false
    645657    { 
    646658        $command = trim($command); 
    647659        if (empty($command)) 
    648660            return; 
    649         $this->send(Phergie_Event_Request::TYPE_NOTICE, array($target, chr(1).trim(strtoupper($command).' '.$reply).chr(1))); 
     661        $this->send(Phergie_Event_Request::TYPE_NOTICE, array($target, chr(1).trim(strtoupper($command).' '.$reply).chr(1)), $priority); 
    650662    } 
    651663 
     
    655667    * @param string $message The message to send to the server 
    656668    */ 
    657     public function doRaw($message
    658     { 
    659         $this->send(Phergie_Event_Request::TYPE_RAW, array($message)); 
     669    public function doRaw($message, $priority = false
     670    { 
     671        $this->send(Phergie_Event_Request::TYPE_RAW, array($message), $priority); 
    660672    } 
    661673} 
  • trunk/Phergie/Plugin/Altnick.php

    r200 r214  
    4242            $altnick = $this->getPluginIni('altnick' . $this->index); 
    4343            if ($altnick) { 
    44                 $this->doNick($altnick); 
     44                $this->doNick($altnick, true); 
    4545                $this->setIni('nick', $altnick); 
    4646            } else { 
  • trunk/Phergie/Plugin/Nickserv.php

    r200 r214  
    117117                $this->doPrivmsg( 
    118118                    $this->botNick, 
    119                     'GHOST ' . $this->nick . ' ' . $password 
     119                    'GHOST ' . $this->nick . ' ' . $password, 
     120                    true 
    120121                ); 
    121122            } 
     
    137138                $this->doPrivmsg( 
    138139                    $this->botNick, 
    139                     'GHOST ' . $this->nick . ' ' . $password 
     140                    'GHOST ' . $this->nick . ' ' . $password, 
     141                    true 
    140142                ); 
    141143            }