Skip to content

Commit de255c1

Browse files
committed
IRC: Update to use always SASL authentication.
This reverts to using sync IRC client, because upstream https://github.com/jaraco/irc only supports it for the sync client.
1 parent ccda105 commit de255c1

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

zulip/integrations/bridge_with_irc/irc_mirror_backend.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
import logging
12
import multiprocessing as mp
23
from typing import Any, Dict
34

45
import irc.bot
56
import irc.strings
67
from irc.client import Event, ServerConnection, ip_numstr_to_quad
7-
from irc.client_aio import AioReactor
88

9+
logging.basicConfig(level=logging.DEBUG)
910

10-
class IRCBot(irc.bot.SingleServerIRCBot):
11-
reactor_class = AioReactor
1211

12+
class IRCBot(irc.bot.SingleServerIRCBot):
1313
def __init__(
1414
self,
1515
zulip_client: Any,
@@ -30,19 +30,14 @@ def __init__(
3030
# Make sure the bot is subscribed to the stream
3131
self.check_subscription_or_die()
3232
# Initialize IRC bot after proper connection to Zulip server has been confirmed.
33-
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
33+
irc.bot.SingleServerIRCBot.__init__(
34+
self, [(server, port, nickserv_password)], nickname, nickname, sasl_login=nickname
35+
)
3436

3537
def zulip_sender(self, sender_string: str) -> str:
3638
nick = sender_string.split("!")[0]
3739
return nick + "@" + self.IRC_DOMAIN
3840

39-
def connect(self, *args: Any, **kwargs: Any) -> None:
40-
# Taken from
41-
# https://github.com/jaraco/irc/blob/main/irc/client_aio.py,
42-
# in particular the method of AioSimpleIRCClient
43-
self.c = self.reactor.loop.run_until_complete(self.connection.connect(*args, **kwargs))
44-
print("Listening now. Please send an IRC message to verify operation")
45-
4641
def check_subscription_or_die(self) -> None:
4742
resp = self.zulip_client.get_subscriptions()
4843
if resp["result"] != "success":
@@ -76,7 +71,7 @@ def forward_to_irc(msg: Dict[str, Any]) -> None:
7671
at_the_specified_subject = msg["subject"].casefold() == self.topic.casefold()
7772
if in_the_specified_stream and at_the_specified_subject:
7873
msg["content"] = ("@**{}**: ".format(msg["sender_full_name"])) + msg["content"]
79-
send = lambda x: self.c.privmsg(self.channel, x)
74+
send = lambda x: c.privmsg(self.channel, x)
8075
else:
8176
return
8277
else:
@@ -86,9 +81,9 @@ def forward_to_irc(msg: Dict[str, Any]) -> None:
8681
if u["email"] != msg["sender_email"]
8782
]
8883
if len(recipients) == 1:
89-
send = lambda x: self.c.privmsg(recipients[0], x)
84+
send = lambda x: c.privmsg(recipients[0], x)
9085
else:
91-
send = lambda x: self.c.privmsg_many(recipients, x)
86+
send = lambda x: c.privmsg_many(recipients, x)
9287
for line in msg["content"].split("\n"):
9388
send(line)
9489

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
irc==18.0
1+
irc==20.3.0

0 commit comments

Comments
 (0)