/** * Responds with a magic eight ball phrase when asked questions * * @param \Phergie\Irc\Event\EventInterface $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue */ public function handleEvent(Event $event, Queue $queue) { if ($event instanceof UserEvent) { $nick = $event->getNick(); $channel = $event->getSource(); $params = $event->getParams(); $text = $params['text']; $matched = stripos($text, '8 ball') !== false; if ($matched) { $msg = $nick . ', the magic 8 ball says "' . $this->getMagicEightBallAnswer() . '"'; $queue->ircPrivmsg($channel, $msg); } } }
/** * Filters events that are not user-specific or are from the specified users. * * @param \Phergie\Irc\Event\EventInterface $event * @return boolean|null TRUE if the event originated from a user with a matching mask * associated with this filter, FALSE if it originated from a user without a * matching mask, or NULL if it did not originate from a user. */ public function filter(EventInterface $event) { if (!$event instanceof UserEventInterface) { return null; } $nick = $event->getNick(); if ($nick === null) { return null; } $userMask = sprintf('%s!%s@%s', $nick, $event->getUsername(), $event->getHost()); foreach ($this->masks as $mask) { $pattern = '/^' . str_replace('*', '.*', $mask) . '$/'; if (preg_match($pattern, $userMask)) { return true; } } return false; }