/** * Responds to authentication requests and notifications of ghost * connections being killed from NickServ. * * @param \Phergie\Irc\Event\UserEventInterface $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue */ public function handleNotice(UserEvent $event, Queue $queue) { // Ignore notices that aren't from the NickServ agent if (strcasecmp($event->getNick(), $this->botNick) !== 0) { return; } $connection = $event->getConnection(); $params = $event->getParams(); $message = $params['text']; // Authenticate the bot's identity for authentication requests if (preg_match($this->identifyPattern, $message)) { return $queue->ircPrivmsg($this->botNick, 'IDENTIFY ' . $this->password); } // Emit an event on successful authentication if (preg_match($this->loginPattern, $message)) { return $this->getEventEmitter()->emit('nickserv.identified', [$connection, $queue]); } // Reclaim primary nick on ghost confirmation if ($this->ghostNick !== null && preg_match($this->ghostPattern, $message)) { $queue->ircNick($this->ghostNick); $this->ghostNick = null; return; } }
/** * Nick is in use, pick another. * * @param \Phergie\Irc\Event\EventInterface $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue */ public function handleEvent(Event $event, Queue $queue) { $iterator = $this->getIterator($event->getConnection()); if (!$iterator->valid()) { $queue->ircQuit('All specified alternate nicks are in use'); return; } $nick = $iterator->current(); $iterator->next(); $this->logger->debug("[AltNick] Switching nick to '{$nick}'"); $queue->ircNick($nick); $event->getConnection()->setNickname($nick); }
/** * Handle primary nick recovery. * * @param \Phergie\Irc\Event\UserEventInterface $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue */ public function handleQuit(UserEvent $event, Queue $queue) { $nick = $event->getNick(); if ($this->primaryNick !== null && $nick == $this->primaryNick) { $this->logger->debug("[AltNick] '{$nick}' disconnected, switching to primary nick"); $queue->ircNick($this->primaryNick); $this->primaryNick = null; } }