2
2
# SPDX-License-Identifier: MIT
3
3
import time
4
4
5
-
6
5
import adafruit_connection_manager
7
6
8
7
ANSI_ESCAPE_CODES = [
@@ -22,7 +21,8 @@ class IRCClient:
22
21
Handles interaction with IRC Server and makes incoming messages available.
23
22
24
23
:param radio: The network radio to connect with.
25
- :param dict irc_config: Dictionary containing IRC configration for server, port, username and channel.
24
+ :param dict irc_config: Dictionary containing IRC configration for
25
+ server, port, username and channel.
26
26
:param audio_interface: Optional interface to play audio from for beep messages
27
27
:param beep_wave: Optional wave file to use for beep messages
28
28
:param int max_line_length: Maximum characters per line to format messages into.
@@ -142,7 +142,7 @@ def update(self):
142
142
# no data before timeout
143
143
# print(e)
144
144
if "ETIMEDOUT" not in str (e ):
145
- raise RuntimeError (e )
145
+ raise RuntimeError (e ) from e
146
146
# raise RuntimeError("Connection timed out")
147
147
return updated_display_lines
148
148
@@ -163,7 +163,6 @@ def send_dm(self, to_user, message):
163
163
"""
164
164
irc_command = f"PRIVMSG { to_user } :{ message } \r \n "
165
165
self .socket .send (irc_command .encode ("utf-8" ))
166
- # self.process_message(f":{self.config['username']}!~{self.config['username']}@localhost " + irc_command[:-2])
167
166
color = self .get_color_for_user (to_user )
168
167
self .message_buffer .append (f"DM out: <{ color } { to_user } { ANSI_RESET } > { message } " )
169
168
@@ -205,7 +204,7 @@ def get_technical_name(self, nickname):
205
204
if "ETIMEDOUT" in str (e ):
206
205
whois_resp_lines = None
207
206
else :
208
- raise RuntimeError (e )
207
+ raise RuntimeError (e ) from e
209
208
210
209
if whois_resp_lines is None :
211
210
return None
@@ -221,10 +220,11 @@ def get_technical_name(self, nickname):
221
220
222
221
whois_response = parts [2 ].split (" " , 1 )[1 ]
223
222
response_parts = whois_response .split (" " )
224
- showname = response_parts [0 ]
225
223
technical_name = f"*!{ response_parts [1 ]} @{ response_parts [2 ]} "
226
224
return technical_name
227
225
226
+ return None
227
+
228
228
def ban (self , user ):
229
229
"""
230
230
Ban the specified user from the channel
@@ -301,13 +301,14 @@ def split_string_chunks(s, chunk_size):
301
301
return chunks
302
302
303
303
def process_message (self , message ):
304
+ # pylint: disable=too-many-branches, too-many-statements
304
305
"""
305
306
Process an incoming IRC message
306
307
:param message: The message that came from the IRC server.
307
308
308
309
:return lines_added: The number of lines added to the display
309
310
"""
310
-
311
+ # pylint: disable=too-many-locals
311
312
lines_added = 0
312
313
313
314
message = message .lstrip ("\x00 " )
@@ -317,12 +318,12 @@ def process_message(self, message):
317
318
if message .startswith ("PING" ):
318
319
pong_response = message .replace ("PING" , "PONG" )
319
320
self .socket .send (f"{ pong_response } \r \n " .encode ("utf-8" ))
320
- print (f "Responded to PING" )
321
+ print ("Responded to PING" )
321
322
return 0
322
323
323
324
# Parse IRC message format: :prefix COMMAND params
324
325
parts = message .split (" " , 2 )
325
-
326
+ # pylint: disable=too-many-nested-blocks
326
327
if len (parts ) >= 2 :
327
328
command = parts [1 ]
328
329
try :
@@ -331,7 +332,7 @@ def process_message(self, message):
331
332
command_num = None
332
333
333
334
# End of MOTD - now we can join the channel
334
- if command == "376" or command == "422" : # 422 is "no MOTD"
335
+ if command in { "376" , "422" } : # 422 is "no MOTD"
335
336
# join channel
336
337
self .join ()
337
338
@@ -357,7 +358,7 @@ def process_message(self, message):
357
358
welcome_text = welcome_text [1 :]
358
359
359
360
print (
360
- f"'{ welcome_text [0 :11 ]} ' startswith '{ self .config ['username' ]} ' ? { welcome_text .startswith (self .config ['username' ])} "
361
+ f"'{ welcome_text [0 :11 ]} ' startswith '{ self .config ['username' ]} ' ? { welcome_text .startswith (self .config ['username' ])} " # pylint: disable=line-too-long
361
362
)
362
363
if welcome_text .startswith (self .config ["username" ]):
363
364
welcome_text = welcome_text .replace (
@@ -451,11 +452,13 @@ def process_message(self, message):
451
452
action_user = parts [0 ].split ("!" , 1 )[0 ][1 :]
452
453
mode_msg_parts = parts [2 ].split (" " , 2 )
453
454
if len (mode_msg_parts ) >= 3 :
454
- channel , mode , target_user = mode_msg_parts
455
+ channel , mode , target_user = (
456
+ mode_msg_parts # pylint: disable=unused-variable
457
+ )
455
458
action_user_color = self .get_color_for_user (action_user )
456
459
target_user_color = self .get_color_for_user (target_user )
457
460
self .message_buffer .append (
458
- f"{ action_user_color } { action_user } { ANSI_RESET } sets mode { mode } on { target_user_color } { target_user } { ANSI_RESET } "
461
+ f"{ action_user_color } { action_user } { ANSI_RESET } sets mode { mode } on { target_user_color } { target_user } { ANSI_RESET } " # pylint: disable=line-too-long
459
462
)
460
463
lines_added += 1
461
464
0 commit comments