@@ -36,8 +36,7 @@ class Bot:
3636
3737 def __init__ (self ) -> None :
3838 log .info (
39- "Initializing bot as: %s" ,
40- subprocess .check_output ("id" , text = True ).rstrip (), # pylint: disable=unexpected-keyword-arg
39+ "Initializing bot as: %s" , subprocess .check_output ("id" , text = True ).rstrip (), # pylint: disable=unexpected-keyword-arg
4140 )
4241 instance = config .INSTANCE
4342 self ._setup_channel_queues () # Sets up executors and queues required by IRC handler.
@@ -83,19 +82,14 @@ def _msg_channel(self, channel: str) -> NoReturn: # pylint: disable=too-many-lo
8382 user , url , title = result
8483 if title .casefold () in title_blacklist :
8584 log .info (
86- "Skipping globally blacklisted title %s for %s in %s for URL %s" ,
87- repr (title ),
88- user ,
89- channel ,
90- url ,
85+ "Skipping globally blacklisted title %s for %s in %s for URL %s" , repr (title ), user , channel , url ,
9186 )
9287 continue
9388 msg = f"{ title_prefix } { title } "
9489 if irc .connected :
9590 irc .msg (channel , msg )
9691 log .info (
97- "Sent outgoing message for %s in %s in %.1fs having content %s for URL %s with %s "
98- "active threads." ,
92+ "Sent outgoing message for %s in %s in %.1fs having content %s for URL %s with %s " "active threads." ,
9993 user ,
10094 channel ,
10195 time .monotonic () - start_time ,
@@ -105,8 +99,7 @@ def _msg_channel(self, channel: str) -> NoReturn: # pylint: disable=too-many-lo
10599 )
106100 else :
107101 log .warning (
108- "Skipped outgoing message for %s in %s in %.1fs having content %s for URL %s with %s "
109- "active threads because the IRC client is not connected." ,
102+ "Skipped outgoing message for %s in %s in %.1fs having content %s for URL %s with %s " "active threads because the IRC client is not connected." ,
110103 user ,
111104 channel ,
112105 time .monotonic () - start_time ,
@@ -120,46 +113,30 @@ def _setup_channel_queues(self) -> None:
120113 channels_str = ", " .join (channels )
121114 active_count = threading .active_count
122115 log .debug (
123- "Setting up executor and queue for %s channels (%s) with %s currently active threads." ,
124- len (channels ),
125- channels_str ,
126- active_count (),
116+ "Setting up executor and queue for %s channels (%s) with %s currently active threads." , len (channels ), channels_str , active_count (),
127117 )
128118 for channel in channels :
129119 log .debug ("Setting up executor and queue for %s." , channel )
130- self .EXECUTORS [channel ] = concurrent .futures .ThreadPoolExecutor (
131- max_workers = config .MAX_WORKERS_PER_CHANNEL , thread_name_prefix = f"TitleReader-{ channel } "
132- )
120+ self .EXECUTORS [channel ] = concurrent .futures .ThreadPoolExecutor (max_workers = config .MAX_WORKERS_PER_CHANNEL , thread_name_prefix = f"TitleReader-{ channel } " )
133121 self .QUEUES [channel ] = queue .SimpleQueue ()
134122 log .debug (
135- "Finished setting up executor and queue for %s with %s currently active threads." ,
136- channel ,
137- active_count (),
123+ "Finished setting up executor and queue for %s with %s currently active threads." , channel , active_count (),
138124 )
139125 log .info (
140- "Finished setting up executor and queue for %s channels (%s) with %s currently active threads." ,
141- len (channels ),
142- channels_str ,
143- active_count (),
126+ "Finished setting up executor and queue for %s channels (%s) with %s currently active threads." , len (channels ), channels_str , active_count (),
144127 )
145128
146129 def _setup_channel_threads (self ) -> None :
147130 channels = config .INSTANCE ["channels" ]
148131 channels_str = ", " .join (channels )
149132 active_count = threading .active_count
150133 log .debug (
151- "Setting up thread for %s channels (%s) with %s currently active threads." ,
152- len (channels ),
153- channels_str ,
154- active_count (),
134+ "Setting up thread for %s channels (%s) with %s currently active threads." , len (channels ), channels_str , active_count (),
155135 )
156136 for channel in channels :
157137 threading .Thread (target = self ._msg_channel , name = f"ChannelMessenger-{ channel } " , args = (channel ,)).start ()
158138 log .info (
159- "Finished setting up thread for %s channels (%s) with %s currently active threads." ,
160- len (channels ),
161- channels_str ,
162- active_count (),
139+ "Finished setting up thread for %s channels (%s) with %s currently active threads." , len (channels ), channels_str , active_count (),
163140 )
164141
165142
@@ -173,10 +150,7 @@ def _get_title(irc: miniirc.IRC, channel: str, user: str, url: str) -> Optional[
173150 # Note: exc almost always includes the actual URL, so it need not be duplicated in the alert.
174151 if url .endswith (PUNCTUATION ):
175152 period = "" if msg .endswith ("." ) else "."
176- msg += (
177- f'{ period } It will however be reattempted with its trailing punctuation character "{ url [- 1 ]} " '
178- "stripped."
179- )
153+ msg += f'{ period } It will however be reattempted with its trailing punctuation character "{ url [- 1 ]} " ' "stripped."
180154 log .info (msg )
181155 else :
182156 _alert (irc , msg )
@@ -185,12 +159,7 @@ def _get_title(irc: miniirc.IRC, channel: str, user: str, url: str) -> Optional[
185159 else :
186160 if title : # Filter out None or blank title.
187161 log .debug (
188- 'Returning title "%s" for URL %s in message from %s in %s in %.1fs.' ,
189- title ,
190- url ,
191- user ,
192- channel ,
193- time .monotonic () - start_time ,
162+ 'Returning title "%s" for URL %s in message from %s in %s in %.1fs.' , title , url , user , channel , time .monotonic () - start_time ,
194163 )
195164 return user , url , title
196165 return None
@@ -210,10 +179,7 @@ def _handle_900_loggedin(irc: miniirc.IRC, hostmask: Tuple[str, str, str], args:
210179 log .info ("The client identity as <nick>!<user>@<host> is %s." , identity )
211180 if nick_casefold != config .INSTANCE ["nick:casefold" ]:
212181 _alert (
213- irc ,
214- f"The client nick was configured to be { config .INSTANCE ['nick' ]} but it is { nick } . "
215- "The configured nick will be regained." ,
216- logging .WARNING ,
182+ irc , f"The client nick was configured to be { config .INSTANCE ['nick' ]} but it is { nick } . The configured nick will be regained." , logging .WARNING ,
217183 )
218184 irc .msg ("nickserv" , "REGAIN" , config .INSTANCE ["nick" ], os .environ ["IRC_PASSWORD" ])
219185
@@ -252,9 +218,7 @@ def _handle_privmsg(irc: miniirc.IRC, hostmask: Tuple[str, str, str], args: List
252218 # Ignoring private message from freenode-connect having ident frigg
253219 # and hostname freenode/utility-bot/frigg: VERSION
254220 _alert (
255- irc ,
256- f"Ignoring private message from { user } having ident { ident } and hostname { hostname } : { msg } " ,
257- logging .WARNING ,
221+ irc , f"Ignoring private message from { user } having ident { ident } and hostname { hostname } : { msg } " , logging .WARNING ,
258222 )
259223 return
260224
0 commit comments