pep8 fix
This commit is contained in:
parent
160670bea3
commit
8eb1afb91c
|
@ -231,7 +231,8 @@ class HTMLProcessor:
|
||||||
# Client-side modifications
|
# Client-side modifications
|
||||||
|
|
||||||
html = self.quote_regex.sub(r'\1<span class="quote">\2</span>\3', html)
|
html = self.quote_regex.sub(r'\1<span class="quote">\2</span>\3', html)
|
||||||
html = self.spoiler_regex.sub(r'\1<font color="#00000000">\2</font>\3', html)
|
html = self.spoiler_regex.sub(
|
||||||
|
r'\1<font color="#00000000">\2</font>\3', html)
|
||||||
|
|
||||||
if not inline:
|
if not inline:
|
||||||
return html
|
return html
|
||||||
|
|
|
@ -636,19 +636,23 @@ class MatrixClient(nio.AsyncClient):
|
||||||
reply_to_event_id: Optional[str] = None,
|
reply_to_event_id: Optional[str] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
if text.startswith("//") or text.startswith(r"\/"):
|
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("/"):
|
elif text.startswith("/"):
|
||||||
for k,v in self.cmd_handler_map.items():
|
for k, v in self.cmd_handler_map.items():
|
||||||
if text.startswith("/"+k):
|
if text.startswith("/" + k):
|
||||||
await v(self, room_id, text[len("/"+k):], display_name_mentions, reply_to_event_id)
|
await v(self, room_id, text[len("/" + k):],
|
||||||
|
display_name_mentions, reply_to_event_id)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
await self.send_fake_notice(
|
await self.send_fake_notice(
|
||||||
room_id,
|
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:
|
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(
|
async def _send_text(
|
||||||
|
@ -683,7 +687,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
# override_echo_body will not be effective if it is a reply.
|
# 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
|
# echo_body is only shown before the event is received back from the
|
||||||
# server, so this is fine if not ideal
|
# 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
|
echo_body = override_echo_body or echo_body
|
||||||
|
|
||||||
if to_html not in (html.escape(text), f"<p>{html.escape(text)}</p>"):
|
if to_html not in (html.escape(text), f"<p>{html.escape(text)}</p>"):
|
||||||
|
@ -754,7 +758,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
text,
|
text,
|
||||||
display_name_mentions,
|
display_name_mentions,
|
||||||
reply_to_event_id,
|
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}
|
display_name_mentions: Optional[Dict[str, str]] = None, # {id: name}
|
||||||
reply_to_event_id: Optional[str] = None,
|
reply_to_event_id: Optional[str] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
if reply_to_event_id is None or reply_to_event_id == '':
|
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 🙃")
|
await self.send_fake_notice(
|
||||||
|
room_id, "please reply to a message to react to it 🙃")
|
||||||
else:
|
else:
|
||||||
reaction = emoji.emojize(text, language="alias")
|
reaction = emoji.emojize(text, language="alias")
|
||||||
await self.send_reaction(room_id, reaction, reply_to_event_id)
|
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}
|
display_name_mentions: Optional[Dict[str, str]] = None, # {id: name}
|
||||||
reply_to_event_id: Optional[str] = None,
|
reply_to_event_id: Optional[str] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
if reply_to_event_id is None or reply_to_event_id == '':
|
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 🙃")
|
await self.send_fake_notice(
|
||||||
|
room_id,
|
||||||
|
"Please reply to a message with /unspoiler to unspoiler it 🙃",
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
spoiler_event: Event = \
|
spoiler_event: Event = \
|
||||||
self.models[self.user_id, room_id, "events"][reply_to_event_id]
|
self.models[self.user_id, room_id, "events"][reply_to_event_id]
|
||||||
|
|
||||||
# get formatted_body, fallback to body,
|
# get formatted_body, fallback to body,
|
||||||
spoiler = getattr(spoiler_event.source, "formatted_body", None) or \
|
spoiler = getattr(spoiler_event.source, "formatted_body", None) \
|
||||||
getattr(spoiler_event.source, "body", "")
|
or getattr(spoiler_event.source, "body", "")
|
||||||
|
|
||||||
unspoiler = re.sub(r'<span[^>]+data-mx-spoiler[^>]*>(.*?)</?span>', r'\1', spoiler)
|
unspoiler = re.sub(
|
||||||
|
r"<span[^>]+data-mx-spoiler[^>]*>(.*?)</?span>", r"\1",
|
||||||
|
spoiler,
|
||||||
|
)
|
||||||
await self.send_fake_notice(room_id, unspoiler)
|
await self.send_fake_notice(room_id, unspoiler)
|
||||||
|
|
||||||
|
|
||||||
|
@ -830,7 +841,8 @@ class MatrixClient(nio.AsyncClient):
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
# local event id in model isn't necessarily the actual event id
|
# 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()
|
item_uuid = uuid4()
|
||||||
|
|
||||||
|
@ -846,7 +858,8 @@ class MatrixClient(nio.AsyncClient):
|
||||||
content[f"{__reverse_dns__}.transaction_id"] = str(tx_id)
|
content[f"{__reverse_dns__}.transaction_id"] = str(tx_id)
|
||||||
|
|
||||||
await self.pause_while_offline()
|
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
|
# only update the UI after the reaction is sent, to not be misleading
|
||||||
await self._register_reaction(
|
await self._register_reaction(
|
||||||
|
@ -1239,7 +1252,8 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
|
|
||||||
async def _send_message(
|
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:
|
) -> None:
|
||||||
"""Send a message event with `content` dict to a room."""
|
"""Send a message event with `content` dict to a room."""
|
||||||
|
|
||||||
|
@ -2631,7 +2645,8 @@ class MatrixClient(nio.AsyncClient):
|
||||||
if reacts_to_event:
|
if reacts_to_event:
|
||||||
reactions = reacts_to_event.reactions
|
reactions = reacts_to_event.reactions
|
||||||
if key not in 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"]:
|
if sender not in reactions[key]["users"]:
|
||||||
reactions[key]["users"].append(sender)
|
reactions[key]["users"].append(sender)
|
||||||
reacts_to_event.set_fields(reactions=reactions)
|
reacts_to_event.set_fields(reactions=reactions)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user