def onMessage(self, author_id=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, **kwargs): # Mark message as read self.markAsRead(author_id) # Print info on consoleka log.info("Message {} from {} in {}".format(message_object, thread_id, thread_type)) # Message Text msgText = message_object.text reply = 'hello world' # Send message if author_id != self.uid: self.send(Message(text=reply), thread_id=thread_id, thread_type=thread_type) # Mark message as delivered self.markAsDelivered(author_id, thread_id)
def onMessage(self, mid=None, author_id=None, message=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, ts=None, metadata=None, msg=None): # igrone your own message if (author_id == self.uid): return self.markAsDelivered(thread_id, message_object.uid) self.delay() self.markAsRead(thread_id) self.delay() #handle name = self.get_name_by_user_id(author_id) text = message_object.text log.info('{}: {}'.format(name, text)) text_to_speech.say(name + ' nói ' + text)
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): self.markAsDelivered(thread_id, message_object.uid) self.markAsRead(thread_id) data = {} with open('stopGroups', 'r') as stopGroups: data = json.load(stopGroups) if thread_id in data: return log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) if author_id == self.uid: return words = message_object.text.split() bad_words = [] regex = re.compile('[^a-zA-Z\']') for word in words: word = regex.sub('', word) if Dictionary.check(word) == False: bad_words.append(word) if len(bad_words) != 0: suggested_strings = [] for bad_word in bad_words: suggested_strings.append("Incorrect Word: " + bad_word + ". Suggested Words: " + ", ".join(Dictionary.suggest(bad_word))) message = "\n".join(suggested_strings) message = message_intros[random.randint(0, len(message_intros)-1)].format(self.fetchUserInfo(author_id)[author_id].first_name) + "\n" + message self.send(Message(text=message), thread_id = thread_id, thread_type = thread_type)
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): if author_id != self.uid: self.markAsDelivered(author_id, thread_id) self.markAsRead(author_id) thread: Thread = Thread(thread_id, thread_type, self.lookupThread(thread_id).name) message: Message = Message(message_object.text, author_id, self.lookupUser(author_id).first_name, thread) client: Client = Client(self) try: log.info( f'\n{message.author_name} in thread {thread.thread_name} said:\n{indent(message.text)}' ) for handler in self.handlers: if (handler.couldHandle(message)): try: log.info(f'Using: {handler.name()}') handler.handle(message, client) except RuntimeError as e: client.sendText(thread, f'Error: {e}') break except: client.sendText(thread, 'X_X') raise
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): self.markAsDelivered(author_id, thread_id) self.markAsRead(author_id) log.info(self.states) if self.states.get(author_id,0) == 0 and author_id != self.uid: self.thread_id = thread_id self.send(Message(text = "Hello, welcome to deepdoc. What is your name?"), thread_id=thread_id, thread_type=thread_type) self.states[author_id] = 1 elif self.states.get(author_id,0) == 1 and author_id != self.uid: self.HandleReplyName(message_object, thread_id, thread_type, author_id) elif self.states.get(author_id,0) == 2 and author_id != self.uid: self.HandleReplyMatter(message_object, thread_id, thread_type,author_id) elif self.states.get(author_id,0) == 3 and author_id != self.uid: self.HandleReplyScale(message_object, thread_id, thread_type,author_id) elif self.states.get(author_id,0) == 4 and author_id != self.uid: self.HandleReplyTime(message_object, thread_id, thread_type,author_id) elif author_id != self.uid: self.send(Message(text = "The doctor is busy and talking to someone else. Try again in 5 minuites."), thread_id=thread_id, thread_type=thread_type)
def onMessage(self, mid, author_id, message_object, thread_id, thread_type, ts, metadata, msg, **kwargs): self.markAsDelivered(author_id, thread_id) self.markAsRead(author_id) log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) # If message matches activation string send message if (message_object.text == cfg.activation['phrase']): ## Send the message self.send(Message(text=self.getReply(0)), thread_id=thread_id, thread_type=thread_type) # If message matches story activation send story if (message_object.text == cfg.activation['phrase'] + " -story"): ## Send the story self.send(Message(text=self.getReply(1)), thread_id=thread_id, thread_type=thread_type) # If message matches info activation, print info if (message_object.text == cfg.activation['phrase'] + " -info"): # Send info self.send(Message(text=cfg.info['desc']), thread_id=thread_id, thread_type=thread_type)
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): # Don't do anything with messages sendt by you if author_id == self.uid: return self.markAsDelivered(thread_id, message_object.uid) # self.markAsRead(thread_id) log.info("{} fra: {} - from {} in {}".format(message_object, author_id, thread_id, thread_type.name)) username = "" ## Find the username from author_id if author_id in users: username = users[author_id] else: username = author_id ## Set a gateway from the thread_id gateway = "FBgateway" if thread_id in threads: gateway = threads[thread_id] sendMsg(username, gateway, message_object.text)
def onMessage(self, author_id=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, **kwargs): # Mark message as read self.markAsRead(author_id) # Print info on console log.info("Message {} from {} in {}".format(message_object, thread_id, thread_type)) msgText = message_object.text if type(msgText) != str: msgText = "..." # print("\n\n\n\n" + msgText + " \n\n\n\n\n") reply = getRply(msgText) if "he will reach out" in reply: f = open("newSentence.txt", "a") f.write(msgText + "\n") f.close() # Send message if author_id != self.uid: self.send(Message(text=reply), thread_id=thread_id, thread_type=thread_type) # Mark message as delivered self.markAsDelivered(author_id, thread_id)
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)) # If you're not the author, echo if author_id != self.uid: m = Message() m.text = message_object.text text_msg = "\nthis was sent from a bot cuz Armaan doesn't feel like responding" txt_msg = "".join( list( map( lambda x: x.upper() if random.random() > 0.5 else x.lower(), list(text_msg)))) m.text = txt_msg self.reactToMessage(message_object.uid, MessageReaction.WOW) self.sendRemoteImage( "https://usatftw.files.wordpress.com/2017/05/spongebob.jpg", thread_id=thread_id, thread_type=thread_type) self.send(m, thread_id=thread_id, thread_type=thread_type)
def onMessage(self, mid, author_id, message_object, thread_id, thread_type, ts, metadata, msg, **kwargs): emotion_list = ['YES', 'SMILE'] list = random.choice(emotion_list) self.markAsDelivered(thread_id, message_object.uid) self.markAsRead(thread_id) log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) print(author_id) print(message_object) print(thread_type) print(thread_id) print(self) print(mid) print(ts) print(metadata) print(msg) if thread_type.name == "GROUP" and (author_id == mum or author_id == dad): if list == 'YES': client.reactToMessage(mid, MessageReaction.YES) if list == 'SMILE': client.reactToMessage(mid, MessageReaction.SMILE) if author_id == self.uid: self.send(Message(text='yo yo yo yo yo yo yo'), thread_id=client.uid, thread_type=ThreadType.USER) print("111111111111") if message_object.text == "testing": print("222222222222") if thread_type.name == "USER": print("333333333333")
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): self.markAsDelivered(author_id, thread_id) self.markAsRead(author_id) log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) # If you're not the author, echo if author_id != self.uid: msg = { "data": { "utterances": [message_object.text], "lang": "en-us" }, "type": "recognizer_loop:utterance", "context": { "source": self.protocol.peer, "destinatary": "https_server", "platform": platform, "user": author_id, "fb_chat_id": author_id, "target": "fbchat" } } msg = json.dumps(msg) self.protocol.clients[author_id] = {"type": thread_type} self.protocol.sendMessage(msg, False)
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)) if author_id != self.uid: if message_object.text: if message_object.text == '/Getid' or message_object.text == '/getid': self.send(Message(text=message_object.author), thread_id=thread_id, thread_type=thread_type) elif '/tuvi' in message_object.text: tuoi = message_object.text[message_object.text. index('/tuvi') + len('/tuvi'):] tuvi = TuVi() loi_phan = tuvi.con_giap(Cgiap=tuoi) self.send(Message(text=loi_phan), thread_id=thread_id, thread_type=thread_type) else: self.send(Message( text= '\n \n🙂 Tôi là Nguyễn Mạnh. \n- Tôi sẽ rep sau khi đi công việc về \n- Nếu xem tử vi gõ /tuvi <tuổi>; ví dụ: /tuvi sửu. \n- Tin nhắn của bạn: {0}' .format(message_object.text)), thread_id=thread_id, thread_type=thread_type)
def reaction_removed_handler(client, mid, author_id, thread_id, thread_type, ts, msg): global emotionmap global reaction_history if author_id != client.uid: # update emotion map message = client.fetchMessageInfo(mid, thread_id=thread_id) pol = SentimentIntensityAnalyzer().polarity_scores(message.text) try: reaction = reaction_history[(author_id, mid)] except KeyError: # emotion history cleared before reaction removed return react_sentiment = emotionmap[reaction][0] react_sentiment = [ emotionmap[reaction][1] * i for i in react_sentiment ] react_sentiment = [ i - j for i, j in zip(react_sentiment, list(pol.values())[:-1][::-1]) ] emotionmap[reaction][1] -= 1 react_sentiment = [ float(i / emotionmap[reaction][1]) for i in react_sentiment ] emotionmap[reaction][0] = react_sentiment log.info(f"Removed sentiment {pol} for message {mid} to {reaction}.") log.info(emotionmap)
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('Đã nhận được tin nhắn từ {} với nội dung là: {}'.format(author_id, message_object)) if author_id != self.uid: if message_object.text: if message_object.text == '/Getid' or message_object.text == '/getid': self.send(Message(text=message_object.author), thread_id=thread_id, thread_type=thread_type) elif '/simi' in message_object.text: self.ass += 2 self.send(Message(text="Hi i'm simsimi"), thread_id=thread_id, thread_type=thread_type) elif self.ass > 1 and message_object.text: mess = message_object.text simmi = Simi() simi_text = simmi.simi(maxii=mess) self.send(Message(text=simi_text), thread_id=thread_id, thread_type=thread_type) elif '/timidol' in message_object.text: self.idol_seach += 2 self.send(Message(text="Nhập tên đi bạn hiền"), thread_id=thread_id, thread_type=thread_type) elif self.idol_seach > 1 and message_object.text: mess = message_object.text idol = JavIdol().look_up_actress(mess) counts = len(idol) self.send(Message(text='Found {} babes named "{}"'.format(counts, mess)), thread_id=thread_id, thread_type=thread_type) self.send(Message(text="{:<7} | {:17} | {}\t".format("ID", "Actress Name", "Japanese Name")), thread_id=thread_id, thread_type=thread_type) for i in range(counts): actress_id = idol[i]['id'] actress_name = idol[i]['name'] actress_japName = idol[i]['japanName'] self.send(Message(text="-Id idol: {:<7} \n-Tên idol: {:17} \n-Tên nhật: {}\t".format(actress_id, actress_name, actress_japName)), thread_id=thread_id, thread_type=thread_type) elif '/timmovies' in message_object.text: self.movies_seach += 2 self.send(Message(text="Nhập ID idol đi tui tìm cho hihi"), thread_id=thread_id, thread_type=thread_type) elif self.movies_seach > 1 and message_object.text: mess = message_object.text movies = JavIdol().look_up_movies(mess) counts = len(movies) self.send(Message(text="Found {} videos for {}".format(counts, mess)), thread_id=thread_id, thread_type=thread_type) for i in range(counts): video_title = movies[i]['name'] if len(movies[i]['name']) > 50: video_title = video_title.replace(video_title[49:], '...') else: video_title = movies[i]['name'] siteUrl = movies[i]['siteUrl'] video_code = siteUrl[(siteUrl.find("cid=") + 4):(len(siteUrl) - 1)].replace('00', '-', 1).upper() message = "\n-Code: {:<15} \n-Tiêu đề: {}".format(video_code, video_title) self.send(Message(text=message), thread_id=thread_id, thread_type=thread_type) else: self.send(Message( text='\n \n Tôi là Tú. \n- Tôi sẽ rep sau khi đi công việc về \n- Nếu muốn trò chuyện với simsimi gõ /simi. \n- Tìm idol gõ /timidol \n- Tìm phim gõ /timmovies \n- Tin nhắn của bạn: {0}'.format( message_object.text)), thread_id=thread_id, thread_type=thread_type )
def sendMeme(self, thread_id, thread_type=ThreadType.GROUP): memePath = str(confgr.memesDIR + random.choice(os.listdir(confgr.memesDIR))) self.sendLocalImage(memePath, thread_id=thread_id, thread_type=thread_type) log.info("Sending %s meme", memePath)
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): message_info = {'author_id': author_id, 'message_object': message_object, 'thread_id': thread_id, 'thread_type': thread_type} # the dict containing all the message info; It's later passed to the command handling methods self.markAsDelivered(thread_id, message_object.uid) # mark the message as delivered log.info("{} from {} of type {}".format(message_object.text, thread_id, thread_type.name)) # log into the console what's the message, from which thread it's from, and what's it's thread type try: message_text = message_object.text.lower() except: message_text = message_object.text if author_id != self.uid and re.search('^!', message_text): # if the message begins with an '!' message_components = re.findall(r'[\w,]+', message_text) # split up the message command = message_components[0] # first part of the message is the command if command == 'calc': arguments = re.findall(r'[0-9]+|[\*\/\+\-]+', message_text) else: arguments = [i for i in message_components[1:]] # the rest are the arguments if arguments == []: arguments.append(True) if command in self.command_list: # if such a command exists self.command_list[command](arguments, message_info) # call it with the arguments and the message info else: # self.command_unrecognized(message_info) # if not, call command_unrecognized()
def onMessage(self, author_id=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, **kwargs): # Mark message as read self.markAsRead(author_id) # Print info on console log.info("Message {} from {} in {}".format(message_object, thread_id, thread_type)) # Establish conn self.apiaiCon() # Message Text msgText = message_object.text # Request query/reply for the msg received self.request.query = msgText # Get the response which is a json object response = self.request.getresponse().read() # Convert json obect to a list json_response = response.decode('utf-8') obj = json.loads(json_response) # Get reply from the list reply = obj['result']['fulfillment']['speech'] print("Reply ---", reply) # Send message if author_id != self.uid: self.send(Message(text=reply), thread_id=thread_id, thread_type=thread_type) # Mark message as delivered self.markAsDelivered(author_id, thread_id)
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) if author_id != self.uid: Kiusatav(author_id, message_object, thread_id, thread_type, **kwargs)
def onPersonRemoved(self, removed_id, author_id, thread_id, **kwargs): # No point in trying to add ourself if (old_thread_id == thread_id and removed_id != self.uid and author_id != self.uid): log.info( "{} got removed. They will be re-added".format(removed_id)) self.addUsersToGroup(removed_id, thread_id=thread_id)
def reaction_added_handler(client, mid, reaction, author_id, thread_id, thread_type): global emotionmap global reaction_history if author_id != client.uid: # add to reaction reaction history reaction_history[(author_id, mid)] = reaction # update emotion map pol = SentimentIntensityAnalyzer().polarity_scores( client.fetchMessageInfo(mid, thread_id=thread_id).text) react_sentiment = emotionmap[reaction][0] react_sentiment = [ emotionmap[reaction][1] * i for i in react_sentiment ] react_sentiment = [ i + j for i, j in zip(react_sentiment, list(pol.values())[:-1][::-1]) ] emotionmap[reaction][1] += 1 react_sentiment = [ float(i / emotionmap[reaction][1]) for i in react_sentiment ] emotionmap[reaction][0] = react_sentiment log.info(f"Added sentiment {pol} for message {mid} to {reaction}.") log.info(emotionmap)
def onColorChange(self, author_id, new_color, thread_id, thread_type, **kwargs): if old_thread_id == thread_id and old_color != new_color: log.info( "{} changed the thread color. It will be changed back".format( author_id)) self.changeThreadColor(old_color, thread_id=thread_id)
def onEmojiChange(self, author_id, new_emoji, thread_id, thread_type, **kwargs): if old_thread_id == thread_id and new_emoji != old_emoji: log.info( "{} changed the thread emoji. It will be changed back".format( author_id)) self.changeThreadEmoji(old_emoji, thread_id=thread_id)
def onMessage(self, client, mid=None, author_id=None, message=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, ts=None, metadata=None, msg=None): """ Called when the client is listening, and somebody sends a message :param mid: The message ID :param author_id: The ID of the author :param message: (deprecated. Use `message_object.text` instead) :param message_object: The message (As a `Message` object) :param thread_id: Thread ID that the message was sent to. See :ref:`intro_threads` :param thread_type: Type of thread that the message was sent to. See :ref:`intro_threads` :param ts: The timestamp of the message :param metadata: Extra metadata about the message :param msg: A full set of the data recieved :type message_object: models.Message :type thread_type: models.ThreadType """ log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name))
def onMessage(self, mid=None, author_id=None, message=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, ts=None, metadata=None, msg=None, **kwargs): # self.markAsRead(author_id) log.info("Message {} from {} in {}".format(message_object, thread_id, thread_type)) self.apiaiCon() msgText = message_object.text self.request.query = msgText response = self.request.getresponse() obj = json.load(response) reply = obj['result']['fulfillment']['speech'] if author_id != self.uid: self.send(Message(text=reply), thread_id=thread_id, thread_type=thread_type) self.markAsDelivered(author_id, thread_id)
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)) msgText = message_object.text if (msgText.upper() == "START"): reply = "Starting the programme..." os.system("systemctl start sisc.service") elif (msgText.upper() == "STOP"): reply = "Stopping the programme..." os.system("systemctl stop sisc.service") elif (msgText.upper() == "HELP"): reply = "Commands:\nStart\n\t-start the progamme\nStop\n\t-stop the programme" else: reply = "Invalid command. Type 'Help' for more information." if author_id != self.uid: self.send(Message(text=reply), thread_id=thread_id, thread_type=thread_type)
def onMessage(self, author_id=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, **kwargs): self.markAsDelivered(author_id, thread_id) log.info("Message {} from {} in {}".format(message_object, thread_id, thread_type)) #check if the message is a text if message_object.text: text = message_object.text if thread_type != ThreadType.GROUP: if author_id != self.uid: #searching for answer to reply for answer in answers: if re.search(answer["pattern"], text, flags=re.IGNORECASE): self.send(Message(text=answer["reponse"]), thread_id=thread_id, thread_type=thread_type) break else: #if it's not a text then reply back the same message if author_id != self.uid: self.send(message_object, thread_id=thread_id, thread_type=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) global want log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) if author_id == victimsUID: if 'lõpeta ära' in message_object.text or 'Lõpeta ära' in message_object.text: if self.want: self.send(Message(text='lÕpeTa äRa'), thread_id=thread_id, thread_type=thread_type) else: self.send(Message(text='Lõpeta oma elu ära'), thread_id=thread_id, thread_type=thread_type) elif 'ma kutsun ema' in message_object.text or 'Ma kutsun ema' in message_object.text: if self.want: self.send(Message(text='Olgu olgu ma lõpetan'), thread_id=thread_id, thread_type=thread_type) self.send(Message(text='Pussy'), thread_id=thread_id, thread_type=thread_type) self.want = False else: self.send(Message(text='Mida sa hüppad, ma pole midagi teinudki'), thread_id=thread_id, thread_type=thread_type) elif 'kiusa mind' in message_object.text or 'Kiusa mind' in message_object.text: self.send(Message(text='( ͡° ͜ʖ ͡°) Nice'), thread_id=thread_id, thread_type=thread_type) self.want = True elif self.want: self.send(message_object, thread_id=thread_id, thread_type=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) url = "https://xingluke.api.stdlib.com/wuphf-twilio@dev/" #requests.post(url, data={"phone": phone, "sender": sender, "sender": sender}) log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) #print(type(message_object)) #print(message_object.text) msg = message_object.text #print(self.fetchAllUsersFromThreads([thread_id])) #print(type(author_id)) #print(author_id) #print(type(thread_type)) obj = { 'msg': msg, 'platform': platform, 'author': author_id, 'phone': phone } requests.post(url, data=obj)
def sendReply(): #Handle replying log.info("Sending message to " + sender_name + ", text:" + reply) #Send the message self.send(Message(text=reply), thread_id=thread_id, thread_type=thread_type)
def onMessage(self, author_id=None,messaege_object=None,thread_id=None, thread_type=ThreadType.USER,**kwargs): self.markAsRead(author_id) log.info("Message {} from {} in {}".format(messaege_object,thread_id,thread_type)) msgText=messaege_object.msgText reply ='Hello world' if author_id!=self.uid: self.send(Message(text=reply, thread_id=thread_id,thread_type=thread_type)) self.markAsDelivered(author_id,thread_id)