Exemplo n.º 1
0
    def nick(self, sock, source, nick):
        user = User.objects.filter(sock=sock).first()

        if not VALID_NICK_REGEX.match(nick):
            return ERR_ERRONEUSNICKNAME(nick)

        if len(nick) > self.parent.nicklen:
            return ERR_ERRONEUSNICKNAME(nick)

        if any(x for x in User.objects.all()
               if x.nick and x.nick.lower() == nick.lower()):
            return ERR_NICKNAMEINUSE(nick)

        prefix = user.prefix or joinprefix(*source)
        user.nick = nick
        user.save()

        if user.userinfo and user.userinfo.user is not None:
            user.registered = True
            user.save()
            return signon(sock, user.source)

        users = chain(*map(attrgetter("users"), user.channels))

        self.notify(users, Message(u("NICK"), nick, prefix=prefix))
Exemplo n.º 2
0
    def on_privmsg_or_notice(self, event, sock, source, target, message):
        user = User.objects.filter(sock=sock).first()

        prefix = user.prefix or joinprefix(*source)

        if target.startswith(u"#"):
            channel = Channel.objects.filter(name=target).first()
            if channel is None:
                return ERR_NOSUCHCHANNEL(target)

            if "n" in channel.modes:
                if not user.oper and user not in channel.users:
                    return ERR_CANNOTSENDTOCHAN(channel.name)

            if "m" in channel.modes:
                if not user.oper and user not in chain(channel.operators,
                                                       channel.voiced):
                    return ERR_CANNOTSENDTOCHAN(channel.name)

            self.notify(channel.users,
                        _Message(u"PRIVMSG", target, message, prefix=prefix),
                        user)
        else:
            user = User.objects.filter(nick=target).first()
            if user is None:
                return ERR_NOSUCHNICK(target)

            return reply(
                user.sock,
                _Message(event.name.upper(), target, message, prefix=prefix))
Exemplo n.º 3
0
    def on_privmsg_or_notice(self, event, sock, source, target, message):
        user = User.objects.filter(sock=sock).first()

        prefix = user.prefix or joinprefix(*source)

        if target and target[0] in (u("&"), u("#"),):
            channel = Channel.objects.filter(name=target).first()
            if channel is None:
                return ERR_NOSUCHCHANNEL(target)

            if u("n") in channel.modes:
                if not user.oper and user not in channel.users:
                    return ERR_CANNOTSENDTOCHAN(channel.name)

            if u("m") in channel.modes:
                if not user.oper and user not in chain(channel.operators, channel.voiced):
                    return ERR_CANNOTSENDTOCHAN(channel.name)

            self.notify(
                channel.users,
                _Message(u("PRIVMSG"), target, message, prefix=prefix),
                user
            )
        else:
            user = User.objects.filter(nick=target).first()
            if user is None:
                return ERR_NOSUCHNICK(target)

            return reply(
                user.sock,
                _Message(
                    event.name.upper(), target, message,
                    prefix=prefix
                )
            )
Exemplo n.º 4
0
    def nick(self, sock, source, nick):
        user = User.objects.filter(sock=sock).first()

        if not VALID_NICK_REGEX.match(nick):
            return ERR_ERRONEUSNICKNAME(nick)

        if len(nick) > self.parent.nicklen:
            return ERR_ERRONEUSNICKNAME(nick)

        if any(x for x in User.objects.all() if x.nick and x.nick.lower() == nick.lower()):
            return ERR_NICKNAMEINUSE(nick)

        prefix = user.prefix or joinprefix(*source)
        user.nick = nick
        user.save()

        if not user.registered and user.userinfo is not None:
            user.registered = True
            user.save()
            return signon(sock, user.source)

        users = chain(*map(attrgetter("users"), user.channels))

        self.notify(users, Message(u"NICK", nick, prefix=prefix))
Exemplo n.º 5
0
 def prefix(self):
     userinfo = self.userinfo
     if userinfo is None:
         return
     return joinprefix(*self.source)
Exemplo n.º 6
0
def test_joinprefix():
    nick, ident, host = "test", "foo", "localhost"
    s = joinprefix(nick, ident, host)
    assert s == "test!foo@localhost"
Exemplo n.º 7
0
 def prefix(self):
     userinfo = self.userinfo
     if userinfo is None:
         return
     return joinprefix(*self.source)
Exemplo n.º 8
0
def test_joinprefix():
    nick, ident, host = "test", "foo", "localhost"
    s = joinprefix(nick, ident, host)
    assert s == "test!foo@localhost"
Exemplo n.º 9
0
 def prefix(self):
     userinfo = self.userinfo
     return joinprefix(self.nick, userinfo.user, userinfo.host)
Exemplo n.º 10
0
 def prefix(self):
     userinfo = self.userinfo
     return joinprefix(self.nick, userinfo.user, userinfo.host)