Skip to content

Commit

Permalink
IRC: Update to use always SASL authentication.
Browse files Browse the repository at this point in the history
This reverts to using sync IRC client, because upstream
https://github.com/jaraco/irc only supports it for the sync client.
  • Loading branch information
rht committed Oct 1, 2023
1 parent ccda105 commit de255c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
23 changes: 9 additions & 14 deletions zulip/integrations/bridge_with_irc/irc_mirror_backend.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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":
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion zulip/integrations/bridge_with_irc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
irc==18.0
irc==20.3.0

0 comments on commit de255c1

Please sign in to comment.