예제 #1
0
 /**
  * Create IRC Bot, connect, login and listen for events, and finally disconnect.
  */
 public function run()
 {
     $config = $this->config;
     // setup logging
     // redirect stderr to a log
     ini_set('log_errors', 'On');
     ini_set('error_log', $config['error_log']);
     $this->irc = $irc = new Net_SmartIRC();
     if (isset($config['debuglevel'])) {
         $irc->setDebugLevel($config['debuglevel']);
     }
     if (isset($config['logfile'])) {
         $irc->setLogdestination(SMARTIRC_FILE);
         $irc->setLogfile($config['logfile']);
     }
     // reconnect is poorly designed, do not use it
     // @see https://pear.php.net/bugs/bug.php?id=20974
     //$irc->setAutoRetry(true);
     $irc->setAutoRetry(false);
     $irc->setAutoRetryMax(PHP_INT_MAX);
     $irc->setReconnectDelay(10000);
     $irc->setReceiveTimeout(600);
     $irc->setTransmitTimeout(600);
     // enable user and channel syncing,
     // users are accessible via $irc->user array, i.e $irc->user['meebey']->host;
     $irc->setChannelSyncing(true);
     $irc->setUserSyncing(true);
     $this->registerHandlers($this->irc);
     $irc->connect($config['hostname'], $config['port']);
     if (empty($config['username'])) {
         $irc->login($config['nickname'], $config['realname']);
     } elseif (empty($config['password'])) {
         $irc->login($config['nickname'], $config['realname'], 0, $config['username']);
     } else {
         $irc->login($config['nickname'], $config['realname'], 0, $config['username'], $config['password']);
     }
     $this->joinChannels($irc);
     // loop forever, reconnect and retry
     // @see https://pear.php.net/bugs/bug.php?id=20974
     while (!$this->shutdown) {
         $irc->listen();
         $irc->reconnect();
     }
     $irc->disconnect();
 }