commit dd951c31d0ed2150ac33dcf880a914da353a3bb7 Author: urlbot Date: Sun Aug 10 12:14:03 2014 +0200 init(). testing for a native bot using python-xmpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..578d951 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.*swp +*.pyc +local_config.py diff --git a/bot.py b/bot.py new file mode 100755 index 0000000..6b44d61 --- /dev/null +++ b/bot.py @@ -0,0 +1,31 @@ +#!/usr/bin/python + +import xmpp +from local_config import conf + +def message_handler(connect_object, message_node): + print 'connect_object:' + print connect_object + print 'message_node:' + print message_node + return None + +jid = xmpp.protocol.JID(conf('jid')) + +client = xmpp.Client(jid.getDomain()) #, debug=[]) +client.connect() +client.auth(jid.getNode(), conf('password')) +client.RegisterHandler('message', message_handler) + +client.send(xmpp.Presence(to=(conf('room') + '/' + conf('nick')))) + +if 0: + msg = xmpp.protocol.Message(body='''wee, I'm a native bot.''') + msg.setTo(conf('room')) + msg.setType('groupchat') + client.send(msg) + +import time +time.sleep(10) + +client.disconnect() diff --git a/local_config.py.skel b/local_config.py.skel new file mode 100644 index 0000000..ef99f78 --- /dev/null +++ b/local_config.py.skel @@ -0,0 +1,16 @@ +#!/usr/bin/python + +if '__main__' == __name__: + print '''don't try running this''' + exit(-1) + +config = {} +config['jid'] = '' +config['password'] = '' +config['room'] = '' +config['nick'] = '' + +def conf(val): + if val in config.keys(): + return config[val] + return None