Changeset 308

Show
Ignore:
Timestamp:
12/13/08 20:37:21 (5 years ago)
Author:
sean@…
Message:

changes 'too many messages in public' behaviour. fixes #61

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Phergie/Plugin/Remind.php

    r289 r308  
    99class Phergie_Plugin_Remind extends Phergie_Plugin_Abstract_Command 
    1010{ 
     11    /** 
     12     * Number of reminders to show in public 
     13     */ 
     14    const PUBLIC_REMINDERS = 3; 
     15     
    1116    /** 
    1217     * Indicates that a local directory is required for this plugin 
     
    269274         
    270275        // fetch and deliver messages 
    271         foreach ($this->fetchMessages($channel, $nick) as $msg) { 
     276        $reminders = $this->fetchMessages($channel, $nick); 
     277        if (count($reminders) > self::PUBLIC_REMINDERS) { 
     278            $msgs = array_slice($reminders, 0, self::PUBLIC_REMINDERS); 
     279            $privmsgs = array_slice($reminders, self::PUBLIC_REMINDERS); 
     280        } else { 
     281            $msgs = $reminders; 
     282            $privmsgs = false; 
     283        } 
     284        foreach ($msgs as $msg) { 
    272285            $this->doPrivmsg( 
    273286                $channel, 
     
    277290            $this->deleteMessage($msg['rowid'], $channel, $nick); 
    278291        } 
     292        if ($privmsgs) { 
     293            foreach ($privmsgs as $msg) { 
     294                $this->doPrivmsg( 
     295                    $nick, 
     296                    "{$nick}: (from {$msg['sender']}, {$msg['time']}) " . 
     297                        $msg['message'] 
     298                ); 
     299                $this->deleteMessage($msg['rowid'], $channel, $nick); 
     300            } 
     301            $this->doPrivmsg( 
     302                $channel, 
     303                "{$nick}: (" . count($privmsgs) . " more messages sent in private.)" 
     304            ); 
     305        } 
    279306    } 
    280307