diff --git a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py index 5242ca0d6..1f9398196 100644 --- a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py +++ b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py @@ -1,15 +1,15 @@ +import logging import multiprocessing as mp from typing import Any, Dict import irc.bot import irc.strings from irc.client import Event, ServerConnection, ip_numstr_to_quad -from irc.client_aio import AioReactor +logging.basicConfig(level=logging.DEBUG) -class IRCBot(irc.bot.SingleServerIRCBot): - reactor_class = AioReactor +class IRCBot(irc.bot.SingleServerIRCBot): def __init__( self, zulip_client: Any, @@ -30,19 +30,14 @@ def __init__( # Make sure the bot is subscribed to the stream self.check_subscription_or_die() # Initialize IRC bot after proper connection to Zulip server has been confirmed. - irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname) + irc.bot.SingleServerIRCBot.__init__( + self, [(server, port, nickserv_password)], nickname, nickname, sasl_login=nickname + ) def zulip_sender(self, sender_string: str) -> str: nick = sender_string.split("!")[0] return nick + "@" + self.IRC_DOMAIN - def connect(self, *args: Any, **kwargs: Any) -> None: - # Taken from - # https://github.com/jaraco/irc/blob/main/irc/client_aio.py, - # in particular the method of AioSimpleIRCClient - self.c = self.reactor.loop.run_until_complete(self.connection.connect(*args, **kwargs)) - print("Listening now. Please send an IRC message to verify operation") - def check_subscription_or_die(self) -> None: resp = self.zulip_client.get_subscriptions() if resp["result"] != "success": @@ -76,7 +71,7 @@ def forward_to_irc(msg: Dict[str, Any]) -> None: at_the_specified_subject = msg["subject"].casefold() == self.topic.casefold() if in_the_specified_stream and at_the_specified_subject: msg["content"] = ("@**{}**: ".format(msg["sender_full_name"])) + msg["content"] - send = lambda x: self.c.privmsg(self.channel, x) + send = lambda x: c.privmsg(self.channel, x) else: return else: @@ -86,9 +81,9 @@ def forward_to_irc(msg: Dict[str, Any]) -> None: if u["email"] != msg["sender_email"] ] if len(recipients) == 1: - send = lambda x: self.c.privmsg(recipients[0], x) + send = lambda x: c.privmsg(recipients[0], x) else: - send = lambda x: self.c.privmsg_many(recipients, x) + send = lambda x: c.privmsg_many(recipients, x) for line in msg["content"].split("\n"): send(line) diff --git a/zulip/integrations/bridge_with_irc/requirements.txt b/zulip/integrations/bridge_with_irc/requirements.txt index 085dd9a8d..b090adb76 100644 --- a/zulip/integrations/bridge_with_irc/requirements.txt +++ b/zulip/integrations/bridge_with_irc/requirements.txt @@ -1 +1 @@ -irc==18.0 +irc==20.3.0