示例#1
0
 /**
  * Sets the pattern associated with this filter.
  *
  * \param string $pattern
  *      Pattern to use in text comparisons.
  *
  * \throw Erebot::InvalidValueException
  *      The given value for $pattern is invalid.
  */
 public function setPattern($pattern)
 {
     if (!\Erebot\Utils::stringifiable($pattern)) {
         throw new \Erebot\InvalidValueException('Pattern must be a string');
     }
     $this->pattern = $pattern;
 }
示例#2
0
文件: Source.php 项目: erebot/erebot
 /**
  * Sets the source used in comparisons.
  *
  * \param $source string|object
  *      Source to match incoming events against.
  *
  * \throw Erebot::InvalidValueException
  *      The given source is invalid.
  */
 public function setSource($source)
 {
     if ($source !== null && !\Erebot\Utils::stringifiable($source)) {
         throw new \Erebot\InvalidValueException('Not a valid nickname');
     }
     $this->source = $source;
 }
示例#3
0
文件: Chan.php 项目: erebot/erebot
 /**
  * Sets the channel used in comparisons.
  *
  * \param $chan string|object
  *      Channel to match incoming events against.
  *
  * \throw Erebot::InvalidValueException
  *      The given chan is invalid.
  */
 public function setChan($chan)
 {
     if (!\Erebot\Utils::stringifiable($chan)) {
         throw new \Erebot\InvalidValueException('Not a channel');
     }
     $this->chan = $chan;
 }
示例#4
0
文件: LineIO.php 项目: erebot/erebot
 /**
  * Retrieves a single line of text from the incoming buffer
  * and puts it in the incoming FIFO.
  *
  * \retval true
  *      Whether a line could be fetched from the buffer.
  *
  * \retval false
  *      ... or not.
  *
  * \note
  *      Lines fetched by this method are always UTF-8 encoded.
  */
 protected function getLine()
 {
     $pos = false;
     foreach ($this->eol as $eol) {
         $pos = strpos($this->incomingData, $eol);
         if ($pos !== false) {
             break;
         }
     }
     if ($pos === false) {
         return false;
     }
     $len = strlen($eol);
     $line = \Erebot\Utils::toUTF8(substr($this->incomingData, 0, $pos));
     $this->incomingData = substr($this->incomingData, $pos + $len);
     $this->rcvQueue[] = $line;
     $logger = \Plop\Plop::getInstance();
     $logger->debug('%(line)s', array('line' => addcslashes($line, "..")));
     return true;
 }
示例#5
0
文件: Core.php 项目: erebot/erebot
 /**
  * Handles request for a graceful shutdown of the bot.
  * Such requests are received as signals.
  *
  * \param int $signum
  *      The number of the signal.
  */
 public function handleSignal($signum)
 {
     $consts = get_defined_constants(true);
     $signame = '???';
     foreach ($consts['pcntl'] as $name => $value) {
         if (!strncmp($name, 'SIG', 3) && strncmp($name, 'SIG_', 4) && $signum == $value) {
             $signame = $name;
             break;
         }
     }
     $logger = \Plop\Plop::getInstance();
     $logger->info($this->gettext('Received signal #%(signum)d (%(signame)s)'), array('signum' => $signum, 'signame' => $signame));
     // Print some statistics.
     if (function_exists('memory_get_peak_usage')) {
         $logger->debug($this->gettext('Memory usage:'));
         $limit = trim(ini_get('memory_limit'));
         $limit = \Erebot\Utils::parseHumanSize($limit . "B");
         $stats = array($this->gettext("Allocated:") => \Erebot\Utils::humanSize(memory_get_peak_usage(true)), $this->gettext("Used:") => \Erebot\Utils::humanSize(memory_get_peak_usage(false)), $this->gettext("Limit:") => \Erebot\Utils::humanSize($limit));
         foreach ($stats as $key => $value) {
             $logger->debug('%(key)-16s%(value)10s', array('key' => $key, 'value' => $value));
         }
     }
     $this->stop();
 }
示例#6
0
文件: Base.php 项目: erebot/api
 /**
  * Send a raw command to the IRC server.
  *
  * \param string $command
  *      The command to send.
  */
 protected function sendCommand($command)
 {
     if (!\Erebot\Utils::stringifiable($command)) {
         throw new \Exception('Invalid command (not a string)');
     }
     $this->connection->getIO()->push((string) $command);
 }