コード例 #1
0
 def deluser(self, bot, cli, ev):
     if not len(ev.splitd) > 0:
         cli.msg(ev.target, "\00304Error\003: Faltan parametros.")
         return 0
     user = User.get(User.name == ev.splitd[0].lower())
     if user is False:
         cli.msg(ev.target, "\003Error\003: El usuario no existe.")
     else:
         user.delete_instance()
         cli.msg(ev.target, "Se ha eliminado el usuario \2{0}\2".format(
             ev.splitd[0].lower()))
コード例 #2
0
    def register(self, bot, cli, ev):
        if len(ev.splitd) != 2:
            cli.msg(ev.target, "\00304Error\003: Faltan parametros.")
            return 0
        passw = hashlib.sha1(ev.splitd[1].encode('utf-8')).hexdigest()

        u = User.get(User.name == ev.splitd[0].lower())
        if u is False:
            u = User()
            u.name = ev.splitd[0].lower()
            u.password = passw
            u.save()
            # Si no hago esto no puedo obtener el uid :\
            user = User.get(User.name == ev.splitd[0].lower())
            UserPriv.create(uid=user.uid, priv=0, secmod="*", secchan="*")
            cli.msg(ev.target, "Te has registrado exitosamente. Ahora"
            " debes identificarte (\2{0}help auth\2)".format(bot.conf['prefix']
            ))
            self.whouid = user.uid
            cli.who(ev.target, "%atn,9")
        else:
            cli.msg(ev.target, "\00304Error\003: Ya estás registrado.")
コード例 #3
0
 def listpriv(self, bot, cli, ev):
     if not len(ev.splitd) > 0:
         cli.msg(ev.target, "\00304Error\003: Faltan parametros.")
         return 0
     user = User.get(User.name == ev.splitd[0].lower())
     if user is False:
         cli.msg(ev.target, "\003Error\003: El usuario no existe.")
     else:
         resp = "El usuario \2{0}\2 tiene los siguientes privilegios:" \
             .format(user.name)
         privs = UserPriv.select().where(UserPriv.uid == user.uid)
         for priv in privs:
             resp += " \2{0}\2 en el módulo \2{1}\2 en el canal \2{2}\2" \
                 .format(priv.priv, priv.secmod, priv.secchan)
         cli.msg(ev.target, resp)
コード例 #4
0
    def addpriv(self, bot, cli, ev):
        if not len(ev.splitd) > 1:
            cli.msg(ev.target, "\00304Error\003: Faltan parametros.")
            return 0
        #guh
        uname = ev.splitd[0].lower()
        priv = int(ev.splitd[1])
        if len(ev.splitd) > 2:
            module = ev.splitd[2]
        else:
            module = "*"

        if len(ev.splitd) > 3:
            chan = ev.splitd[3]
        else:
            chan = "*"

        user = User.get(User.name == uname)
        if user is False:
            cli.msg(ev.target, "\003Error\003: El usuario no existe")
            return 0

        uprivs = UserPriv.select().where(UserPriv.uid == user.uid)

        p = 0
        for upriv in uprivs:
            if upriv.priv >= priv:
                p += 1
            if upriv.secchan == chan or upriv.secchan == "*":
                p += 1

            if upriv.secmod == module or upriv.secmod == "*":
                p += 1

            if p == 3:
                cli.msg(ev.target, "\003Error\003: El usuario ya tiene priv"
                 "ilegios iguales o superiores a los que se intento otorgar.")
                return 0

            if upriv.secchan == chan and upriv.secmod == module:
                upriv.priv = priv
                upriv.save()
                cli.msg(ev.target, "Se han otorgado los privilegios.")
                return 0

        UserPriv.create(uid=user.uid, priv=priv, secchan=chan, secmod=module)

        cli.msg(ev.target, "Se han otorgado los privilegios.")
コード例 #5
0
    def delpriv(self, bot, cli, ev):
        if not len(ev.splitd) > 1:
            cli.msg(ev.target, "\00304Error\003: Faltan parametros.")
            return 0

        #guh x2
        uname = ev.splitd[0].lower()
        priv = int(ev.splitd[1])
        if len(ev.splitd) > 2:
            module = ev.splitd[2]
        else:
            module = "*"

        if len(ev.splitd) > 3:
            chan = ev.splitd[3]
        else:
            chan = "*"

        user = User.get(User.name == uname)
        if user is False:
            cli.msg(ev.target, "\003Error\003: El usuario no existe")
            return 0

        uprivs = UserPriv.select().where(UserPriv.uid == user.uid)

        p = 0
        tot = 0
        for upriv in uprivs:
            if upriv.priv >= priv:
                p += 1
            if upriv.secchan == chan or chan == "*":
                p += 1

            if upriv.secmod == module or module == "*":
                p += 1

            if p == 3:
                upriv.delete_instance()
                tot += 1

        if tot == 0:
            cli.msg(ev.target, "\003Error\003: No se ha encontrado ningun "
             "privilegio coincidiendo para borrar.")
        else:
            cli.msg(ev.target, "Se han borrado {0} privilegios".format(tot))
コード例 #6
0
    def quote(self, bot, cli, ev):
        if len(ev.splitd) < 1:
            cli.msg(ev.target, "\00304Error\003: Faltan parametros.")
            return 1

        if ev.splitd[0] == "add":
            if len(ev.splitd) < 2:
                cli.msg(ev.target, "\00304Error\003: Faltan parametros.")
                return 1
            try:
                uid = bot.authd[ev.source2]
            except:
                cli.msg(
                    ev.target, "\00304Error\003: Debes estar identific"
                    "ado con el bot para añadir quotes!")
                return 1
            u = User.get(User.uid == uid)
            if u is False:
                cli.msg(
                    ev.target, "\00304Error\003: Debes estar identific"
                    "ado con el bot para añadir quotes!")
                return 1
            ptime = time.time()
            user = u.name
            quote = " ".join(ev.splitd[1:])
            tquote.create(channel=ev.target, nick=user, ts=ptime, quote=quote)
            cli.msg(ev.target, "Quote añadido.")
        elif ev.splitd[0] == "del":
            if len(ev.splitd) < 2:
                cli.msg(ev.target, "\00304Error\003: Faltan parametros.")
                return 1
            if self.is_numeric(ev.splitd[1]) is False:
                cli.msg(ev.target, "\00304Error\003: Faltan parametros.")
                return 1
            try:
                uid = bot.authd[ev.source2]
            except:
                cli.msg(
                    ev.target, "\00304Error\003: Debes estar identific"
                    "ado con el bot para añadir quotes!")
                return 1
            usr = User.get(User.uid == uid)
            quoteid = ev.splitd[1]
            u = tquote.get(tquote.qid == quoteid)
            if u.nick == usr.name:
                u.delete_instance()
                cli.msg(ev.target, "Se ha eliminado el quote")
            else:
                if bot.authchk(ev.source2, 5, "quotes"):
                    u.delete_instance()
                    cli.msg(ev.target, "Se ha eliminado el quote")
                else:
                    cli.msg(ev.target, "\00304Error\003: No autorizado")

        elif ev.splitd[0] == "random":
            q = tquote.select().where(tquote.channel == ev.target)
            qc = tquote.select().where(tquote.channel == ev.target).count()
            if qc == 0:
                cli.msg(ev.target, "\00304Error\003: No hay quotes en"
                        " este canal.")
                return 1
            u = q[random.randint(0, qc - 1)]
            tm = time.asctime(time.localtime(float(u.ts)))
            cli.msg(
                ev.target, "Quote \2%s\2 por \2%s\2, añadido el"
                " \2%s\2: %s" % (u.qid, u.nick, tm, u.quote))
        else:
            if self.is_numeric(ev.splitd[0]) is False:
                cli.msg(ev.target, "\00304Error\003: Faltan parametros.")
                return 1
            quoteid = ev.splitd[0]
            u = tquote.get(tquote.qid == quoteid)
            if u is False:
                cli.msg(ev.target, "\00304Error\003: Ese quote no existe!")
                return 1
            if u.channel != ev.target:
                cli.msg(ev.target, "\00304Error\003: Quote inválido.")
                return 1
            tm = time.asctime(time.localtime(float(u.ts)))
            cli.msg(
                ev.target, "Quote \2%s\2 por \2%s\2, añadido el"
                " \2%s\2: %s" % (u.qid, u.nick, tm, u.quote))
コード例 #7
0
ファイル: quotes.py プロジェクト: ijpulidos/pyCoBot
    def quote(self, bot, cli, ev):
        if len(ev.splitd) < 1:
            cli.privmsg(ev.target, "\00304Error\003: Faltan parametros.")
            return 1

        if ev.splitd[0] == "add":
            if len(ev.splitd) < 2:
                cli.privmsg(ev.target, "\00304Error\003: Faltan parametros.")
                return 1
            try:
                uid = bot.authd[ev.source2]
            except:
                cli.privmsg(ev.target, "\00304Error\003: Debes estar identific"
                    "ado con el bot para añadir quotes!")
                return 1
            u = User.get(User.uid == uid)
            if u is False:
                cli.privmsg(ev.target, "\00304Error\003: Debes estar identific"
                    "ado con el bot para añadir quotes!")
                return 1
            ptime = time.time()
            user = u.name
            quote = " ".join(ev.splitd[1:])
            tquote.create(channel=ev.target, nick=user, ts=ptime, quote=quote)
            cli.privmsg(ev.target, "Quote añadido.")
        elif ev.splitd[0] == "del":
            if len(ev.splitd) < 2:
                cli.privmsg(ev.target, "\00304Error\003: Faltan parametros.")
                return 1
            if self.is_numeric(ev.splitd[1]) is False:
                cli.privmsg(ev.target, "\00304Error\003: Faltan parametros.")
                return 1
            try:
                uid = bot.authd[ev.source2]
            except:
                cli.privmsg(ev.target, "\00304Error\003: Debes estar identific"
                    "ado con el bot para añadir quotes!")
                return 1
            usr = User.get(User.uid == uid)
            quoteid = ev.splitd[1]
            u = tquote.get(tquote.qid == quoteid)
            if u.nick == usr.name:
                u.delete_instance()
                cli.privmsg(ev.target, "Se ha eliminado el quote")
            else:
                if bot.authchk(ev.source2, 5, "quotes"):
                    u.delete_instance()
                    cli.privmsg(ev.target, "Se ha eliminado el quote")
                else:
                    cli.privmsg(ev.target, "\00304Error\003: No autorizado")

        elif ev.splitd[0] == "random":
            q = tquote.select().where(tquote.channel == ev.target)
            qc = tquote.select().where(tquote.channel == ev.target).count()
            if qc == 0:
                cli.privmsg(ev.target, "\00304Error\003: No hay quotes en"
                    " este canal.")
                return 1
            u = q[random.randint(0, qc - 1)]
            tm = time.asctime(time.localtime(float(u.ts)))
            cli.privmsg(ev.target, "Quote \2%s\2 por \2%s\2, añadido el"
                " \2%s\2: %s" % (u.qid, u.nick, tm, u.quote))
        else:
            if self.is_numeric(ev.splitd[0]) is False:
                cli.privmsg(ev.target, "\00304Error\003: Faltan parametros.")
                return 1
            quoteid = ev.splitd[0]
            u = tquote.get(tquote.qid == quoteid)
            if u is False:
                cli.privmsg(ev.target, "\00304Error\003: Ese quote no existe!")
                return 1
            if u.channel != ev.target:
                cli.privmsg(ev.target, "\00304Error\003: Quote inválido.")
                return 1
            tm = time.asctime(time.localtime(float(u.ts)))
            cli.privmsg(ev.target, "Quote \2%s\2 por \2%s\2, añadido el"
                " \2%s\2: %s" % (u.qid, u.nick, tm, u.quote))