Skip to content

Commit

Permalink
Using the native timers instead of own ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlinc committed May 17, 2012
1 parent 29b374b commit 50ee160
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions src/Module/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ class Main extends AModule

public $events = array(
'on251' => 'setNetwork',
'loopIterate',
'onConnect',
'onCtcpRequest'
);

public $_oldTime = array();

public function __construct()
{
$spamfilter = new \Botlife\Application\Spamfilter;
$timer1 = new \Ircbot\Entity\Timer(
'spamfilter-decrease', array($spamfilter, 'decreaseAmount'), 3000
);
$timer2 = new \Ircbot\Entity\Timer(
'storage-save', '\Botlife\Application\Storage::saveToDisk', 50000
);
\Ircbot\Handler\Timer::addTimer($timer1);
\Ircbot\Handler\Timer::addTimer($timer2);
}

public function onConnect()
{
Expand All @@ -30,32 +40,15 @@ public function setNetwork()
$bot->currentNetwork = $network;
}

public function loopIterate()
{
if (empty($this->_oldTime)) {
$this->_oldTime[0] = time();
$this->_oldTime[1] = time();
}
if ((time() - $this->_oldTime[0]) >= 3) {
$spamfilter = new \Botlife\Application\Spamfilter;
$spamfilter->decreaseAmount();
$this->_oldTime[0] = time();
}
if ((time() - $this->_oldTime[1]) >= 60) {
\Botlife\Application\Storage::saveToDisk();
$this->_oldTime[1] = time();
}
}

public function onCtcpRequest(\Ircbot\Command\CtcpRequest $event)
{
if ($event->message == 'VERSION') {
$reply = new \Ircbot\Command\CtcpReply(
$event->mask->nickname,
$event->mask->nickname,
'VERSION BotLife version ' . `git describe`
);
$bot = Ircbot::getInstance()->getBotHandler()
->getBotById($event->botId);
->getBotById($event->botId);
$bot->sendRawData($reply);
}
}
Expand Down

0 comments on commit 50ee160

Please sign in to comment.