From f87e410787083353b734cc974c3dc23b9dc7eaf3 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Sat, 1 Mar 2014 22:42:20 -0500 Subject: [PATCH] jabber_mirror: Pull rooms to join from Zulip based on mode (imported from commit 115d4d4732d8ff4f12d336cfc42a056183251d87) --- bots/jabber_mirror.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bots/jabber_mirror.py b/bots/jabber_mirror.py index a61662c..2719079 100755 --- a/bots/jabber_mirror.py +++ b/bots/jabber_mirror.py @@ -196,6 +196,19 @@ class ZulipToJabberBot(object): outgoing['thread'] = u'\u1B80' outgoing.send() +def get_rooms(zulip): + if options.mode == 'public': + stream_infos = zulip.client.get_streams()['streams'] + else: + stream_infos = zulip.client.list_subscriptions()['subscriptions'] + + rooms = [] + for stream_info in stream_infos: + stream = stream_info['name'] + if stream.endswith("/xmpp"): + rooms.append(stream_to_room(stream)) + return rooms + if __name__ == '__main__': parser = optparse.OptionParser() parser.add_option('--mode', @@ -263,9 +276,8 @@ user and mirrors messages sent to Jabber rooms to Zulip.'''.replace("\n", " ")) options.zulip_domain = options.zulip_email.partition('@')[-1] zulip = ZulipToJabberBot(zulip.init_from_options(options, "JabberMirror/" + __version__)) - rooms = [s['name'] for s in zulip.client.get_streams()['streams']] xmpp = JabberToZulipBot(options.jabber_username, options.jabber_domain, - options.jabber_password, rooms, + options.jabber_password, get_rooms(zulip), openfire=options.openfire) if not xmpp.connect(use_tls=not options.no_use_tls):