def onMessage(self, mid=None, author_id=None, message=None, message_object=None, thread_id=None, thread_type=models.ThreadType.USER, ts=None, metadata=None, msg=None): self.message_event(message_object, self.parser.event_flag) if message_object.author != self.core_data[ "owner"] or message_object.text.startswith('['): return response, flag = self.parser.execute(message_object.text) if ResponseFlag.KYS in flag: self.kill(thread_id, thread_type) elif ResponseFlag.NOT_FOUND in flag: self.command_not_found(thread_id, thread_type) elif ResponseFlag.WRONG_REQUEST in flag: return elif ResponseFlag.OKAY in flag: send_msg = models.Message('[' + str(response).rstrip() + ']') self.send(send_msg, thread_id, thread_type)
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): self.markAsDelivered(thread_id, message_object.uid) self.markAsRead(thread_id) log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) #SI ESTÁ EN LOS COMANDOS DE EL ARCHIVO if message_object.text in self.comandos: c = models.Message(self.comandos[message_object.text]) self.send(c, thread_id=thread_id, thread_type=thread_type) log.info("Comando {} usado".format(message_object.text)) if message_object.text == "ADIOS": self.send(models.Message("Adios bb de luz"), thread_id=thread_id, thread_type=thread_type) log.info("ÑeroBot está muerto") self.stopListening() print(enumerate())
def message2(self, message): if self.game is False: return self.client.send( model.Message(text=message), thread_id=self.thread2, thread_type=self.thread_type2)
def message(self, message): if self.game is False: return if self.thread1 == self.thread2: self.client.send( model.Message(text=message), thread_id=self.thread1, thread_type=self.thread_type1) else: self.client.send( model.Message(text=message), thread_id=self.thread1, thread_type=self.thread_type1) self.client.send( model.Message(text=message), thread_id=self.thread2, thread_type=self.thread_type2)
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): self.log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) if thread_type == models.ThreadType.USER and message_object.text and message_object.text[0] != "$": self.markAsDelivered(thread_id, message_object.uid) self.markAsRead(thread_id) self.message_queue.put((message_object.text, author_id, "FB")) time.sleep(0.5) if not self.response_queue.empty(): response, author = self.response_queue.get() else: response, author = None, None if response is not None and (self.debug_flag.is_set() or self.uid == thread_id): self.send(models.Message(text='$ ' + response), thread_id=thread_id, thread_type=thread_type)
def send(self, text, thread, mentions=None, reply=None): """Send a message to a specified thread""" # TODO: more settings (in kwargs), like attachments if thread is None: raise Exception('Could not send message: `thread` is None') message = None if mentions is not None: message = models.Message.formatMentions(text, *mentions) if message is None: message = models.Message(text=text) if reply is not None: message.reply_to_id = reply log.info('Sending a message to thread %s', repr(thread)) return self.fbchat_client.send(message, thread_id=thread.id_, thread_type=thread.type_)
def handlerfn(self, message, bot): if not self.uids: self.uids = bot.fbchat_client.\ fetchGroupInfo(self.group.id_)[self.group.id_]\ .participants alphabet = list( 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') out = '' offset = 0 mentions = [] for i in self.uids: mentions.append(models.Mention(i, offset=offset, length=2)) out = out + '@' + alphabet[offset // 3] + ' ' offset += 3 bot.fbchat_client.send(models.Message(text=out, mentions=mentions), thread_type=self.group.type_, thread_id=self.group.id_)
def message(self, message): client.send(model.Message(text=str(message)), thread_id=self.thread_id, thread_type=self.thread_type)
def onMessage(self, author_id=None, message_object=None, thread_id=None, thread_type=models.ThreadType.USER, **kwargs): """ :param author_id: :param message_object: :param thread_id: :param thread_type: :param kwargs: :return: """ bad_words = ['berlin', 'menfred', 'harry', 'styles'] # toggle = self.fetchThreadMessages(thread_id=self.uid, limit=1) # Own account if message_object.text is not None: # print('author', author_id, 'message object', message_object, 'threadid', thread_id) if author_id == users['yun_ann']: # If some bad words are said text = message_object.text.lower() angry = functools.reduce(lambda x, y: x or y in text, bad_words, False) if angry: # Answer it self.sleep() self.send( message=models.Message(text='幹恁娘雞掰', reply_to_id=message_object.uid), thread_id=thread_id, thread_type=thread_type, ) # Angry react self.sleep() self.reactToMessage( message_id=message_object.uid, reaction=models.MessageReaction.ANGRY ) if is_lang(message_object.text, 'es'): # If some Spanish is written self.sleep() self.reactToMessage( message_id=message_object.uid, reaction=models.MessageReaction.ANGRY ) self.sleep() self.send( message=models.Message( text='我们说中文', reply_to_id=message_object.uid ), thread_id=thread_id, thread_type=thread_type, ) elif is_lang(message_object.text, 'fr'): # If some French is written self.sleep() self.reactToMessage( message_id=message_object.uid, reaction=models.MessageReaction.HEART ) if 'usually' in message_object.text.lower(): self.sleep() self.send( message=models.Message( text='It depends', reply_to_id=message_object.uid ), thread_id=thread_id, thread_type=thread_type, )
def command_not_found(self, thread_id, thread_type): """Sends a "command not found" message""" info_msg = models.Message("[Command not found! Use " + self.core_data["prefix"] + "list_cmd to show available commands]") self.send(info_msg, thread_id, thread_type)
def kill(self, thread_id, thread_type): """Stop the selfbot, with message""" exit_msg = models.Message("[Stopping the selfbot]") self.send(exit_msg, thread_id, thread_type) self.stopListening()
def send_message_to_person(self, user, message): self.__client.send(models.Message(text=message), thread_id = user.uid, thread_type = models.ThreadType.USER)