Skip to content

Commit 1386856

Browse files
Update destroy.py
1 parent 5522dd3 commit 1386856

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

fun/destroy.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from utils.scripts import import_library
77

88
lottie = import_library("lottie")
9+
from lottie.exporters import exporters
10+
from lottie.importers import importers
911

1012

1113
@Client.on_message(filters.command("destroy", prefix) & filters.me)
@@ -16,46 +18,55 @@ async def destroy_sticker(client: Client, message: Message):
1618
if not reply or not reply.sticker or not reply.sticker.is_animated:
1719
return await message.edit(
1820
"**Please reply to an animated sticker!**",
19-
parse_mode=enums.ParseMode.MARKDOWN
21+
parse_mode=enums.ParseMode.MARKDOWN,
2022
)
2123

22-
edit_msg = await message.edit("**🔄 Destroying sticker...**", parse_mode=enums.ParseMode.MARKDOWN)
24+
edit_msg = await message.edit(
25+
"**🔄 Destroying sticker...**", parse_mode=enums.ParseMode.MARKDOWN
26+
)
2327

2428
# Download sticker
25-
tgs_path = await client.download_media(reply)
29+
tgs_path = await reply.download()
2630
if not tgs_path or not os.path.exists(tgs_path):
27-
return await edit_msg.edit("**❌ Download failed!**", parse_mode=enums.ParseMode.MARKDOWN)
31+
return await edit_msg.edit(
32+
"**❌ Download failed!**", parse_mode=enums.ParseMode.MARKDOWN
33+
)
2834

2935
# Conversion process
3036
json_path = "temp.json"
3137
output_path = "MoonUB.tgs"
3238

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)
39+
importer = importers.get_from_filename(tgs_path)
40+
if not importer:
41+
return await edit_msg.edit(
42+
"**❌ JSON conversion failed!**", parse_mode=enums.ParseMode.MARKDOWN
43+
)
44+
45+
animation = importer.process(tgs_path)
46+
exporter = exporters.get_from_filename(json_path)
47+
exporter.process(animation, json_path)
3648

3749
# Modify JSON data
3850
with open(json_path, "r+") as f:
3951
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]")
52+
modified = (
53+
content.replace("[1]", "[2]")
54+
.replace("[2]", "[3]")
55+
.replace("[3]", "[4]")
56+
.replace("[4]", "[5]")
57+
.replace("[5]", "[6]")
58+
)
4559
f.seek(0)
4660
f.write(modified)
4761
f.truncate()
4862

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)
63+
importer = importers.get_from_filename(json_path)
64+
animation = importer.process(json_path)
65+
exporter = exporters.get_from_filename(output_path)
66+
exporter.process(animation, output_path)
5367

5468
# Send result
55-
await message.reply_document(
56-
output_path,
57-
reply_to_message_id=reply.id
58-
)
69+
await message.reply_document(output_path, reply_to_message_id=reply.id)
5970
await edit_msg.delete()
6071

6172
except Exception as e:
@@ -70,6 +81,4 @@ async def destroy_sticker(client: Client, message: Message):
7081
print(f"Cleanup error: {clean_error}")
7182

7283

73-
modules_help["destroy"] = {
74-
"destroy [reply]": "Modify and destroy animated stickers"
75-
}
84+
modules_help["destroy"] = {"destroy [reply]": "Modify and destroy animated stickers"}

0 commit comments

Comments
 (0)