mirror of https://github.com/zulip/zulip.git
jabber_mirror: Working room/stream mirroring
(imported from commit 5d0a33423e90edaee3a1094b1d48fae73cfb54ca)
This commit is contained in:
parent
2ca49c3735
commit
577d8d33e1
|
@ -39,9 +39,9 @@ def jid_to_zulip(jid):
|
||||||
return "%s@%s" % (str(jid).rpartition("@")[0], options.zulip_domain)
|
return "%s@%s" % (str(jid).rpartition("@")[0], options.zulip_domain)
|
||||||
|
|
||||||
class JabberToZulipBot(ClientXMPP):
|
class JabberToZulipBot(ClientXMPP):
|
||||||
def __init__(self, nick, password, rooms, openfire=False):
|
def __init__(self, nick, domain, password, rooms, openfire=False):
|
||||||
self.nick = nick
|
self.nick = nick
|
||||||
jid = "%s/zulip" % (nick,)
|
jid = "%s@%s/jabber_mirror" % (nick, domain)
|
||||||
ClientXMPP.__init__(self, jid, password)
|
ClientXMPP.__init__(self, jid, password)
|
||||||
self.password = password
|
self.password = password
|
||||||
self.rooms = rooms
|
self.rooms = rooms
|
||||||
|
@ -51,9 +51,8 @@ class JabberToZulipBot(ClientXMPP):
|
||||||
self.zulip = None
|
self.zulip = None
|
||||||
self.use_ipv6 = False
|
self.use_ipv6 = False
|
||||||
|
|
||||||
if options.conference_domain is not None:
|
# Jabber chatroom support.
|
||||||
# Jabber chatroom support.
|
self.register_plugin('xep_0045')
|
||||||
self.register_plugin('xep_0045')
|
|
||||||
|
|
||||||
if openfire:
|
if openfire:
|
||||||
# OpenFire Jabber servers use a different SSL protocol version
|
# OpenFire Jabber servers use a different SSL protocol version
|
||||||
|
@ -66,10 +65,9 @@ class JabberToZulipBot(ClientXMPP):
|
||||||
def session_start(self, event):
|
def session_start(self, event):
|
||||||
self.get_roster()
|
self.get_roster()
|
||||||
self.send_presence()
|
self.send_presence()
|
||||||
if options.mode == "public":
|
for room in self.rooms:
|
||||||
for room in self.rooms:
|
muc_jid = room + "@" + options.conference_domain
|
||||||
self.plugin['xep_0045'].joinMUC(room + "@" + options.conference_domain,
|
self.plugin['xep_0045'].joinMUC(muc_jid, self.nick)
|
||||||
self.nick)
|
|
||||||
|
|
||||||
def message(self, msg):
|
def message(self, msg):
|
||||||
try:
|
try:
|
||||||
|
@ -84,7 +82,7 @@ class JabberToZulipBot(ClientXMPP):
|
||||||
logging.exception("Error forwarding Jabber => Zulip")
|
logging.exception("Error forwarding Jabber => Zulip")
|
||||||
|
|
||||||
def private(self, msg):
|
def private(self, msg):
|
||||||
if msg["from"] == self.jid or msg['thread'] == u'\u1B80':
|
if options.mode == 'personal' or msg['thread'] == u'\u1B80':
|
||||||
return
|
return
|
||||||
sender = jid_to_zulip(msg["from"])
|
sender = jid_to_zulip(msg["from"])
|
||||||
recipient = jid_to_zulip(msg["to"])
|
recipient = jid_to_zulip(msg["to"])
|
||||||
|
@ -100,7 +98,7 @@ class JabberToZulipBot(ClientXMPP):
|
||||||
logging.error(ret)
|
logging.error(ret)
|
||||||
|
|
||||||
def group(self, msg):
|
def group(self, msg):
|
||||||
if msg.get_mucnick() == self.nick or msg["thread"] == u'\u1B80':
|
if options.mode == 'personal' or msg["thread"] == u'\u1B80':
|
||||||
return
|
return
|
||||||
|
|
||||||
subject = msg["subject"]
|
subject = msg["subject"]
|
||||||
|
@ -229,19 +227,26 @@ user and mirrors messages sent to Jabber rooms to Zulip.'''.replace("\n", " "))
|
||||||
if options.jabber_domain is None:
|
if options.jabber_domain is None:
|
||||||
sys.exit("Must specify a Jabber server")
|
sys.exit("Must specify a Jabber server")
|
||||||
|
|
||||||
jabber_username = options.jabber_username + '@' + options.jabber_domain
|
|
||||||
|
# This won't work for open realms
|
||||||
|
options.zulip_domain = options.zulip_email.partition('@')[-1]
|
||||||
|
|
||||||
zulip = ZulipToJabberBot(zulip.init_from_options(options, "jabber_mirror"))
|
zulip = ZulipToJabberBot(zulip.init_from_options(options, "jabber_mirror"))
|
||||||
rooms = [s['name'] for s in zulip.client.get_streams()['streams']]
|
rooms = [s['name'] for s in zulip.client.get_streams()['streams']]
|
||||||
xmpp = JabberToZulipBot(jabber_username, options.jabber_password, rooms,
|
xmpp = JabberToZulipBot(options.jabber_username, options.jabber_domain,
|
||||||
|
options.jabber_password, rooms,
|
||||||
openfire=options.openfire)
|
openfire=options.openfire)
|
||||||
xmpp.connect(use_tls=not options.no_use_tls)
|
xmpp.connect(use_tls=not options.no_use_tls)
|
||||||
xmpp.process(block=False)
|
|
||||||
xmpp.set_zulip_client(zulip)
|
xmpp.set_zulip_client(zulip)
|
||||||
zulip.set_jabber_client(xmpp)
|
zulip.set_jabber_client(xmpp)
|
||||||
try:
|
|
||||||
logging.info("Connecting to Zulip.")
|
if options.mode == 'public':
|
||||||
zulip.client.call_on_each_event(zulip.process_message)
|
xmpp.process(block=True)
|
||||||
except BaseException as e:
|
else:
|
||||||
logging.exception("Exception in main loop")
|
xmpp.process(block=False)
|
||||||
xmpp.abort()
|
try:
|
||||||
|
logging.info("Connecting to Zulip.")
|
||||||
|
zulip.client.call_on_each_event(zulip.process_message)
|
||||||
|
except BaseException as e:
|
||||||
|
logging.exception("Exception in main loop")
|
||||||
|
xmpp.abort()
|
||||||
|
|
Loading…
Reference in New Issue