def message(): vid = '<iframe id="video" width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>' if 'Rick astley' in request.form.get("message"): return vid elif 'I love cs50' in request.form.get("message"): return vid return analyze(request.form.get("message"))
def on_pubmsg(self, connection, event): args = event.arguments[0].split(":", 1) if len(args) > 1 and irc.strings.lower(args[0]) == irc.strings.lower( self.connection.get_nickname()): connection.privmsg( self.channel, "{0}: {1}".format(event.source.nick, analyze(args[1]).strip())) return
def muc_message(self, msg): # Cmopose data and write message to SQLite DB nick_name = unicode(msg['mucnick']) # User nick sowed in chat room full_jit = unicode(msg['from']) # Like [email protected]/UserName message = unicode(msg['body']) # Message body query = ( time.time(), full_jit, nick_name, message, ) self.write_log(query) # Disable self-interaction if msg['mucnick'] == self.nick: return # Try to run command if msg['body'].startswith(self.nick): tokens = msg['body'].split() if len(tokens) > 1: command = tokens[1] if command == 'ping': self.try_ping(msg['from'], msg['mucnick']) return to_strip = msg['body'] stripped = to_strip[len(tokens[0]):] elz_answer = elz.analyze(to_strip) self.send_message(mto="*****@*****.**", mbody="%s: %s " % (msg['mucnick'], elz_answer), mtype='groupchat') elif "http" in msg['body']: self.try_say_url_info(msg['body'], msg['from'])
def handle_my_custom_event(json, model=model, methods=['GET', 'POST']): print('received my event: ' + str(json)) socketio.emit('my response', json, callback=messageReceived) if json['message'] != '': global message_list message_list += json['message'] + ' ' global message_count message_count += 1 flag = 0 if message_count == 3: message_count = 0 flag = 1 eliza_ponders = { "user_name" : "Eliza", "message" : 'Hmmm ...' } socketio.emit('my response', eliza_ponders, callback=messageReceived) eliza_msg = quote_mapper.getQuote(message_list, model) message_list = '' else: eliza_msg = analyze(json['message'], version='1') eliza_says = { "user_name" : "Eliza", "message" : eliza_msg } socketio.emit('my response', eliza_says, callback=messageReceived) if flag==1: flag = 0 img_loc, img_name = get_image_location(eliza_msg,"withimages_wiseoldsayings.json") if img_loc != "" and img_name != "": img_msg = { "message" : img_loc+img_name } socketio.emit('image handler', img_msg, callback=messageReceived) img_loc = "" img_name = ""
def handle_messages(): # variables global site global chatAl global loc global lat global lon context0 = {} count = 0 print "Handling Messages" payload = request.get_data() print payload data = json.loads(payload) msgev = data["entry"][0]["messaging"] for event in msgev: if "message" in event: if "attachments" in event["message"]: for atta in event["message"]["attachments"]: if "payload" in atta: if "coordinates" in atta["payload"]: print (atta["payload"]["coordinates"]) lat = atta["payload"]["coordinates"]["lat"] lon = atta["payload"]["coordinates"]["long"] f = open("geo.txt", "w") f.write(str(lat) + "," + str(lon)) send_message(PAT, event["sender"]["id"], str(atta["payload"]["coordinates"])) send_message(PAT, event["sender"]["id"], "Coordinates Recieved") loc = True return "ok" # checks if chat option is on or not for sender, message in messaging_events(payload): # chatting with eliza ai if chatAl: # end chat if message == "bye": chatAl = False # chat and get response m1 = eliza.analyze(message) print ("Trying to send...") send_message(PAT, sender, m1) print ("Probably sent") # not chatting. Use Wit.AI else: print "Incoming from %s: %s" % (sender, message) print type(message) resp = client.message(message) # get response from wit.ai print (resp) # decides what type of response it is if u"entities" in resp: resp = resp[u"entities"] if u"intent" in resp: resp = resp[u"intent"] else: send_message(PAT, sender, "I'm sorry. I couldn't understand you. Please rephrase that.") return "ok" else: send_message(PAT, sender, "I'm sorry. I couldn't understand you. Please rephrase that.") return "ok" # if response is understood, get it resp = resp[0] print ("Response type is.... " + resp[u"value"]) # id type of response and run correct method if u"value" in resp: # grocery response to get list of groceries. From imported class if resp[u"value"] == "grocery": message = get_cooking() while len(message) > 300: msg2 = message[:300] message = message[300:] send_message(PAT, sender, msg2) send_message(PAT, sender, message) send_message(PAT, sender, site) # get xkcd comic link, poorly implemented rn elif resp[u"value"] == "xkcd": message = "http://xkcd.com/" send_message(PAT, sender, message) # Location data to switch modes elif resp[u"value"] == "restaurants": restaurants = "" print ("rest method") message = get_restaurants(sender) if message["status"] == "OK": for place in message["results"]: if "permanently_closed" not in place or place["permanently_closed"] is False: # if 'opennow' in place and place['opennow'] is True: restaurant = "Name: " + str(place["name"]) + " Rating: " if "rating" in place: restaurant += str(place["rating"]) else: restaurant += "None" send_message(PAT, sender, restaurant) else: send_message(PAT, sender, "Error") # message = str(get_restaurants(sender)) # while( len(message) > 300): # msg2 = message[:300] # message = message[300:] # send_message(PAT, sender, msg2) # send_message(PAT, sender, message) # else: # send_message(PAT, sender, "Not ok") # else: # send_message(PAT, sender, "Enter your location:") # loc = True time.sleep(6) # greetings response. Usually used to start up elif resp[u"value"] == "greetings": print ("This resp greetings RIGHT HERE") resp = client.converse("my-user-session-42", message, context0) print ("This resp greetings ") print (resp) while "msg" not in resp: resp = client.converse("my-user-session-42", message, context0) print ("This resp HERE ") print (resp) print ("the msg is " + resp["msg"]) message = str(resp["msg"]) print ("Trying to send...") send_message(PAT, sender, message) print ("Probably sent") # talk sets chatAI to true and allows chat with eliza. Use "bye" to end elif resp[u"value"] == "talk": chatAl = True send_message(PAT, sender, "Okay, what's up?") # not working atm elif resp[u"value"] == "weather": # resp = client.run_actions('my-user-session-42',textmsg, context0) print ("This resp weather ") # print (resp) # while('foodList' not in resp): # resp = client.run_actions('my-user-session-42',textmsg, context0) # print ("This resp ") # print(resp) # voice.send_sms(msg[u'from'],str(resp['forecast'])) message = "weather" send_message(PAT, sender, message) # catch all for other intents else: print ("Else") resp = client.converse("my-user-session-42", message, context0) while "msg" not in resp and count <= 10: resp = client.converse("my-user-session-42", message, context0) print ("This resp HERE ") print (resp) print ("the msg is " + resp["msg"]) message = str(resp["msg"]) print ("Trying to send...") send_message(PAT, sender, message) return "ok"
def _compute_reply(self, tid, message): cleverbot = self._init_cleverbot(tid) try: return cleverbot.say(message) except: return eliza.analyze(message)
def talk(bot, update): reply = eliza.analyze(update.message.text) bot.send_message(chat_id=update.message.chat_id, text=reply)