Download:
child 1:e7b3233bb582
0:ce9855302692
Anton Shestakov <av6@dwimlabs.net>, Mon, 09 May 2016 21:21:58 +0800
rollbot: connect and send presence

2 файлов изменено, 54 вставок(+), 0 удалений(-) [+]
requirements.txt file | annotate | diff | comparison | revisions
rollbot.py file | annotate | diff | comparison | revisions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/requirements.txt Mon May 09 21:21:58 2016 +0800
@@ -0,0 +1,1 @@
+sleekxmpp==1.3.1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rollbot.py Mon May 09 21:21:58 2016 +0800
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+import logging
+import sys
+from argparse import ArgumentParser
+
+import sleekxmpp
+
+
+if sys.version_info < (3, 0):
+ reload(sys)
+ sys.setdefaultencoding('utf8')
+else:
+ raw_input = input
+
+
+class RollBot(sleekxmpp.ClientXMPP):
+ def __init__(self, jid, password):
+ sleekxmpp.ClientXMPP.__init__(self, jid, password)
+
+ self.add_event_handler('session_start', self.start)
+
+ def start(self, event):
+ self.get_roster()
+ self.send_presence()
+
+
+def main():
+ parser = ArgumentParser()
+
+ parser.add_argument('-j', '--jid', dest='jid', help='JID to use')
+ parser.add_argument('-p', '--password', dest='password', help='password to use')
+ parser.add_argument('-d', '--debug', help='set logging to DEBUG', action='store_const', dest='loglevel', const=logging.DEBUG, default=logging.INFO)
+
+ args = parser.parse_args()
+
+ logging.basicConfig(level=args.loglevel, format='%(asctime)s %(levelname)-8s %(message)s')
+
+ rollbot = RollBot(args.jid, args.password)
+ rollbot.register_plugin('xep_0030') # Service Discovery
+ rollbot.register_plugin('xep_0092') # Software Version
+ rollbot.register_plugin('xep_0199') # XMPP Ping
+ rollbot.register_plugin('xep_0202') # Entity Time
+
+ if rollbot.connect():
+ logging.info('RollBot connected')
+ rollbot.process(block=True)
+ logging.info('RollBot disconnected')
+ else:
+ logging.fatal("RollBot couldn't connect")
+
+
+if __name__ == '__main__':
+ main()