Skip to content

Commit

Permalink
Black is back
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaoming committed Aug 28, 2021
1 parent e1ba1a7 commit 22a279e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
18 changes: 9 additions & 9 deletions zulip/integrations/bridge_with_irc/irc-mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
parser = zulip.add_default_arguments(
argparse.ArgumentParser(usage=usage), allow_provisioning=True
)
parser.add_argument('--irc-server', default=None)
parser.add_argument('--port', default=6697)
parser.add_argument('--nick-prefix', default=None)
parser.add_argument('--channel', default=None)
parser.add_argument('--no-ssl', default=False)
parser.add_argument('--stream', default="general")
parser.add_argument('--topic', default="IRC")
parser.add_argument('--nickserv-pw', default='')
parser.add_argument("--irc-server", default=None)
parser.add_argument("--port", default=6697)
parser.add_argument("--nick-prefix", default=None)
parser.add_argument("--channel", default=None)
parser.add_argument("--no-ssl", default=False)
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
Expand Down Expand Up @@ -68,6 +68,6 @@
options.irc_server,
options.nickserv_pw,
options.port,
use_ssl=not options.no_ssl
use_ssl=not options.no_ssl,
)
bot.start()
21 changes: 13 additions & 8 deletions zulip/integrations/bridge_with_irc/irc_mirror_backend.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import multiprocessing as mp
import ssl
from typing import Any, Dict

import irc.bot
import irc.connection
import multiprocessing as mp
from irc import schedule
from irc.client import Event, ServerConnection, ip_numstr_to_quad
from irc.client_aio import AioReactor
from irc import schedule
from typing import Any, Dict


class AioReactorWithScheduler(AioReactor):
Expand All @@ -32,7 +33,7 @@ def __init__(
nickserv_password: str = "",
port: int = 6667,
use_ssl: bool = True,
ssl_connection_factory: irc.connection.Factory = None
ssl_connection_factory: irc.connection.Factory = None,
) -> None:
self.channel = channel # type: irc.bot.Channel
self.zulip_client = zulip_client
Expand All @@ -47,17 +48,21 @@ def __init__(
if ssl_connection_factory:
self.connection_factory = ssl_connection_factory
else:
self.connection_factory = irc.connection.AioFactory(ssl=ssl.create_default_context())
self.connection_factory = irc.connection.AioFactory(
ssl=ssl.create_default_context()
)
else:
self.connection_factory = irc.connection.AioFactory()

connect_params = {}
connect_params['connect_factory'] = self.connection_factory
connect_params["connect_factory"] = self.connection_factory

# 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, [irc.bot.ServerSpec(server, port)], nickname, nickname, **connect_params)
irc.bot.SingleServerIRCBot.__init__(
self, [irc.bot.ServerSpec(server, port)], nickname, nickname, **connect_params
)

def zulip_sender(self, sender_string: str) -> str:
nick = sender_string.split("!")[0]
Expand All @@ -67,7 +72,7 @@ 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
kwargs['connect_factory'] = self.connection_factory
kwargs["connect_factory"] = self.connection_factory
self.c = self.reactor.loop.run_until_complete(self.connection.connect(*args, **kwargs))
print("Listening now. Please send an IRC message to verify operation")

Expand Down

0 comments on commit 22a279e

Please sign in to comment.