Add support for bridging spoilers

This commit is contained in:
Tulir Asokan
2021-12-29 22:11:11 +02:00
parent aae8f78cb4
commit afb73b1d17
4 changed files with 11 additions and 3 deletions
@@ -95,5 +95,8 @@ class MatrixParser(BaseMatrixParser[TelegramMessage]):
async def color_to_fstring(self, msg: TelegramMessage, color: str) -> TelegramMessage:
return msg
async def spoiler_to_fstring(self, msg: TelegramMessage, spoiler: str) -> TelegramMessage:
async def spoiler_to_fstring(self, msg: TelegramMessage, reason: str) -> TelegramMessage:
msg = msg.format(self.e.SPOILER)
if reason:
msg = msg.prepend(f"{reason}: ")
return msg
@@ -29,6 +29,7 @@ from telethon.tl.types import (
MessageEntityMention as Mention,
MessageEntityMentionName as MentionName,
MessageEntityPre as Pre,
MessageEntitySpoiler as Spoiler,
MessageEntityStrike as Strike,
MessageEntityTextUrl as TextURL,
MessageEntityUnderline as Underline,
@@ -55,6 +56,7 @@ class TelegramEntityType(Enum):
MENTION = Mention
MENTION_NAME = InputMentionName
COMMAND = Command
SPOILER = Spoiler
USER_MENTION = 1
ROOM_MENTION = 2
@@ -35,6 +35,7 @@ from telethon.tl.types import (
MessageEntityMentionName,
MessageEntityPhone,
MessageEntityPre,
MessageEntitySpoiler,
MessageEntityStrike,
MessageEntityTextUrl,
MessageEntityUnderline,
@@ -293,6 +294,8 @@ async def _telegram_entities_to_matrix(
html.append(f"<font color='blue'>{entity_text}</font>")
elif entity_type in (MessageEntityHashtag, MessageEntityCashtag, MessageEntityPhone):
html.append(f"<font color='blue'>{entity_text}</font>")
elif entity_type == MessageEntitySpoiler:
html.append(f"<span data-mx-spoiler>{entity_text}</span>")
else:
skip_entity = True
last_offset = relative_offset + (0 if skip_entity else entity.length)
+2 -2
View File
@@ -5,8 +5,8 @@ aiohttp>=3,<4
yarl>=1,<2
mautrix>=0.14.0,<0.15
#telethon>=1.24,<1.25
# Fork to make session storage async
tulir-telethon==1.25.0a1
# Fork to make session storage async and update to layer 136
tulir-telethon==1.25.0a2
asyncpg>=0.20,<0.26
mako>=1,<2
setuptools