From a5bc4b716cde4a9c86c9f00027db2879768f5bce Mon Sep 17 00:00:00 2001 From: rht Date: Mon, 13 Aug 2018 07:39:31 +0100 Subject: [PATCH] bridge_with_irc: Add command line arg to specify stream. --- zulip/integrations/bridge_with_irc/irc-mirror.py | 9 ++++++--- zulip/integrations/bridge_with_irc/irc_mirror_backend.py | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/zulip/integrations/bridge_with_irc/irc-mirror.py b/zulip/integrations/bridge_with_irc/irc-mirror.py index 7b35fa1..746d4d9 100755 --- a/zulip/integrations/bridge_with_irc/irc-mirror.py +++ b/zulip/integrations/bridge_with_irc/irc-mirror.py @@ -15,11 +15,13 @@ import traceback if False: from typing import Any, Dict -usage = """./irc-mirror.py --irc-server=IRC_SERVER --channel= --nick-prefix= [optional args] +usage = """./irc-mirror.py --irc-server=IRC_SERVER --channel= --nick-prefix= --stream= [optional args] Example: -./irc-mirror.py --irc-server=127.0.0.1 --channel='#test' --nick-prefix=username +./irc-mirror.py --irc-server=127.0.0.1 --channel='#test' --nick-prefix=username --stream='test' + +--stream is a Zulip stream. Specify your Zulip API credentials and server in a ~/.zuliprc file or using the options. @@ -35,6 +37,7 @@ if __name__ == "__main__": parser.add_argument('--port', default=6667) parser.add_argument('--nick-prefix', default=None) parser.add_argument('--channel', default=None) + parser.add_argument('--stream', default="general") options = parser.parse_args() # Setting the client to irc_mirror is critical for this to work @@ -52,5 +55,5 @@ if __name__ == "__main__": parser.error("Missing required argument") nickname = options.nick_prefix + "_zulip" - bot = IRCBot(zulip_client, options.channel, nickname, options.irc_server, options.port) + bot = IRCBot(zulip_client, options.stream, options.channel, nickname, options.irc_server, options.port) bot.start() diff --git a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py index 8f9f2a4..a189054 100644 --- a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py +++ b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py @@ -11,11 +11,12 @@ def zulip_sender(sender_string): return nick + "@" + IRC_DOMAIN class IRCBot(irc.bot.SingleServerIRCBot): - def __init__(self, zulip_client, channel, nickname, server, port=6667): - # type: (Any, irc.bot.Channel, str, str, int) -> None + def __init__(self, zulip_client, stream, channel, nickname, server, port=6667): + # type: (Any, str, irc.bot.Channel, str, str, int) -> None irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname) self.channel = channel # type: irc.bot.Channel self.zulip_client = zulip_client + self.stream = stream def on_nicknameinuse(self, c, e): # type: (ServerConnection, Event) -> None @@ -62,7 +63,7 @@ class IRCBot(irc.bot.SingleServerIRCBot): def on_pubmsg(self, c, e): # type: (ServerConnection, Event) -> None content = e.arguments[0] - stream = e.target + stream = self.stream sender = zulip_sender(e.source) if sender.endswith("_zulip@" + IRC_DOMAIN): return