75 lines
2.9 KiB
Diff
75 lines
2.9 KiB
Diff
|
diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py
|
||
|
index 701b3eb..8a266bc 100644
|
||
|
--- a/mautrix_telegram/portal.py
|
||
|
+++ b/mautrix_telegram/portal.py
|
||
|
@@ -1822,6 +1822,35 @@ class Portal(DBPortal, BasePortal):
|
||
|
msgtype=content.msgtype,
|
||
|
)
|
||
|
|
||
|
+ async def _find_telegram_sticker(
|
||
|
+ self,
|
||
|
+ client,
|
||
|
+ metadata
|
||
|
+ ):
|
||
|
+ sticker_set_id = int(metadata["pack"]["id"])
|
||
|
+ from telethon.tl.functions.messages import GetAllStickersRequest
|
||
|
+ sticker_sets = await client(GetAllStickersRequest(0))
|
||
|
+ from telethon.tl.functions.messages import GetStickerSetRequest
|
||
|
+ from telethon.tl.types import InputStickerSetID
|
||
|
+ found_sticker_set = None
|
||
|
+ for sticker_set in sticker_sets.sets:
|
||
|
+ if sticker_set.id == sticker_set_id:
|
||
|
+ found_sticker_set = sticker_set
|
||
|
+ break
|
||
|
+ if not found_sticker_set:
|
||
|
+ return None
|
||
|
+
|
||
|
+ stickers = await client(GetStickerSetRequest(
|
||
|
+ hash = 0,
|
||
|
+ stickerset=InputStickerSetID(
|
||
|
+ id=found_sticker_set.id, access_hash=found_sticker_set.access_hash
|
||
|
+ )
|
||
|
+ ))
|
||
|
+
|
||
|
+ for sticker in stickers.documents:
|
||
|
+ if sticker.id == int(metadata["id"]):
|
||
|
+ return sticker
|
||
|
+
|
||
|
async def _handle_matrix_file(
|
||
|
self,
|
||
|
sender: u.User,
|
||
|
@@ -1842,6 +1871,7 @@ class Portal(DBPortal, BasePortal):
|
||
|
w = h = None
|
||
|
max_image_size = self.config["bridge.image_as_file_size"] * 1000**2
|
||
|
max_image_pixels = self.config["bridge.image_as_file_pixels"]
|
||
|
+ media = None
|
||
|
|
||
|
attributes = []
|
||
|
if self.config["bridge.parallel_file_transfer"] and content.url:
|
||
|
@@ -1863,7 +1893,13 @@ class Portal(DBPortal, BasePortal):
|
||
|
file = await self.main_intent.download_media(content.url)
|
||
|
|
||
|
if content.msgtype == MessageType.STICKER:
|
||
|
- if mime == "image/gif":
|
||
|
+ tg_sticker = None
|
||
|
+ if "net.maunium.telegram.sticker" in content.info:
|
||
|
+ tg_sticker = await self._find_telegram_sticker(client, content.info["net.maunium.telegram.sticker"])
|
||
|
+
|
||
|
+ if tg_sticker is not None:
|
||
|
+ media = tg_sticker
|
||
|
+ elif mime == "image/gif":
|
||
|
# Remove sticker description
|
||
|
file_name = "sticker.gif"
|
||
|
else:
|
||
|
@@ -1911,7 +1947,9 @@ class Portal(DBPortal, BasePortal):
|
||
|
if "fi.mau.telegram.force_document" in content:
|
||
|
force_document = bool(content["fi.mau.telegram.force_document"])
|
||
|
|
||
|
- if (mime == "image/png" or mime == "image/jpeg") and not force_document:
|
||
|
+ if media is not None:
|
||
|
+ pass
|
||
|
+ elif (mime == "image/png" or mime == "image/jpeg") and not force_document:
|
||
|
media = InputMediaUploadedPhoto(file_handle)
|
||
|
else:
|
||
|
media = InputMediaUploadedDocument(
|