Home  |  Linux  | Mysql  | PHP  | XML
From:Tobias Schlitt Date:Sat Jun 26 05:22:37 2004
Subject:cvs: pearbot /modules bugstats.php
toby		Sat Jun 26 07:22:37 2004 EDT

  Added files:                 
    /pearbot/modules	bugstats.php 
  Log:
  * Added bug stats module.
  
  

http://cvs.php.net/co.php/pearbot/modules/bugstats.php?r=1.1&p=1
Index: pearbot/modules/bugstats.php
+++ pearbot/modules/bugstats.php
<?php
/**
 * $Id: bugstats.php,v 1.1 2004/06/26 11:22:37 toby Exp $
 * $Revision: 1.1 $
 * $Author: toby $
 * $Date: 2004/06/26 11:22:37 $
 *
 * Copyright (c) 2004 Tobias Schlitt <toby@php.net> & Mirco Bauer <meebey@php.net>
*/

require_once "HTTP/Request.php";

class Net_SmartIRC_module_bugstats
{
    var $name = 'bugstats';
    var $description = '!bugstats command';
    var $author = 'Tobias Schlitt <toby@php.net> & Mirco Bauer <meebey@php.net>';
    var $license = 'LGPL';
    
    var $timeids = array();
    var $actionids = array();
    
    function module_init(&$irc)
    {
        $this->actionids[] = $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL|SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^!bugstats', $this, 'bugstats');
        $this->timeids[] = $irc->registerTimehandler(90000, $this, 'autoBugstats');
    }
    
    function module_exit(&$irc)
    {
        foreach ($this->actionids as $value) {
            $irc->unregisterActionid($value);
        }
    }

    
    function bugstats(&$irc, &$data) 
    {
        $count = $this->getStats();
        if (PEAR::isError($count)) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $count->getMessage());
            return $count;
        }
        
        $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $data->nick.': Current bug count is '.$count);
        return true;
    }

    function autoBugstats (&$irc) {
        $count = $this->getStats();
        if (PEAR::isError($count)) {
            return $count;
        }
        $chan = $irc->getChannel('#pear');
        $topic = $chan->topic;
        $topic = preg_replace('/[0-9] open bugs/isU', '', $topic);
        $irc->setTopic('#pear', $topic.' '.$count.' open bugs');
        return true;
    }

    function getStats ( ) {        
        $req =& new HTTP_Request('http://pear.php.net/bugs/lstat.php');
        if (PEAR::isError($req->sendRequest())) {
            return PEAR::raiseError('Error fetching bug stats.', 0);
        }
        return $req->getResponseBody();
    }
}
?>
Navigate in group php.pear.bot at sever news.php.net
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by Zareef Ahmed
Powered By PHP Consultants