comparison libervia/backend/plugins/plugin_misc_text_commands.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 4b842c1fb686
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
149 ) 149 )
150 150
151 return data 151 return data
152 152
153 def register_text_commands(self, instance): 153 def register_text_commands(self, instance):
154 """ Add a text command 154 """Add a text command
155 155
156 @param instance: instance of a class containing text commands 156 @param instance: instance of a class containing text commands
157 """ 157 """
158 for attr in dir(instance): 158 for attr in dir(instance):
159 if attr.startswith("cmd_"): 159 if attr.startswith("cmd_"):
194 self._whois.sort(key=lambda item: item[0], reverse=True) 194 self._whois.sort(key=lambda item: item[0], reverse=True)
195 195
196 def send_message_trigger( 196 def send_message_trigger(
197 self, client, mess_data, pre_xml_treatments, post_xml_treatments 197 self, client, mess_data, pre_xml_treatments, post_xml_treatments
198 ): 198 ):
199 """Install SendMessage command hook """ 199 """Install SendMessage command hook"""
200 pre_xml_treatments.addCallback(self._send_message_cmd_hook, client) 200 pre_xml_treatments.addCallback(self._send_message_cmd_hook, client)
201 return True 201 return True
202 202
203 def _send_message_cmd_hook(self, mess_data, client): 203 def _send_message_cmd_hook(self, mess_data, client):
204 """ Check text commands in message, and react consequently 204 """Check text commands in message, and react consequently
205 205
206 msg starting with / are potential command. If a command is found, it is executed, 206 msg starting with / are potential command. If a command is found, it is executed,
207 else an help message is sent. 207 else an help message is sent.
208 msg starting with // are escaped: they are sent with a single / 208 msg starting with // are escaped: they are sent with a single /
209 commands can abord message sending (if they return anything evaluating to False), 209 commands can abord message sending (if they return anything evaluating to False),
246 ) 246 )
247 raise failure.Failure(exceptions.CancelError()) 247 raise failure.Failure(exceptions.CancelError())
248 248
249 # looks like an actual command, we try to call the corresponding method 249 # looks like an actual command, we try to call the corresponding method
250 def ret_handling(ret): 250 def ret_handling(ret):
251 """ Handle command return value: 251 """Handle command return value:
252 if ret is True, normally send message (possibly modified by command) 252 if ret is True, normally send message (possibly modified by command)
253 else, abord message sending 253 else, abord message sending
254 """ 254 """
255 if ret: 255 if ret:
256 return mess_data 256 return mess_data
379 379
380 whois_msg = [_("whois for %(jid)s") % {"jid": target_jid}] 380 whois_msg = [_("whois for %(jid)s") % {"jid": target_jid}]
381 381
382 d = defer.succeed(None) 382 d = defer.succeed(None)
383 for __, callback in self._whois: 383 for __, callback in self._whois:
384 d.addCallback( 384 d.addCallback(lambda __: callback(client, whois_msg, mess_data, target_jid))
385 lambda __: callback(client, whois_msg, mess_data, target_jid)
386 )
387 385
388 def feed_back(__): 386 def feed_back(__):
389 self.feed_back(client, "\n".join(whois_msg), mess_data) 387 self.feed_back(client, "\n".join(whois_msg), mess_data)
390 return False 388 return False
391 389
462 help_mess = _("/{name}: {short_help}\n{syntax}{args_help}").format( 460 help_mess = _("/{name}: {short_help}\n{syntax}{args_help}").format(
463 name=cmd_name, 461 name=cmd_name,
464 short_help=cmd_data["doc_short_help"], 462 short_help=cmd_data["doc_short_help"],
465 syntax=_(" " * 4 + "syntax: {}\n").format(syntax) if syntax else "", 463 syntax=_(" " * 4 + "syntax: {}\n").format(syntax) if syntax else "",
466 args_help="\n".join( 464 args_help="\n".join(
467 [" " * 8 + "{}".format(line) for line in self._get_args_help(cmd_data)] 465 [
466 " " * 8 + "{}".format(line)
467 for line in self._get_args_help(cmd_data)
468 ]
468 ), 469 ),
469 ) 470 )
470 471
471 self.feed_back(client, help_mess, mess_data) 472 self.feed_back(client, help_mess, mess_data)