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('\*', '.*', preg_quote($mask, '/')) . '$/';

            if ($this->caseless) {
                $pattern .= "i";
            }

            if (preg_match($pattern, $userMask)) {
                return true;
            }
        }

        return false;
    }