bridge_with_irc: Fix sending from Zulip to IRC and enable it by default.

This commit is contained in:
rht 2018-08-13 07:30:07 +01:00 committed by Tim Abbott
parent 910f83ee8e
commit edcf1fd8e9
2 changed files with 4 additions and 8 deletions

View file

@ -26,9 +26,6 @@ Example:
Specify your Zulip API credentials and server in a ~/.zuliprc file or using the options. Specify your Zulip API credentials and server in a ~/.zuliprc file or using the options.
Note that "_zulip" will be automatically appended to the IRC nick provided Note that "_zulip" will be automatically appended to the IRC nick provided
Also note that at present you need to edit this code to do the Zulip => IRC side
""" """
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -2,6 +2,7 @@ import irc.bot
import irc.strings import irc.strings
from irc.client import ip_numstr_to_quad, ip_quad_to_numstr, Event, ServerConnection from irc.client import ip_numstr_to_quad, ip_quad_to_numstr, Event, ServerConnection
from irc.client_aio import AioReactor from irc.client_aio import AioReactor
import multiprocessing as mp
from typing import Any, Dict from typing import Any, Dict
@ -41,7 +42,7 @@ class IRCBot(irc.bot.SingleServerIRCBot):
def forward_to_irc(msg): def forward_to_irc(msg):
# type: (Dict[str, Any]) -> None # type: (Dict[str, Any]) -> None
if msg["type"] == "stream": if msg["type"] == "stream":
send = lambda x: c.privmsg(msg["display_recipient"], x) send = lambda x: c.privmsg(self.channel, x)
else: else:
recipients = [u["short_name"] for u in msg["display_recipient"] if recipients = [u["short_name"] for u in msg["display_recipient"] if
u["email"] != msg["sender_email"]] u["email"] != msg["sender_email"]]
@ -52,10 +53,8 @@ class IRCBot(irc.bot.SingleServerIRCBot):
for line in msg["content"].split("\n"): for line in msg["content"].split("\n"):
send(line) send(line)
## Forwarding from Zulip => IRC is disabled; uncomment the next z2i = mp.Process(target=self.zulip_client.call_on_each_message, args=(forward_to_irc,))
## line to make this bot forward in that direction instead. z2i.start()
#
# self.zulip_client.call_on_each_message(forward_to_irc)
def on_privmsg(self, c, e): def on_privmsg(self, c, e):
# type: (ServerConnection, Event) -> None # type: (ServerConnection, Event) -> None