Skip to content

Instantly share code, notes, and snippets.

@superbahbi
Created October 2, 2014 16:44
Show Gist options
  • Save superbahbi/be5c5d8a6f6e709649c8 to your computer and use it in GitHub Desktop.
Save superbahbi/be5c5d8a6f6e709649c8 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#To install cleverbot use 'pip install cleverbot'
import cleverbot, getpass, time, random
from sleekxmpp import ClientXMPP
class fbMsgBot(ClientXMPP):
def __init__(self, jid, password):
ClientXMPP.__init__(self, jid, password)
self.add_event_handler('session_start', self.start)
self.add_event_handler("message", self.message)
print "Processing"
def start(self, event):
print "Process session start"
self.send_presence()
def message(self, msg):
print ("RECV: from=%s, message=%s"% (msg['from'], msg['body']))
if msg['type'] in ('chat', 'normal'):
cb1 = cleverbot.Cleverbot()
t = random.randint(2, 5)
time.sleep(t)
ans = cb1.ask(msg['body'])
msg.reply(ans).send()
print("SEND: to=%s message=%s"% (msg['to'], ans))
if __name__ == '__main__':
username = raw_input("Enter yout facebook username: ")
password = getpass.getpass("Enter your facebook password: ")
print "Connecting"
xmpp = fbMsgBot(username+"@chat.facebook.com", password)
xmpp.connect()
print "Connected"
xmpp.process(block=True)
raw_input("There was some sort of error :(\nEnter any key to quit")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment