Пример #1
0
 /**
  * Initializes the queues. You can specify custom flood limits, but the defaults should be safe for most servers.
  * @param Bot $bot The bot object
  * @param int $linesPerSecond Maximum lines per second that will be sent to the output. 0 for no limit.
  * @param int $linesMaxBurst Maximum lines that will be sent initially.
  * @see setFloodLimits()
  */
 public function __construct(Bot $bot, $linesPerSecond = 2, $linesMaxBurst = 4)
 {
     parent::__construct($bot);
     $this->setFloodLimits($linesPerSecond, $linesMaxBurst);
     // Prepares the queues array so that we can later easily iterate over them
     $this->recreateQueues();
 }
Пример #2
0
 /**
  * Set up some initial events.
  * @param Bot $bot The bot object.
  */
 public function __construct(Bot $bot)
 {
     parent::__construct($bot);
     $IRCMessageInboundEvent = new RegisteredEvent('IIRCMessageInboundEvent');
     $bot->getEventManager()->register('IRCMessageInbound', $IRCMessageInboundEvent);
     $IRCMessageOutgoingEvent = new RegisteredEvent('IIRCMessageOutgoingEvent');
     $bot->getEventManager()->register('IRCMessageOutgoing', $IRCMessageOutgoingEvent);
     $ConnectEvent = new RegisteredEvent('IConnectEvent');
     $bot->getEventManager()->register('Connect', $ConnectEvent);
 }
Пример #3
0
 /**
  * Initializes the queues. You can specify custom flood limits, but the defaults should be safe for most servers.
  * @param Bot $bot The bot object
  * @param int $linesPerSecond Maximum lines per second that will be sent to the output. 0 for no limit.
  * @param int $linesMaxBurst Maximum lines that will be sent initially.
  * @see setFloodLimits()
  */
 public function __construct(Bot $bot, $linesPerSecond = 2, $linesMaxBurst = 4)
 {
     parent::__construct($bot);
     $this->setFloodLimits($linesPerSecond, $linesMaxBurst);
     // Prepares the queues array so that we can later easily iterate over them
     $this->recreateQueues();
     // Sets a timer.
     //$timer = new Timer(1, array($this, 'flush'));
     //$this->bot->getTimerManager()->add('QueueTimer', $timer);
 }
Пример #4
0
 /**
  * Loads the config file and parses it.
  * @param Bot $bot The bot object
  * @param string $config The path to the config file.
  * @throws \Exception on read error.
  */
 public function __construct(Bot $bot, $config)
 {
     parent::__construct($bot);
     try {
         // Open the file and surpress errors; we'll do our own error handling here.
         $data = @file_get_contents($config);
         if (!empty($data) && is_string($data)) {
             $this->config = Neon::decode(file_get_contents($config));
         } else {
             throw new ConfigurationException('The configuration could not be loaded. Please check the file ' . $config . ' exists and is readable/not corrupt.');
         }
     } catch (\Exception $e) {
         throw new ConfigurationException('Configuration syntax error: ' . $e->getMessage());
     }
 }
Пример #5
0
 /**
  * Set up the class.
  * @param Bot $bot The bot object
  * @param string $logDir The directory to store logs in
  */
 public function __construct(Bot $bot, $logDir = WPHP_LOG_DIR)
 {
     parent::__construct($bot);
     // Make sure we end up clean when quitting.
     register_shutdown_function(array($this, 'logShutdown'));
     // Fetch the configuration.
     $config = $bot->getConfig('log');
     // Set some flags.
     $this->writeDebug = $bot->getConfig('log.writeDebug');
     $this->printDebug = $bot->getConfig('log.printDebug');
     $this->writeChannel = $bot->getConfig('log.writeChannel');
     $this->printChannel = $bot->getConfig('log.printChannel');
     // Can't log to a file not set.
     if (empty($config['file'])) {
         throw new \RuntimeException('LogManager: A log file needs to be set to use logging. Aborting.');
     }
     // Check for log dir and create it if necessary
     if (!file_exists($logDir)) {
         if (!mkdir($logDir, 0775)) {
             throw new \RuntimeException('Log directory (' . $logDir . ') does not exist. Attempt to create it failed.');
         }
     }
     // Check if the log dir is in fact a directory
     if (!is_dir($logDir)) {
         throw new \RuntimeException($logDir . ': ' . __CLASS__ . ' expected directory.');
     }
     // Also can't log to a directory we can't write to.
     if (!is_writable($logDir)) {
         throw new \RuntimeException('Log directory (' . $logDir . ') has insufficient write permissions.');
     }
     // Start off with the base path to the file.
     $this->logFile = $logDir . '/' . $config['file'];
     // Now, we're going to count up until we find a file that doesn't yet exist.
     $i = 0;
     do {
         $i++;
     } while (file_exists($this->logFile . $i . '.log'));
     // And fix up the final log name.
     $this->logFile = $this->logFile . $i . '.log';
     // Ready!
     if ($this->handle = fopen($this->logFile, 'w')) {
         $this->log('Using log file ' . $this->logFile);
     } else {
         trigger_error('LogManager: Cannot create file ' . $this->logFile . '. Aborting.', E_USER_ERROR);
     }
 }
Пример #6
0
 /**
  * Setup the Error Handler.
  * @param Bot $bot
  */
 public function __construct(Bot $bot)
 {
     parent::__construct($bot);
     set_error_handler(array($this, 'handler'));
 }
Пример #7
0
 /**
  * Sets up the module manager.
  * @param Bot $bot An instance of the bot.
  * @param string $dir The directory where the modules are in.
  */
 public function __construct(Bot $bot, $dir = WPHP_MODULE_DIR)
 {
     parent::__construct($bot);
     $this->moduleDir = $dir;
     spl_autoload_register(array($this, 'autoLoad'));
 }
Пример #8
0
 /**
  * Hook into events and get everything set up.
  * @param Bot $bot The bot object.
  */
 public function __construct(Bot $bot)
 {
     parent::__construct($bot);
     $this->bot->getEventManager()->getEvent('Loop')->registerListener(array($this, 'trigger'));
 }