diff --git a/src/backend/html_markdown.py b/src/backend/html_markdown.py index d414dc9f..18cc5091 100644 --- a/src/backend/html_markdown.py +++ b/src/backend/html_markdown.py @@ -231,7 +231,8 @@ class HTMLProcessor: # Client-side modifications html = self.quote_regex.sub(r'\1\2\3', html) - html = self.spoiler_regex.sub(r'\1\2\3', html) + html = self.spoiler_regex.sub( + r'\1\2\3', html) if not inline: return html diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 91e79d87..1f74346f 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -636,19 +636,23 @@ class MatrixClient(nio.AsyncClient): reply_to_event_id: Optional[str] = None, ) -> None: if text.startswith("//") or text.startswith(r"\/"): - await self._send_text(room_id, text[1:], display_name_mentions, reply_to_event_id) + await self._send_text( + room_id, text[1:], display_name_mentions, reply_to_event_id) elif text.startswith("/"): - for k,v in self.cmd_handler_map.items(): - if text.startswith("/"+k): - await v(self, room_id, text[len("/"+k):], display_name_mentions, reply_to_event_id) + for k, v in self.cmd_handler_map.items(): + if text.startswith("/" + k): + await v(self, room_id, text[len("/" + k):], + display_name_mentions, reply_to_event_id) break else: await self.send_fake_notice( room_id, - r"That command was not recognised. To send a message starting with /, use //", + r"That command was not recognised. " + r"To send a message starting with /, use //", ) else: - await self._send_text(room_id, text, display_name_mentions, reply_to_event_id) + await self._send_text( + room_id, text, display_name_mentions, reply_to_event_id) async def _send_text( @@ -683,7 +687,7 @@ class MatrixClient(nio.AsyncClient): # override_echo_body will not be effective if it is a reply. # echo_body is only shown before the event is received back from the # server, so this is fine if not ideal - to_html = override_to_html or to_html + to_html = override_to_html or to_html echo_body = override_echo_body or echo_body if to_html not in (html.escape(text), f"

{html.escape(text)}

"): @@ -754,7 +758,7 @@ class MatrixClient(nio.AsyncClient): text, display_name_mentions, reply_to_event_id, - emote=True + emote=True, ) @@ -765,8 +769,9 @@ class MatrixClient(nio.AsyncClient): display_name_mentions: Optional[Dict[str, str]] = None, # {id: name} reply_to_event_id: Optional[str] = None, ) -> None: - if reply_to_event_id is None or reply_to_event_id == '': - await self.send_fake_notice(room_id, "please reply to a message to react to it 🙃") + if reply_to_event_id is None or reply_to_event_id == "": + await self.send_fake_notice( + room_id, "please reply to a message to react to it 🙃") else: reaction = emoji.emojize(text, language="alias") await self.send_reaction(room_id, reaction, reply_to_event_id) @@ -808,17 +813,23 @@ class MatrixClient(nio.AsyncClient): display_name_mentions: Optional[Dict[str, str]] = None, # {id: name} reply_to_event_id: Optional[str] = None, ) -> None: - if reply_to_event_id is None or reply_to_event_id == '': - await self.send_fake_notice(room_id, "Please reply to a message with /unspoiler to unspoiler it 🙃") + if reply_to_event_id is None or reply_to_event_id == "": + await self.send_fake_notice( + room_id, + "Please reply to a message with /unspoiler to unspoiler it 🙃", + ) else: spoiler_event: Event = \ self.models[self.user_id, room_id, "events"][reply_to_event_id] # get formatted_body, fallback to body, - spoiler = getattr(spoiler_event.source, "formatted_body", None) or \ - getattr(spoiler_event.source, "body", "") + spoiler = getattr(spoiler_event.source, "formatted_body", None) \ + or getattr(spoiler_event.source, "body", "") - unspoiler = re.sub(r']+data-mx-spoiler[^>]*>(.*?)', r'\1', spoiler) + unspoiler = re.sub( + r"]+data-mx-spoiler[^>]*>(.*?)", r"\1", + spoiler, + ) await self.send_fake_notice(room_id, unspoiler) @@ -830,7 +841,8 @@ class MatrixClient(nio.AsyncClient): ) -> None: # local event id in model isn't necessarily the actual event id - reacts_to_event_id = self.models[self.user_id, room_id, "events"][reacts_to].event_id + reacts_to_event_id = self.models[ + self.user_id, room_id, "events"][reacts_to].event_id item_uuid = uuid4() @@ -846,7 +858,8 @@ class MatrixClient(nio.AsyncClient): content[f"{__reverse_dns__}.transaction_id"] = str(tx_id) await self.pause_while_offline() - await self._send_message(room_id, content, item_uuid, message_type = "m.reaction") + await self._send_message( + room_id, content, item_uuid, message_type = "m.reaction") # only update the UI after the reaction is sent, to not be misleading await self._register_reaction( @@ -1239,7 +1252,8 @@ class MatrixClient(nio.AsyncClient): async def _send_message( - self, room_id: str, content: dict, transaction_id: UUID, message_type: str = "m.room.message", + self, room_id: str, content: dict, transaction_id: UUID, + message_type: str = "m.room.message", ) -> None: """Send a message event with `content` dict to a room.""" @@ -2631,7 +2645,8 @@ class MatrixClient(nio.AsyncClient): if reacts_to_event: reactions = reacts_to_event.reactions if key not in reactions: - reactions[key] = {"hint": emoji.demojize(key, language="alias"), "users": []} + reactions[key] = { + "hint": emoji.demojize(key, language="alias"), "users": []} if sender not in reactions[key]["users"]: reactions[key]["users"].append(sender) reacts_to_event.set_fields(reactions=reactions)