Changeset 2068 for trunk/modules/kobot

Show
Ignore:
Timestamp:
02/16/2008 07:20:36 PM (9 months ago)
Author:
Shadowhand
Message:

Updated Kobot:

  • Uptime timer added
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/kobot/libraries/Kobot.php

    r2067 r2068  
    104104        } 
    105105 
     106        public function __get($key) 
     107        { 
     108                if (isset($this->$key)) 
     109                { 
     110                        return $this->$key; 
     111                } 
     112        } 
     113 
    106114        public function default_responses() 
    107115        { 
     
    135143                $this->set_trigger('^info ([^\s]+)$', array($this, 'trigger_info')); 
    136144 
     145                // Set the "uptime" timer for 60 minutes 
     146                $this->set_timer(60 * 60, array($this, 'timer_uptime')); 
     147 
    137148                foreach ($this->dropped as $cmd) 
    138149                { 
    139150                        // Drop all requested commands 
    140151                        $this->set_response($cmd, array($this, 'response_drop')); 
    141                 } 
    142         } 
    143  
    144         public function __get($key) 
    145         { 
    146                 if (isset($this->$key)) 
    147                 { 
    148                         return $this->$key; 
    149152                } 
    150153        } 
     
    665668        } 
    666669 
     670        /** 
     671         * Default timers. 
     672         */ 
     673 
     674        protected function timer_uptime() 
     675        { 
     676                // Uptime array 
     677                $uptime = array(); 
     678 
     679                // Timespan array 
     680                $timespan = date::timespan((int) $this->stats['start']); 
     681 
     682                // Skip all the empty starting intervals 
     683                $skip = TRUE; 
     684 
     685                foreach ($timespan as $interval => $amount) 
     686                { 
     687                        if ($amount > 0 OR $skip === FALSE) 
     688                        { 
     689                                // Stop skipping intervals 
     690                                $skip = FALSE; 
     691 
     692                                // Only add amounts that are greater than 0 
     693                                $uptime[$interval] = $amount.' '.$interval; 
     694                        } 
     695                } 
     696                // Add "and" before the last amount 
     697                $uptime[$interval] = 'and '.$uptime[$interval]; 
     698 
     699                // Log the uptime 
     700                $this->log(1, 'Uptime: '.implode(' ', $uptime)); 
     701        } 
     702 
    667703} // End Kobot