bridge_with_irc: Add command line arg to specify stream.

This commit is contained in:
rht 2018-08-13 07:39:31 +01:00 committed by Tim Abbott
parent ed6c797d19
commit a5bc4b716c
2 changed files with 10 additions and 6 deletions

View file

@ -15,11 +15,13 @@ import traceback
if False:
from typing import Any, Dict
usage = """./irc-mirror.py --irc-server=IRC_SERVER --channel=<CHANNEL> --nick-prefix=<NICK> [optional args]
usage = """./irc-mirror.py --irc-server=IRC_SERVER --channel=<CHANNEL> --nick-prefix=<NICK> --stream=<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()

View file

@ -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