/** * Kick-starts the ghost process. * * @param \Phergie\Irc\Event\ServerEventInterface $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue */ public function handleNicknameInUse(ServerEvent $event, Queue $queue) { // Don't listen if ghost isn't enabled, or this isn't the first nickname-in-use error if (!$this->ghostEnabled || $this->ghostNick !== null) { return; } // Save the nick, so that we can send a ghost request once registration is complete $params = $event->getParams(); $this->ghostNick = $params[1]; }
/** * Populate channels with names on join. * * @param \Phergie\Irc\Event\ServerEventInterface $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue */ public function processNames(ServerEvent $event, Queue $queue) { $special = '\\[\\]\\`_\\^\\{\\|\\}'; $server = strtolower($event->getConnection()->getServerHostname()); $params = array_slice($event->getParams(), 2); $channel = array_shift($params); $this->getLogger()->debug('Adding names to channel', array('server' => $server, 'channel' => $channel)); $names = count($params) == 1 ? explode(' ', $params[0]) : $params; foreach (array_filter($names) as $name) { // Strip prefix characters $name = preg_replace("/^[^A-Za-z{$special}]+/", '', $name); $this->channels[$server][$channel][$name] = true; } }
/** * Generates the chanmode/prefix maps and enables NAMESX if supported. * * @param \Phergie\Irc\Event\ServerEventInterface $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue */ public function processCapabilities(ServerEventInterface $event, EventQueueInterface $queue) { $connection = $event->getConnection(); $logger = $this->getLogger(); $store = $this->connectionStore; if (!$store->contains($connection)) { $store->attach($connection, new \ArrayObject()); } foreach ($event->getParams()['iterable'] as $param) { if ($param == 'NAMESX') { $queue->ircProtoctl('NAMESX'); } elseif (preg_match('/^CHANMODES=([^,]*),((?1)),((?1)),((?1))$/', $param, $matches)) { $logger->debug('Parsing chanmode types from RPL_ISUPPORT'); $chanModeTypes = []; foreach (array(1 => self::CHANMODE_TYPE_LIST, 2 => self::CHANMODE_TYPE_PARAM_ALWAYS, 3 => self::CHANMODE_TYPE_PARAM_SETONLY, 4 => self::CHANMODE_TYPE_NOPARAM) as $index => $type) { if (!empty($matches[$index])) { $chanModeTypes += array_fill_keys(str_split($matches[$index]), $type); } } if (!empty($store[$connection]['modes'])) { $chanModeTypes += $store[$connection]['modes']; } $store[$connection]['modes'] = $chanModeTypes; } elseif (preg_match('/^PREFIX=\\((\\S+)\\)(\\S+)$/', $param, $matches) && strlen($matches[1]) == strlen($matches[2])) { $logger->debug('Parsing prefixes from RPL_ISUPPORT'); $prefixModes = str_split($matches[1]); $store[$connection]['prefixes'] = array_combine(str_split($matches[2]), $prefixModes); $chanModeTypes = array_fill_keys($prefixModes, self::CHANMODE_TYPE_PARAM_ALWAYS); if (!empty($store[$connection]['modes'])) { $chanModeTypes += $store[$connection]['modes']; } $store[$connection]['modes'] = $chanModeTypes; } } }