def handle(msg): global is_chatting global tweet_client chat_id = msg['chat']['id'] command = msg['text'] print 'Got command: %s' % command if command == '/hello' and not is_chatting: bot.sendMessage(chat_id, 'Hello, how are you?') elif command == '/timeline' and not is_chatting: bot.sendMessage( chat_id, '\n'.join([ message.text for message in tweet_client.handle.home_timeline() ])) elif command.split('=')[0] == '/tweet' and not is_chatting: try: tweet_client.hitme(command.split('=')[1] + ' #mika') bot.sendMessage(chat_id, 'Your message tweeted successfully') except: bot.sendMessage( chat_id, 'There is some problem tweeting! Try after some time') elif command == '/chat': is_chatting = True bot.sendMessage(chat_id, 'Hi I am Iesha. Who are You?') elif command == '/stopchat': is_chatting = False bot.sendMessage(chat_id, 'Bye Bye. take care!') elif not command.startswith('/') and is_chatting: bot.sendMessage(chat_id, iesha_chatbot.respond(command)) else: pass
def handle(msg): global is_chatting global tweet_client chat_id = msg['chat']['id'] command = msg['text'] print 'Got command: %s' % command if command == '/hello' and not is_chatting: bot.sendMessage(chat_id, 'Hello, how are you?') elif command == '/timeline' and not is_chatting: bot.sendMessage(chat_id, '\n'.join([message.text for message in tweet_client.handle.home_timeline()])) elif command.split('=')[0] == '/tweet' and not is_chatting: try: tweet_client.hitme(command.split('=')[1] + ' #mika') bot.sendMessage(chat_id, 'Your message tweeted successfully') except: bot.sendMessage(chat_id, 'There is some problem tweeting! Try after some time') elif command == '/chat': is_chatting = True bot.sendMessage(chat_id, 'Hi I am Iesha. Who are You?') elif command == '/stopchat': is_chatting = False bot.sendMessage(chat_id, 'Bye Bye. take care!') elif not command.startswith('/') and is_chatting: bot.sendMessage(chat_id, iesha_chatbot.respond(command)) else: pass
def handle(msg): global is_chatting chat_id = msg["chat"]["id"] command = msg["text"] print "Got command: %s" % command if command == "/hello": bot.sendMessage(chat_id, "Hello, how are you?") if command == "/chat": is_chatting = True bot.sendMessage(chat_id, "Hi I am Iesha. Who are You?") elif command == "/stopchat": is_chatting = False bot.sendMessage(chat_id, "Bye Bye. take care!") elif not command.startswith("/") and is_chatting: bot.sendMessage(chat_id, iesha_chatbot.respond(command)) else: pass
def received_im_msg(account, name, message, conversation, flags): global is_chatting print "Recieved message:" ,message print "account=[" + str(account) + "], name=[" + str(name) + "], message=[" + str(message) + "], conversation=[" + str(conversation) + "], flags=[" + str(flags) + "]" text = "%s says %s" % (name, message) if not conversation: conversation = purple.PurpleConversationNew(1, account, name) im = purple.PurpleConversationGetImData(conversation) print "im=[" + str(im) + "]" if message == 'hello' and not is_chatting: purple.PurpleConvImSend(im, 'Hello, how are you?') if message == '/chat': is_chatting = True purple.PurpleConvImSend(im, 'Hi I am son of Odin, people call me Thor. Who are You?') #send_message = raw_input("You said: ") send_message = ""; send_message = iesha_chatbot.respond(message); purple.PurpleConvImSend(im, send_message ) print "You said: "+send_message protocol = purple.PurpleAccountGetProtocolName(account) print "protocol = " + protocol