예제 #1
0
 public function __construct($argc, $argv)
 {
     $this->xbot = new xbot();
     // new xbot
     if ($argc > 1 && $argv[1] == 'debug') {
         self::$debug = true;
     }
     // argc
     $conf = file_get_contents('github.conf');
     self::$config = json_decode($conf, true);
     if (self::$config == null) {
         self::debug('failed config parse, you may have comments in it, remove them :)');
         die;
     }
     // config can't be parsed.
     self::debug('connecting to mysql (' . self::$config['mysql']['host'] . ':' . self::$config['mysql']['db'] . ')');
     self::$db = mysql_connect(self::$config['mysql']['host'], self::$config['mysql']['user'], self::$config['mysql']['pass']);
     mysql_select_db(self::$config['mysql']['db'], self::$db);
     // connect to mysql
     foreach (self::$config['networks'] as $network => $net_data) {
         self::debug('connecting to (' . $network . ':' . $net_data['port'] . ') as ' . $net_data['nick']);
     }
     $this->xbot->connect(self::$config);
     self::debug('connected to networks');
     // connect the bot
     $this->xbot->timer->add(array('bot', 'listen_data', array($this->xbot)), 5, 0);
     $this->xbot->timer->add(array('bot', 'get_new_data', array($this->xbot)), self::$config['options']['new_data_interval'], 0);
     // set up some timers, we only actually go hunting for new data every 30 seconds, then if new data is found its stored
     // the stored data is checked by listen_data every 5 seconds. We only check every 30 seconds because for huge repos like
     // rails/rails, which I developed this on it can be quite intensive, and plus the more often we check the quicker
     // we can run out of api calls (unless you get on the whitelist)
     $this->xbot->main('bot', 'main');
     // boot the main loop w/ a callback*/
 }