diff --git a/zulip/integrations/bridge_with_irc/README.md b/zulip/integrations/bridge_with_irc/README.md index 67637c0..4f59e6e 100644 --- a/zulip/integrations/bridge_with_irc/README.md +++ b/zulip/integrations/bridge_with_irc/README.md @@ -7,6 +7,7 @@ ``` `--stream` is a Zulip stream. +`--topic` is a Zulip topic, is optionally specified, defaults to "IRC". Specify your Zulip API credentials and server in a ~/.zuliprc file or using the options. @@ -15,6 +16,8 @@ Note that "_zulip" will be automatically appended to the IRC nick provided ## Example ``` -./irc-mirror.py --irc-server=irc.freenode.net --channel='#python-mypy' --nick-prefix=irc_mirror --stream='test here' \ - --site="https://chat.zulip.org" --user= --api-key= +./irc-mirror.py --irc-server=irc.freenode.net --channel='#python-mypy' --nick-prefix=irc_mirror \ +--stream='test here' --topic='#mypy' \ +--site="https://chat.zulip.org" --user= \ +--api-key= ``` diff --git a/zulip/integrations/bridge_with_irc/irc-mirror.py b/zulip/integrations/bridge_with_irc/irc-mirror.py index 91a1ce2..b8b3e75 100755 --- a/zulip/integrations/bridge_with_irc/irc-mirror.py +++ b/zulip/integrations/bridge_with_irc/irc-mirror.py @@ -17,9 +17,10 @@ usage = """./irc-mirror.py --irc-server=IRC_SERVER --channel= --nick-pr Example: -./irc-mirror.py --irc-server=127.0.0.1 --channel='#test' --nick-prefix=username --stream='test' +./irc-mirror.py --irc-server=127.0.0.1 --channel='#test' --nick-prefix=username --stream='test' --topic='#mypy' --stream is a Zulip stream. +--topic is a Zulip topic, is optionally specified, defaults to "IRC". Specify your Zulip API credentials and server in a ~/.zuliprc file or using the options. @@ -33,6 +34,7 @@ if __name__ == "__main__": parser.add_argument('--nick-prefix', default=None) parser.add_argument('--channel', default=None) parser.add_argument('--stream', default="general") + parser.add_argument('--topic', default="IRC") options = parser.parse_args() # Setting the client to irc_mirror is critical for this to work @@ -50,5 +52,5 @@ if __name__ == "__main__": parser.error("Missing required argument") nickname = options.nick_prefix + "_zulip" - bot = IRCBot(zulip_client, options.stream, options.channel, nickname, options.irc_server, options.port) + bot = IRCBot(zulip_client, options.stream, options.topic, 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 5e4c7cc..f4ef2b4 100644 --- a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py +++ b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py @@ -9,12 +9,13 @@ from typing import Any, Dict class IRCBot(irc.bot.SingleServerIRCBot): reactor_class = AioReactor - def __init__(self, zulip_client, stream, channel, nickname, server, port=6667): - # type: (Any, str, irc.bot.Channel, str, str, int) -> None + def __init__(self, zulip_client, stream, topic, channel, nickname, server, port=6667): + # type: (Any, str, 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 + self.topic = topic self.IRC_DOMAIN = server def zulip_sender(self, sender_string): @@ -77,7 +78,6 @@ class IRCBot(irc.bot.SingleServerIRCBot): def on_pubmsg(self, c, e): # type: (ServerConnection, Event) -> None content = e.arguments[0] - stream = self.stream sender = self.zulip_sender(e.source) if sender.endswith("_zulip@" + self.IRC_DOMAIN): return @@ -85,8 +85,8 @@ class IRCBot(irc.bot.SingleServerIRCBot): # Forward the stream message to Zulip print(self.zulip_client.send_message({ "type": "stream", - "to": stream, - "subject": "IRC", + "to": self.stream, + "subject": self.topic, "content": content, "content": "**{0}**: {1}".format(sender, content), }))