Skip to content

Fix bridge_with_irc #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions zulip/integrations/bridge_with_irc/irc-mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

--stream is a Zulip stream.
--topic is a Zulip topic, is optionally specified, defaults to "IRC".
--nickserv-pw is a password for the nickserv, is optionally specified.

Specify your Zulip API credentials and server in a ~/.zuliprc file or using the options.

Expand All @@ -35,14 +36,15 @@
parser.add_argument('--channel', default=None)
parser.add_argument('--stream', default="general")
parser.add_argument('--topic', default="IRC")
parser.add_argument('--nickserv-pw', default='')

options = parser.parse_args()
# Setting the client to irc_mirror is critical for this to work
options.client = "irc_mirror"
zulip_client = zulip.init_from_options(options)
try:
from irc_mirror_backend import IRCBot
except ImportError as e:
except ImportError:
traceback.print_exc()
print("You have unsatisfied dependencies. Install all missing dependencies with "
"{} --provision".format(sys.argv[0]))
Expand All @@ -52,5 +54,6 @@
parser.error("Missing required argument")

nickname = options.nick_prefix + "_zulip"
bot = IRCBot(zulip_client, options.stream, options.topic, options.channel, nickname, options.irc_server, options.port)
bot = IRCBot(zulip_client, options.stream, options.topic, options.channel,
nickname, options.irc_server, options.nickserv_pw, options.port)
bot.start()
23 changes: 18 additions & 5 deletions zulip/integrations/bridge_with_irc/irc_mirror_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
class IRCBot(irc.bot.SingleServerIRCBot):
reactor_class = AioReactor

def __init__(self, zulip_client, stream, topic, channel, nickname, server, port=6667):
# type: (Any, str, str, irc.bot.Channel, str, str, int) -> None
def __init__(self, zulip_client, stream, topic, channel,
nickname, server, nickserv_password='', port=6667):
# type: (Any, str, str, irc.bot.Channel, str, 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
self.nickserv_password = nickserv_password

def zulip_sender(self, sender_string):
# type: (str) -> str
Expand All @@ -38,15 +40,26 @@ def on_nicknameinuse(self, c, e):

def on_welcome(self, c, e):
# type: (ServerConnection, Event) -> None
if len(self.nickserv_password) > 0:
msg = 'identify %s' % (self.nickserv_password,)
c.privmsg('NickServ', msg)
c.join(self.channel)

def forward_to_irc(msg):
# type: (Dict[str, Any]) -> None
if msg["sender_email"] == self.zulip_client.email:
not_from_zulip_bot = msg["sender_email"] != self.zulip_client.email
if not not_from_zulip_bot:
# Do not forward echo
return
if msg["type"] == "stream":
send = lambda x: c.privmsg(self.channel, x)
is_a_stream = msg["type"] == "stream"
if is_a_stream:
in_the_specified_stream = msg["display_recipient"] == self.stream
at_the_specified_subject = msg["subject"].casefold() == self.topic.casefold()
if in_the_specified_stream and at_the_specified_subject:
msg["content"] = ("@**%s**: " % msg["sender_full_name"]) + msg["content"]
send = lambda x: c.privmsg(self.channel, x)
else:
return
else:
recipients = [u["short_name"] for u in msg["display_recipient"] if
u["email"] != msg["sender_email"]]
Expand Down