def __init__(self, message_entity): self.who = helper.get_who_send(message_entity) self.who_name = helper.sender_name(message_entity) self.conversation = message_entity.getFrom() self.message_entity = message_entity self.valid = False self.message = "" self.text = "" self.file_path = None self.command = None self.predicate = None self.build()
def __init__(self, message_entity): self.message = helper.clean_message(message_entity) self.who = helper.get_who_send(message_entity) self.who_name = helper.sender_name(message_entity) self.conversation = message_entity.getFrom() self.message_entity = message_entity # These two attributes are just easier ways to identify instructions # But they are not really needed since you have the whole message # But I use these a lot so f**k it, lemme be happy # =================================================================== # command is what goes after '!' self.command = helper.command(message_entity) # predicate is what goes after the command self.predicate = helper.predicate(message_entity)
def on_text_message(self, message_entity): # Detect command and the predicate of the message command = "" predicate = "" print("----------------------------------------------") try: command = helper.predicate(message_entity).split(' ', 1)[0] predicate = helper.predicate(message_entity).split(' ', 1)[1] except IndexError: print "Comando sin segundo parametro" # Log # helper.log_mac(message_entity) who = helper.get_who_send(message_entity) conversation = message_entity.getFrom() if helper.is_command(message_entity): main.handle_message(self, command, predicate, message_entity, who, conversation)
def handle_message(instance, command, predicate, message_entity, who, conversation): if command == "hola": who_name = helper.sender_name(message_entity) bot.send_message(instance, "Hola *" + who_name + "*".decode('utf8'), conversation) elif command == "ayuda": answer = """*Lista de comandos*\n !hola\n !noticia <videojuegos,ciencia,series,música,actualidad>\n !chollo\n !anime <temp, temp lista, búsqueda>\n !adv\n !chiste\n !siono \n !ayuda""" bot.send_message(instance, answer, conversation) elif command == "siono": yesno = YesNo(instance, conversation) yesno.send_yesno() elif command == "anime": anime = None person = helper.get_who_send(message_entity) if predicate: if predicate == "temp": anime = Anime(instance, conversation, person, param='season') elif predicate == "temp lista": anime = Anime(instance, conversation, person, param='season_list') elif predicate.isdigit(): anime = Anime(instance, conversation, person, param='anime_num', num=predicate) else: commands = predicate.split() if len(commands) == 2 and commands[0] == "temp" and commands[ 1].isdigit(): anime = Anime(instance, conversation, person, param='season_num', num=commands[1]) # Buscar anime else: anime = Anime(instance, conversation, person, param=predicate) else: #Anime aleatorio anime = Anime(instance, conversation, person) if (anime): anime.send_anime() elif command == "chollo": chollo = Chollo(instance, conversation) chollo.build() chollo.send_chollo() # elif command == "frase": # quote = Quote(instance, conversation) # quote.send_quote() elif command == "chiste": chiste = Chiste(instance, conversation) chiste.send_chiste() # elif command == "wur": # wur = WUR(instance, conversation) # wur.build() # wur.send_wur() elif command == "adv": adv = ADV(instance, conversation) adv.send_adv() elif command == "noticia": l = ['videojuegos', 'ciencia', 'series', 'música', 'actualidad'] if predicate.encode('utf8') in l: noticia = Noticias(instance, conversation, predicate) noticia.send_noticia() #cambia la foto del perfil elif command == "fotoPerfil": path = get_avatar() bot.profile_set_picture(instance, path) #cambia el estado del perfil elif command == "estado": if predicate: bot.profile_setStatus(instance, predicate) else: #return answer = cleverbot_answer(command + " " + predicate) bot.send_message(instance, answer, conversation)
def __init__(self, message_entity): self.who = helper.get_who_send(message_entity) self.conversation = message_entity.getFrom() self.who_name = helper.sender_name(message_entity)