Mercurial > libervia-backend
diff sat/plugins/plugin_exp_parrot.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | be6d91572633 |
children | c23cad65ae99 |
line wrap: on
line diff
--- a/sat/plugins/plugin_exp_parrot.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat/plugins/plugin_exp_parrot.py Sat Apr 08 13:54:42 2023 +0200 @@ -48,21 +48,21 @@ # XXX: This plugin can be potentially dangerous if we don't trust entities linked # this is specially true if we have other triggers. - # sendMessageTrigger avoid other triggers execution, it's deactivated to allow + # send_message_trigger avoid other triggers execution, it's deactivated to allow # /unparrot command in text commands plugin. # FIXME: potentially unsecure, specially with e2e encryption def __init__(self, host): log.info(_("Plugin Parrot initialization")) self.host = host - host.trigger.add("messageReceived", self.messageReceivedTrigger, priority=100) - # host.trigger.add("sendMessage", self.sendMessageTrigger, priority=100) + host.trigger.add("messageReceived", self.message_received_trigger, priority=100) + # host.trigger.add("sendMessage", self.send_message_trigger, priority=100) try: - self.host.plugins[C.TEXT_CMDS].registerTextCommands(self) + self.host.plugins[C.TEXT_CMDS].register_text_commands(self) except KeyError: log.info(_("Text commands not available")) - # def sendMessageTrigger(self, client, mess_data, treatments): + # def send_message_trigger(self, client, mess_data, treatments): # """ Deactivate other triggers if recipient is in parrot links """ # try: # _links = client.parrot_links @@ -73,7 +73,7 @@ # log.debug("Parrot link detected, skipping other triggers") # raise trigger.SkipOtherTriggers - def messageReceivedTrigger(self, client, message_elt, post_treat): + def message_received_trigger(self, client, message_elt, post_treat): """ Check if source is linked and repeat message, else do nothing """ # TODO: many things are not repeated (subject, thread, etc) from_jid = message_elt["from"] @@ -92,13 +92,13 @@ lang = e.getAttribute("lang") or "" try: - entity_type = self.host.memory.getEntityData( + entity_type = self.host.memory.entity_data_get( client, from_jid, [C.ENTITY_TYPE])[C.ENTITY_TYPE] except (UnknownEntityError, KeyError): entity_type = "contact" if entity_type == C.ENTITY_TYPE_MUC: src_txt = from_jid.resource - if src_txt == self.host.plugins["XEP-0045"].getRoomNick( + if src_txt == self.host.plugins["XEP-0045"].get_room_nick( client, from_jid.userhostJID() ): # we won't repeat our own messages @@ -115,7 +115,7 @@ return True - def addParrot(self, client, source_jid, dest_jid): + def add_parrot(self, client, source_jid, dest_jid): """Add a parrot link from one entity to another one @param source_jid: entity from who messages will be repeated @@ -132,7 +132,7 @@ % (source_jid.userhost(), str(dest_jid)) ) - def removeParrot(self, client, source_jid): + def remove_parrot(self, client, source_jid): """Remove parrot link @param source_jid: this entity will no more be repeated @@ -152,17 +152,17 @@ if not link_left_jid.user or not link_left_jid.host: raise jid.InvalidFormat except (RuntimeError, jid.InvalidFormat, AttributeError): - txt_cmd.feedBack( + txt_cmd.feed_back( client, "Can't activate Parrot mode for invalid jid", mess_data ) return False link_right_jid = mess_data["to"] - self.addParrot(client, link_left_jid, link_right_jid) - self.addParrot(client, link_right_jid, link_left_jid) + self.add_parrot(client, link_left_jid, link_right_jid) + self.add_parrot(client, link_right_jid, link_left_jid) - txt_cmd.feedBack( + txt_cmd.feed_back( client, "Parrot mode activated for {}".format(str(link_left_jid)), mess_data, @@ -180,17 +180,17 @@ if not link_left_jid.user or not link_left_jid.host: raise jid.InvalidFormat except jid.InvalidFormat: - txt_cmd.feedBack( + txt_cmd.feed_back( client, "Can't deactivate Parrot mode for invalid jid", mess_data ) return False link_right_jid = mess_data["to"] - self.removeParrot(client, link_left_jid) - self.removeParrot(client, link_right_jid) + self.remove_parrot(client, link_left_jid) + self.remove_parrot(client, link_right_jid) - txt_cmd.feedBack( + txt_cmd.feed_back( client, "Parrot mode deactivated for {} and {}".format( str(link_left_jid), str(link_right_jid)