mirror of
https://github.com/Xtao-Labs/iShotaBot.git
synced 2024-11-21 14:48:23 +00:00
fix: video sticker
This commit is contained in:
parent
58379c3493
commit
d4109d32ed
@ -79,7 +79,7 @@ async def converter(src_file: Union[Path, str]) -> Path:
|
||||
src_file.unlink(missing_ok=True)
|
||||
else:
|
||||
logs.error("转换 %s -> %s 时出错: %s", src_file.name, target_file.name, stderr.decode("utf-8"))
|
||||
raise ValueError
|
||||
raise ValueError("转换 %s -> %s 时出错" % (src_file.name, target_file.name))
|
||||
return target_file
|
||||
|
||||
|
||||
@ -162,14 +162,12 @@ async def get_from_sticker_set(short_name: str, uid: int, client: "Client", repl
|
||||
|
||||
|
||||
async def get_from_sticker(client: "Client", message: "Message") -> Path:
|
||||
sticker_path = temp_path / f"{message.sticker.file_unique_id}.webp"
|
||||
await client.download_media(message, file_name=sticker_path.as_posix())
|
||||
sticker_path = await client.download_media(message)
|
||||
return await converter(sticker_path)
|
||||
|
||||
|
||||
async def get_from_custom_emoji(client: "Client", sticker: "Sticker") -> Path:
|
||||
sticker_path = temp_path / f"{sticker.file_unique_id}.webp"
|
||||
await client.download_media(sticker.file_id, file_name=sticker_path.as_posix())
|
||||
sticker_path = await client.download_media(sticker.file_id)
|
||||
return await converter(sticker_path)
|
||||
|
||||
|
||||
|
@ -43,8 +43,11 @@ async def process_sticker_set(client: "Client", message: "Message"):
|
||||
async def process_single_sticker(client: "Client", message: "Message"):
|
||||
await message.reply_chat_action(ChatAction.TYPING)
|
||||
if temp := await cache.get(f"sticker:export:{message.from_user.id}"):
|
||||
await export_add(temp, message.sticker, client)
|
||||
await message.reply_text("成功加入导出列表,结束选择请输入 /sticker_export_end", quote=True)
|
||||
try:
|
||||
await export_add(temp, message.sticker, client)
|
||||
await message.reply_text("成功加入导出列表,结束选择请输入 /sticker_export_end", quote=True)
|
||||
except ValueError as exc:
|
||||
await message.reply(str(exc), quote=True)
|
||||
else:
|
||||
reply = await message.reply("正在转换贴纸...请耐心等待", quote=True)
|
||||
target_file = None
|
||||
@ -52,11 +55,13 @@ async def process_single_sticker(client: "Client", message: "Message"):
|
||||
target_file = await get_from_sticker(client, message)
|
||||
await message.reply_chat_action(ChatAction.UPLOAD_DOCUMENT)
|
||||
await message.reply_document(target_file.as_posix(), quote=True)
|
||||
with contextlib.suppress(Exception):
|
||||
await reply.delete()
|
||||
except ValueError as exc:
|
||||
await reply.edit(str(exc))
|
||||
finally:
|
||||
if target_file:
|
||||
target_file.unlink(missing_ok=True)
|
||||
with contextlib.suppress(Exception):
|
||||
await reply.delete()
|
||||
raise ContinuePropagation
|
||||
|
||||
|
||||
@ -70,17 +75,23 @@ async def process_custom_emoji(client: "Client", message: "Message"):
|
||||
await message.reply("无法获取贴纸", quote=True)
|
||||
raise ContinuePropagation
|
||||
reply = await message.reply(f"正在下载 {len(stickers)} 个 emoji ...请耐心等待", quote=True)
|
||||
exc = None
|
||||
for sticker in stickers:
|
||||
target_file = None
|
||||
try:
|
||||
target_file = await get_from_custom_emoji(client, sticker)
|
||||
await message.reply_chat_action(ChatAction.UPLOAD_DOCUMENT)
|
||||
await message.reply_document(target_file.as_posix(), quote=True)
|
||||
except ValueError as exc_:
|
||||
exc = exc_
|
||||
finally:
|
||||
if target_file:
|
||||
target_file.unlink(missing_ok=True)
|
||||
with contextlib.suppress(Exception):
|
||||
await reply.delete()
|
||||
if exc:
|
||||
await reply.edit(str(exc))
|
||||
else:
|
||||
with contextlib.suppress(Exception):
|
||||
await reply.delete()
|
||||
raise ContinuePropagation
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user