bugfix spoiler: drop animation support and fix media logic.

This commit is contained in:
thedragonsinn
2024-12-06 13:38:48 +05:30
parent 5b5e3e21f6
commit 3a0c13ab19

View File

@@ -5,7 +5,6 @@ from ub_core.utils import get_tg_media_details
MEDIA_TYPE_MAP: dict[MessageMediaType, str] = {
MessageMediaType.PHOTO: "photo",
MessageMediaType.VIDEO: "video",
MessageMediaType.ANIMATION: "animation",
}
@@ -14,21 +13,22 @@ async def mark_spoiler(bot: BOT, message: Message):
"""
CMD: SPOILER
INFO: Convert Non-Spoiler media to Spoiler
USAGE: .spoiler [reply to a photo | video | animation]
USAGE: .spoiler [reply to a photo | video]
"""
reply_method_str = MEDIA_TYPE_MAP.get(message.media)
reply_message = message.replied
if not message.media or message.document or not reply_method_str:
await message.reply(text="Reply to a Photo | Video | Animation")
try:
reply_method_str = MEDIA_TYPE_MAP.get(reply_message.media)
assert reply_method_str and not reply_message.document
except (AssertionError, AttributeError):
await message.reply(text="Reply to a Photo | Video")
return
media = get_tg_media_details(message=message)
media = get_tg_media_details(message=reply_message)
kwargs = {reply_method_str: media.file_id, "has_spoiler": True}
if message.media == MessageMediaType.ANIMATION and bot.is_user:
kwargs["unsave"] = True
reply_method = getattr(message, f"reply_{reply_method_str}")
await reply_method(**kwargs)