#!/usr/bin/env python2.1 # NOTE: I don't use this bot any longer # and I can't guarantee that it # works with newer versions of # the jabber.py library. YMMV. # This bot requires jabber.py (see # http://jabberpy.sourceforge.net/ # for details -- and much thanks to # Matthew Allum for his code!) import socket from select import select from string import split,strip,join import sys,os sys.path.insert(1, os.path.join(sys.path[0], '..')) import jabber True = 1 False = 0 Server = 'jabber.org' Username = 'stpeterbot' Password = 'secret' Resource = 'bot' JID = Username + '@' + Server + '/' + Resource def messageCB(con, msg): """Called when a message is recieved""" print ('got message from: ' + str(msg.getFrom()) + '') print ('message is: ' + str(msg.getBody()) + '') msg = jabber.Message(str(msg.getFrom()), 'test successful! unfortunately, I\'m just a stupid bot so you can\'t really chat with me.... :-(') msg.setType('chat') print "<%s> %s" % (JID, msg.getBody()) con.send(msg) def presenceCB(con, prs): """we do nothing with presence chunks""" pass def iqCB(con,iq): """we do nothing with iq chunks""" pass def disconnectedCB(con): print ("Ouch, network error") sys.exit(1) print ("That's all, folks!") con = jabber.Client(host=Server,debug=True,log=sys.stderr) try: con.connect() except IOError, e: print "Couldn't connect: %s" % e sys.exit(0) else: print ("Connected") con.setMessageHandler(messageCB) con.setPresenceHandler(presenceCB) con.setIqHandler(iqCB) con.setDisconnectHandler(disconnectedCB) print ("Attempting to log in...") if con.auth(Username,Password,Resource): print ("Logged in as %s to server %s" % ( Username, Server)) else: print "eek -> ", con.lastErr, con.lastErrCode sys.exit(1) con.sendInitPresence() print ("Ok, ready") while(1): inputs, outputs, errors = select([sys.stdin], [], [],1) if sys.stdin in inputs: doCmd(con,sys.stdin.readline()) else: con.process(1)