1
+ import logging
1
2
import multiprocessing as mp
2
3
from typing import Any , Dict
3
4
4
5
import irc .bot
5
6
import irc .strings
6
7
from irc .client import Event , ServerConnection , ip_numstr_to_quad
7
- from irc .client_aio import AioReactor
8
8
9
+ logging .basicConfig (level = logging .DEBUG )
9
10
10
- class IRCBot (irc .bot .SingleServerIRCBot ):
11
- reactor_class = AioReactor
12
11
12
+ class IRCBot (irc .bot .SingleServerIRCBot ):
13
13
def __init__ (
14
14
self ,
15
15
zulip_client : Any ,
@@ -30,19 +30,14 @@ def __init__(
30
30
# Make sure the bot is subscribed to the stream
31
31
self .check_subscription_or_die ()
32
32
# 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
+ )
34
36
35
37
def zulip_sender (self , sender_string : str ) -> str :
36
38
nick = sender_string .split ("!" )[0 ]
37
39
return nick + "@" + self .IRC_DOMAIN
38
40
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
-
46
41
def check_subscription_or_die (self ) -> None :
47
42
resp = self .zulip_client .get_subscriptions ()
48
43
if resp ["result" ] != "success" :
@@ -76,7 +71,7 @@ def forward_to_irc(msg: Dict[str, Any]) -> None:
76
71
at_the_specified_subject = msg ["subject" ].casefold () == self .topic .casefold ()
77
72
if in_the_specified_stream and at_the_specified_subject :
78
73
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 )
80
75
else :
81
76
return
82
77
else :
@@ -86,9 +81,9 @@ def forward_to_irc(msg: Dict[str, Any]) -> None:
86
81
if u ["email" ] != msg ["sender_email" ]
87
82
]
88
83
if len (recipients ) == 1 :
89
- send = lambda x : self . c .privmsg (recipients [0 ], x )
84
+ send = lambda x : c .privmsg (recipients [0 ], x )
90
85
else :
91
- send = lambda x : self . c .privmsg_many (recipients , x )
86
+ send = lambda x : c .privmsg_many (recipients , x )
92
87
for line in msg ["content" ].split ("\n " ):
93
88
send (line )
94
89
0 commit comments