From 910f83ee8ef00b1113e87d9aa6eccd9536109cb6 Mon Sep 17 00:00:00 2001 From: rht Date: Mon, 13 Aug 2018 06:56:15 +0100 Subject: [PATCH] bridge_with_irc: Use async client to avoid timeout. --- .../bridge_with_irc/irc_mirror_backend.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py index b204b94..95c1a1a 100644 --- a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py +++ b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py @@ -1,10 +1,13 @@ import irc.bot import irc.strings from irc.client import ip_numstr_to_quad, ip_quad_to_numstr, Event, ServerConnection +from irc.client_aio import AioReactor from typing import Any, Dict class IRCBot(irc.bot.SingleServerIRCBot): + reactor_class = AioReactor + def __init__(self, zulip_client, stream, channel, nickname, server, port=6667): # type: (Any, str, irc.bot.Channel, str, str, int) -> None irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname) @@ -18,6 +21,15 @@ class IRCBot(irc.bot.SingleServerIRCBot): nick = sender_string.split("!")[0] return nick + "@" + self.IRC_DOMAIN + def connect(self, *args, **kwargs): + # type: (*Any, **Any) -> None + # Taken from + # https://github.com/jaraco/irc/blob/master/irc/client_aio.py, + # in particular the method of AioSimpleIRCClient + self.reactor.loop.run_until_complete( + self.connection.connect(*args, **kwargs) + ) + def on_nicknameinuse(self, c, e): # type: (ServerConnection, Event) -> None c.nick(c.get_nickname().replace("_zulip", "__zulip"))