getstickerset 修复部分贴纸包获取预览图失败的问题

This commit is contained in:
xtaodada 2021-08-16 15:23:12 +08:00
parent 01e8b8a210
commit 03f7bed38c
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
2 changed files with 11 additions and 8 deletions

View File

@ -1,4 +1,4 @@
from telethon.errors import StickersetInvalidError
from telethon.errors import StickersetInvalidError, FileMigrateError
from telethon.tl.custom.message import Message
from telethon.tl.functions.messages import GetStickerSetRequest
from telethon.tl.functions.upload import GetFileRequest
@ -65,12 +65,15 @@ async def get_sticker_set(context: Message):
# 下载预览图
file = None
if thumb_version:
try:
thumb = await bot(GetFileRequest(location=InputStickerSetThumb(
stickerset=InputStickerSetID(id=sid, access_hash=access_hash),
thumb_version=thumb_version), offset=-1, limit=1048576, precise=False, cdn_supported=True))
with open('data/sticker_thumb.jpg', 'wb') as f:
f.write(thumb.bytes)
file = 'data/sticker_thumb.jpg'
except FileMigrateError:
pass
else:
if not stickers_set.animated:
await bot.download_media(stickers.documents[0], file='data/sticker_thumb.webp')

View File

@ -732,7 +732,7 @@
},
{
"name": "getstickerset",
"version": "1.0",
"version": "1.01",
"section": "chat",
"maintainer": "xtaodada",
"size": "4.4 kb",