/**
  * Reload Bot configuration
  *
  */
 public function reloadConfiguration()
 {
     $this->config->reset();
     $this->lists = array();
     // Set base directory for lists relative to that of the config file's
     $base = dirname($this->config->getFilename()) . DIRECTORY_SEPARATOR;
     // Read word/message lists
     foreach ($this->config->readSection('lists') as $identifier => $file) {
         $this->lists[$identifier] = array();
         $f = new File($base . $file);
         try {
             if ($f->open(FILE_MODE_READ)) {
                 while (($line = $f->readLine()) && !$f->eof()) {
                     $this->lists[$identifier][] = $line;
                 }
             }
             $f->close();
         } catch (IOException $e) {
             $e->printStackTrace();
             return FALSE;
         }
     }
     // Read karma recognition phrases
     $f = new File($base . $this->config->readString('karma', 'recognition'));
     try {
         if ($f->open(FILE_MODE_READ)) {
             while (!$f->eof()) {
                 $line = $f->readLine();
                 if (empty($line) || strspn($line, ';#')) {
                     continue;
                 }
                 list($pattern, $channel, $direct) = explode(':', $line);
                 $this->recognition[$pattern] = array((int) $channel, (int) $direct);
             }
         }
         $f->close();
     } catch (IOException $e) {
         $e->printStackTrace();
         return FALSE;
     }
     // If no karma is set and the karma storage exists, load it
     if (0 == sizeof($this->karma)) {
         try {
             $f = new File($base . 'karma.list');
             if ($f->exists()) {
                 $karma = unserialize(FileUtil::getContents($f));
                 if ($karma) {
                     $this->karma = $karma;
                 }
             }
         } catch (IOException $e) {
             // Karma loading failed - log, but ignore...
             $this->cat && $this->cat->error($e);
         }
     }
 }
Example #2
0
 function testreadLine()
 {
     $this->assertFalse(PEAR::isError(File::rewind('test.txt', FILE_MODE_READ)));
     $this->assertEquals($this->getTestLine(), File::readLine('test.txt'));
     $this->assertEquals($this->getTestLine(), File::readLine('test.txt'));
     $this->assertEquals($this->getTestLine(), File::readLine('test.txt'));
     $this->assertEquals($this->getTestLine(), File::readLine('test.txt'));
     $this->assertEquals($this->getTestLine(), File::readLine('test.txt'));
     $this->assertEquals($this->getTestLine(), File::readLine('test.txt'));
     $this->assertEquals($this->getTestLine(), File::readLine('test.txt'));
     $this->assertEquals($this->getTestLine(), File::readLine('test.txt'));
     $this->assertEquals($this->getTestLine(), File::readLine('test.txt'));
     $this->assertEquals($this->getTestLine(), File::readLine('test.txt'));
 }
	/**
	 * Reinicia o Iterator
	 * @see Iterator::rewind()
	 */
	public function rewind() {
		if ( $this->testFile() ) {
			$this->file->seek( 0 );
			$this->current = $this->file->readLine();
		}
	}