Example #1
0
    def __onmessage_karma_points_remove(self, *args, **kwargs):
        sender, ident, channel, message = kwargs.values()
        nick = message.split("--")[0].strip()
        
        if self.__prevent_self_karma(sender, nick) or not self.__is_admin(nick):
            self.irc.msg_to_channel(channel, "{nick} not allowed to remove karma of yourself".format(nick=sender))
            return

        db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST, self.irc.params.ZEO_PORT)
        
        try:
            user = db.users.has_key(nick)
            
            if not user:
                if self.__is_admin(sender):
                    self.__register_user(nick)
                    self.__remove_karma(nick)
                
                else:
                    self.irc.msg_to_channel(self.irc.params.CHANNEL, "{s} Access Denied".format(s=sender))
                    return
            
            self.__remove_karma(nick)
            self.__karma_message(nick, "karma--")
        
        except Exception as e:
            print(e)
            print(traceback.print_exc())
        finally:
            db.close()
Example #2
0
    def _mostrar_piada(self, *args, **kwargs):
        message = kwargs['data']['message']
        receiver = kwargs['data']['receiver']
        sender = kwargs['data']['sender']
        params = message.split(" ", 3)
        count_args = len(params) - 3
        db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST,
                    self.irc.params.ZEO_PORT)

        try:

            piadas = [p for p in db.piadas.values()]

            if not piadas:
                self.irc.msg_to_channel(self.irc.params.CHANNEL,
                                        "Nenhuma Piada cadastrada!")
                return

            random.shuffle(piadas)  #random.sample(piadas,len(piadas))
            range = random.randrange(len(piadas))
            piada = piadas[range]

            if not piada:
                self.irc.msg_to_channel(self.irc.params.CHANNEL,
                                        "Piada Não Encontrada")
                return

            self.irc.msg_to_channel(self.irc.params.CHANNEL, piada.piada)
            pass
        except Exception as e:
            pass
        finally:
            db.close()
Example #3
0
 def __onmessage_karma_points_add(self, *args, **kwargs):
     sender, ident, channel, message = kwargs.values()
     nick = message.split("++")[0].strip()
     
     if self.__prevent_self_karma(sender, nick):
         self.irc.msg_to_channel(channel, "{nick} not allowed to give karma to yourself.".format(nick=sender))
         return
     try:
         db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST, self.irc.params.ZEO_PORT)
         user = db.users.has_key(nick)
         
         if not user:
             if self.__is_admin(sender):
                 self.__register_user(nick)
                 self.__add_karma(nick)
             
             else:
                 self.irc.msg_to_channel(self.irc.params.CHANNEL, "{s} Access Denied".format(s=sender))
                 return
             return
         
         self.__add_karma(nick)
         self.__karma_message(nick, "karma++")
         # self.irc.msg_to_channel(self.irc.params.CHANNEL,
         #                        "{n} has {points} Karma Points".format(n=nick, points=db.users[nick].karma))
     except Exception as e:
         print(e)
         print(traceback.print_exc())
     finally:
         db.close()
Example #4
0
 def __karma_message(self, nick, type):
     db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST, self.irc.params.ZEO_PORT)
     msg = ""
     try:
         karma = db.users[nick].karma
         
         if karma < -15:
             msg = "(Otário) {nick} {tp}   (total: {karma})".format(nick=nick, tp=type, karma=db.users[nick].karma)
         elif karma >= 0 and karma < 10:
             msg = "{nick} {tp} (total: {karma})".format(nick=nick, tp=type, karma=db.users[nick].karma)
         elif karma > 10:
             msg = "(Gente Final) {tp} {nick}  (total: {karma})".format(nick=nick, tp=type,
                                                                        karma=db.users[nick].karma)
         elif karma > 20:
             msg = "(Gente Bonissima) {tp} {nick} (total: {karma})".format(nick=nick, tp=type,
                                                                           karma=db.users[nick].karma)
         else:
             msg = "{tp} {nick}  (total: {karma})".format(nick=nick, tp=type, karma=db.users[nick].karma)
         
         self.irc.msg_to_channel(self.irc.params.CHANNEL, msg)
     
     except Exception as e:
         print(traceback.print_exc())
     finally:
         db.close()
     pass
Example #5
0
 def __is_admin(self, nick):
 
     db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST, self.irc.params.ZEO_PORT)
     try:
         if db.admin.has_key(nick):
             return True
     except Exception as ex:
         print(ex)
         print(traceback.print_exc())
     finally:
         db.close()
     return False
Example #6
0
 def __remove_karma(self, name):
     db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST, self.irc.params.ZEO_PORT)
     user = db.users.has_key(name)
     
     if not user:
         self.__register_user(name)
         db.users[name].remove_karma()
         db.close()
         db.commit()
         return db.users[name].karma
     
     db.users[name].remove_karma()
     db.commit()
     db.close()
     return db.users[name].karma
Example #7
0
 def show_karma(self, *args, **kwargs):
     db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST, self.irc.params.ZEO_PORT)
     message = kwargs['data']['message']
     receiver = kwargs['data']['receiver']
     sender = kwargs['data']['sender']
     params = message.split(" ", 3)
     count_args = len(params) - 3
     
     if count_args == 1:
         
         nick = params[3]
         
         user = db.users.has_key(nick)
         if user:
             self.irc.msg_to_channel(self.irc.params.CHANNEL,
                                     "{sender}: {nick} has {karma} points".format(sender=sender, nick=nick,
                                                                                  karma=db.users[nick].karma))
             return
     
     try:
         user = db.users.has_key(sender)
         
         if user:
             
             karma_count = db.users[sender].karma
             point_m = "point"
             if karma_count > 1:
                 point_m = "points"
             
             self.irc.msg_to_channel(self.irc.params.CHANNEL,
                                     "{sender}: You have {karma} {p}".format(sender=sender, p=point_m,
                                                                             karma=karma_count))
         else:
             self.__register_user(sender)
             
             point_m = "point"
             if db.users[sender].karma > 1:
                 point_m = "points"
             
             self.irc.msg_to_channel(self.irc.params.CHANNEL,
                                     "{sender}: You have {karma} {p}".format(sender=sender, p=point_m,
                                                                             karma=db.users[sender].karma))
     except Exception as e:
         print(traceback.print_exc())
         print("Exception: {0}", e)
     finally:
         db.close()
Example #8
0
 def add_new_user(self, *args, **kwargs):
 
     db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST, self.irc.params.ZEO_PORT)
     message = kwargs['data']['message']
     receiver = kwargs['data']['receiver']
     sender = kwargs['data']['sender']
     params = message.split(" ", 3)
     count_args = len(params) - 3
     
     if count_args <= 0 and count_args > 1:
         self.irc.msg_to_channel(self.irc.params.CHANNEL, "{sender}: Invalid Parameters".format(sender=sender))
         return
     
     nick = params[3]
     
     if not self.__is_admin(sender):
         self.irc.msg_to_channel(self.irc.params.CHANNEL,
                                 "{sender}: you're not allowed to do this!".format(sender=nick))
         return
     
     try:
         dt = date.today().strftime("%Y-%m-%d %H:%M:%S")
         db.users[nick] = UserModel(nick, dt)
         db.commit()
         self.irc.msg_to_channel(self.irc.params.CHANNEL,
                                 "{sender}: user {nick} added successfully".format(sender=sender, nick=nick))
     except Exception as ex:
         print(traceback.print_exc())
     finally:
         db.close()
Example #9
0
 def user_add_karma(self, *args, **kwargs):
     db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST, self.irc.params.ZEO_PORT)
     
     message = kwargs['data']['message']
     receiver = kwargs['data']['receiver']
     sender = kwargs['data']['sender']
     params = message.split(" ", 3)
     count_args = len(params) - 3
     
     if count_args <= 0:
         self.irc.msg_to_channel(self.irc.params.CHANNEL, "{sender}: Missing parameter".format(sender=sender))
         return
     
     nick = params[3]
     is_allowed = False
     
     # if not self.is_admin(sender):
     #    self.irc.msg_to_channel(self.irc.params.CHANNEL, "{sender}: you're not allowed to do this!".format(sender=sender))
     #    return
     
     try:
         user = db.users.has_key(nick)
         
         if not user:
             if self.__is_admin(sender):
                 self.__register_user(nick)
                 self.__add_karma(nick)
             else:
                 self.irc.msg_to_channel(self.irc.params.CHANNEL, "{0} Access Denied!".format(sender))
                 return
         else:
             self.__add_karma(nick)
         
         self.__karma_message(nick, "karma++")
         self.irc.msg_to_channel(self.irc.params.CHANNEL,
                                 "{nick} karma++  (total: {karma})".format(nick=nick, karma=db.users[nick].karma))
     
     except Exception as e:
         print(traceback.print_exc())
     finally:
         db.close()
     return
Example #10
0
 def __register_user(self, name):
     db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST, self.irc.params.ZEO_PORT)
     
     user = db.users.has_key(name)
     
     if not user:
         dt = date.today().strftime("%Y-%m-%d %H:%M:%S")
         new_user = UserModel(name, dt)
         
         db.users[name] = new_user
         db.commit()
         db.close()
Example #11
0
    def _listar_piadas(self, *args, **kwargs):
        sender = kwargs['data']['sender']

        db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST,
                    self.irc.params.ZEO_PORT)
        self.irc.msg_to_channel(sender, "Lista de Piadas Cadastradas:")
        time.sleep(2)

        piada_list = {}

        for _, p in enumerate(db.piadas.items(), start=1):

            if sender == p[1].owner:
                piada = p[1]
                id = p[0]
                piada_list[id] = piada.piada

        if not piada_list:
            self.irc.msg_to_channel(
                sender, "Desculpe Voce não cadastrou nenhuma piada")
            return

        for p in piada_list.items():
            print(p)
            msg = " ---- {id} - {piada} ----".format(id=p[0], piada=p[1])
            time.sleep(2)
            self.irc.msg_to_channel(sender, msg)

        self.irc.msg_to_channel(
            sender, "digite ? piadas del <num> para deletar (não tem volta)")
        time.sleep(1)
        self.irc.msg_to_channel(
            sender, "digite ? piadas edit <num> <texto> para editar")
        time.sleep(1)

        db.close()
        pass
Example #12
0
    def cadastrar_nova_piada(self, nick, piada):
        db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST,
                    self.irc.params.ZEO_PORT)

        try:
            if db.piadas:
                size = len(db.piadas)
                db.piadas[size + 1] = PiadaModel(nick, piada[0])

            else:
                db.piadas[0] = PiadaModel(nick, piada[0])

            db.commit()
        except Exception as e:
            pass
        finally:
            db.close()
Example #13
0
    def _edit_piadas(self, *args, **kwargs):
        sender = kwargs['data']['sender']
        message = kwargs['data']['message']
        params = message.split(" ", 3)
        count_args = len(params) - 3

        db = UserDB(self.irc.params.ZEO_DB, self.irc.params.ZEO_HOST,
                    self.irc.params.ZEO_PORT)

        print(params)

        if count_args < 1:
            self.irc.msg_to_channel(
                sender,
                "parametros invalidos, o parametro correto é ? piadas edit <num> <texto> para editar"
            )
            return

        other_params = IrcModuleInterface.remove_spaces(params[3]).split(
            " ", 1)
        other_params = other_params[1].split(" ", 1)

        id = int(other_params[0])
        texto = other_params[1]

        if not db.piadas[id] or db.piadas[id].owner != sender:
            self.irc.msg_to_channel(
                sender, "piada inexistente ou voce nao é o dono dela")
            return

        try:

            if db.piadas[id].owner == sender:
                old = db.piadas[id].piada
                db.piadas[id].piada = texto
                db.commit()
                self.irc.msg_to_channel(
                    sender,
                    "piada \"{old}\" foi trocada por \"{new}\" com sucesso!".
                    format(old=old, new=texto))
        except Exception as e:
            print(e)
            print(traceback.print_exc())
            pass
        finally:
            db.close()
Example #14
0
def get_database():
    if load_db_with_zeo:
        return UserDB('d', 'localhost', 9100)

    return UserDB('d')