|
| 1 | +import os |
| 2 | +from pyrogram import Client, filters, enums |
| 3 | +from pyrogram.types import Message |
| 4 | + |
| 5 | +from utils.misc import modules_help, prefix |
| 6 | +from utils.scripts import import_library |
| 7 | + |
| 8 | +lottie = import_library("lottie") |
| 9 | + |
| 10 | + |
| 11 | +@Client.on_message(filters.command("destroy", prefix) & filters.me) |
| 12 | +async def destroy_sticker(client: Client, message: Message): |
| 13 | + """Destroy animated stickers by modifying their animation properties""" |
| 14 | + try: |
| 15 | + reply = message.reply_to_message |
| 16 | + if not reply or not reply.sticker or not reply.sticker.is_animated: |
| 17 | + return await message.edit( |
| 18 | + "**Please reply to an animated sticker!**", |
| 19 | + parse_mode=enums.ParseMode.MARKDOWN |
| 20 | + ) |
| 21 | + |
| 22 | + edit_msg = await message.edit("**🔄 Destroying sticker...**", parse_mode=enums.ParseMode.MARKDOWN) |
| 23 | + |
| 24 | + # Download sticker |
| 25 | + tgs_path = await client.download_media(reply) |
| 26 | + if not tgs_path or not os.path.exists(tgs_path): |
| 27 | + return await edit_msg.edit("**❌ Download failed!**", parse_mode=enums.ParseMode.MARKDOWN) |
| 28 | + |
| 29 | + # Conversion process |
| 30 | + json_path = "temp.json" |
| 31 | + output_path = "MoonUB.tgs" |
| 32 | + |
| 33 | + os.system(f"lottie_convert.py {tgs_path} {json_path}") |
| 34 | + if not os.path.exists(json_path): |
| 35 | + return await edit_msg.edit("**❌ JSON conversion failed!**", parse_mode=enums.ParseMode.MARKDOWN) |
| 36 | + |
| 37 | + # Modify JSON data |
| 38 | + with open(json_path, "r+") as f: |
| 39 | + content = f.read() |
| 40 | + modified = content.replace("[1]", "[2]") \ |
| 41 | + .replace("[2]", "[3]") \ |
| 42 | + .replace("[3]", "[4]") \ |
| 43 | + .replace("[4]", "[5]") \ |
| 44 | + .replace("[5]", "[6]") |
| 45 | + f.seek(0) |
| 46 | + f.write(modified) |
| 47 | + f.truncate() |
| 48 | + |
| 49 | + # Convert back to TGS |
| 50 | + os.system(f"lottie_convert.py {json_path} {output_path}") |
| 51 | + if not os.path.exists(output_path): |
| 52 | + return await edit_msg.edit("**❌ Final conversion failed!**", parse_mode=enums.ParseMode.MARKDOWN) |
| 53 | + |
| 54 | + # Send result |
| 55 | + await message.reply_document( |
| 56 | + output_path, |
| 57 | + reply_to_message_id=reply.id |
| 58 | + ) |
| 59 | + await edit_msg.delete() |
| 60 | + |
| 61 | + except Exception as e: |
| 62 | + await message.edit(f"**❌ Error:** `{e}`", parse_mode=enums.ParseMode.MARKDOWN) |
| 63 | + finally: |
| 64 | + # Cleanup temporary files |
| 65 | + for file_path in [tgs_path, json_path, output_path]: |
| 66 | + if file_path and os.path.exists(file_path): |
| 67 | + try: |
| 68 | + os.remove(file_path) |
| 69 | + except Exception as clean_error: |
| 70 | + print(f"Cleanup error: {clean_error}") |
| 71 | + |
| 72 | + |
| 73 | +modules_help["destroy"] = { |
| 74 | + "destroy [reply]": "Modify and destroy animated stickers" |
| 75 | +} |
0 commit comments