Source for file time.module.php
Documentation is available at time.module.php
* phpIcqBot Time & Uptime Module
* @author Jector <no.one.on@gmail.com>
* @todo number of connections, restarts etc in !uptime
* Time, when bot was started. (time()-$this->uptime) -- current uptime;
* Store last uptime update time
* Standart module's init function
* Adding commands, events, timers
$this->uptime = $this->lastuptime = time();
$this->stats = $this->commands->store->getData($this, 'stats');
$this->stats['restart']= $this->stats['connect']= $this->stats['disconnect']= $this->stats['commands']= $this->stats['uptime']= 0;
$this->commands->addCommand($this, 'uptime', array('u'));
$this->commands->addCommand($this, 'time');
$this->commands->addTimer($this, "uptime",60,"Uptime");
* Standart module's deinit function
$this->stats['uptime']+= (time()- $this->lastuptime);
$this->logs->write('UPTIME: '. $this->diff2time(time()- $this->uptime). ' seconds.');
$this->commands->store->setData($this, 'stats', $this->stats);
* Replies current bot's uptime
* @param unknown_type $uin
$this->commands->sendMsg($uin, "Bot is working ". $this->diff2time(time()- $this->uptime). " starting from ". date('r',$this->uptime). "\r\nOverall uptime is: ". $this->diff2time($this->stats['uptime']));
$this->stats['uptime']+= (time()- $this->lastuptime);
$this->lastuptime= time();
return 'Shows current time';
$this->stats['restart']++ ;
$this->stats['commands']++ ;
$this->stats['connect']++ ;
* Counts Disconnect Events
$this->stats['disconnect']++ ;
* Update Uptime information every minute
$this->stats['uptime']+= (time()- $this->lastuptime);
$this->lastuptime= time();
* Counts diff time in seconds to diff time in days, hours, minutes, seconds
* @param integer $timestamp
private function diff2time($timestamp)
$sec= array("sec"=> 60,"min"=> 60,"hrs"=> 24,"days"=> 30);
$r = ($timestamp % $v). ' '. $k. '. '. $r;
$timestamp = floor($timestamp / $v);
if ($timestamp <= 0) break;
|