stickers: passthrough webm and tgs files
I got the mime type of tgs files from here: https://github.com/tulir/Telethon/blob/main/telethon/utils.py#L54 Signed-off-by: Sumner Evans <sumner@beeper.com>
This commit is contained in:
@@ -99,6 +99,7 @@ from telethon.tl.types import (
|
|||||||
DocumentAttributeAudio,
|
DocumentAttributeAudio,
|
||||||
DocumentAttributeFilename,
|
DocumentAttributeFilename,
|
||||||
DocumentAttributeImageSize,
|
DocumentAttributeImageSize,
|
||||||
|
DocumentAttributeSticker,
|
||||||
DocumentAttributeVideo,
|
DocumentAttributeVideo,
|
||||||
GeoPoint,
|
GeoPoint,
|
||||||
InputChannel,
|
InputChannel,
|
||||||
@@ -110,6 +111,7 @@ from telethon.tl.types import (
|
|||||||
InputPeerChat,
|
InputPeerChat,
|
||||||
InputPeerPhotoFileLocation,
|
InputPeerPhotoFileLocation,
|
||||||
InputPeerUser,
|
InputPeerUser,
|
||||||
|
InputStickerSetEmpty,
|
||||||
InputUser,
|
InputUser,
|
||||||
MessageActionChannelCreate,
|
MessageActionChannelCreate,
|
||||||
MessageActionChatAddUser,
|
MessageActionChatAddUser,
|
||||||
@@ -1841,6 +1843,7 @@ class Portal(DBPortal, BasePortal):
|
|||||||
max_image_size = self.config["bridge.image_as_file_size"] * 1000**2
|
max_image_size = self.config["bridge.image_as_file_size"] * 1000**2
|
||||||
max_image_pixels = self.config["bridge.image_as_file_pixels"]
|
max_image_pixels = self.config["bridge.image_as_file_pixels"]
|
||||||
|
|
||||||
|
attributes = []
|
||||||
if self.config["bridge.parallel_file_transfer"] and content.url:
|
if self.config["bridge.parallel_file_transfer"] and content.url:
|
||||||
file_handle, file_size = await util.parallel_transfer_to_telegram(
|
file_handle, file_size = await util.parallel_transfer_to_telegram(
|
||||||
client, self.main_intent, content.url, sender_id
|
client, self.main_intent, content.url, sender_id
|
||||||
@@ -1860,21 +1863,27 @@ class Portal(DBPortal, BasePortal):
|
|||||||
file = await self.main_intent.download_media(content.url)
|
file = await self.main_intent.download_media(content.url)
|
||||||
|
|
||||||
if content.msgtype == MessageType.STICKER:
|
if content.msgtype == MessageType.STICKER:
|
||||||
if mime != "image/gif":
|
if mime == "image/gif":
|
||||||
mime, file, w, h = util.convert_image(
|
|
||||||
file, source_mime=mime, target_type="webp"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# Remove sticker description
|
# Remove sticker description
|
||||||
file_name = "sticker.gif"
|
file_name = "sticker.gif"
|
||||||
|
else:
|
||||||
|
if mime not in ("video/webm", "application/x-tgsticker"):
|
||||||
|
mime, file, w, h = util.convert_image(
|
||||||
|
file, source_mime=mime, target_type="webp"
|
||||||
|
)
|
||||||
|
attributes.append(
|
||||||
|
DocumentAttributeSticker(
|
||||||
|
alt=content.body, stickerset=InputStickerSetEmpty()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
file_handle = await client.upload_file(file)
|
file_handle = await client.upload_file(file)
|
||||||
file_size = len(file)
|
file_size = len(file)
|
||||||
|
|
||||||
file_handle.name = file_name
|
file_handle.name = file_name
|
||||||
force_document = file_size >= max_image_size
|
force_document = file_size >= max_image_size
|
||||||
|
attributes.append(DocumentAttributeFilename(file_name=file_name))
|
||||||
|
|
||||||
attributes = [DocumentAttributeFilename(file_name=file_name)]
|
|
||||||
if content.msgtype == MessageType.VIDEO:
|
if content.msgtype == MessageType.VIDEO:
|
||||||
attributes.append(
|
attributes.append(
|
||||||
DocumentAttributeVideo(
|
DocumentAttributeVideo(
|
||||||
|
|||||||
Reference in New Issue
Block a user