6
6
from utils .scripts import import_library
7
7
8
8
lottie = import_library ("lottie" )
9
+ from lottie .exporters import exporters
10
+ from lottie .importers import importers
9
11
10
12
11
13
@Client .on_message (filters .command ("destroy" , prefix ) & filters .me )
@@ -16,46 +18,55 @@ async def destroy_sticker(client: Client, message: Message):
16
18
if not reply or not reply .sticker or not reply .sticker .is_animated :
17
19
return await message .edit (
18
20
"**Please reply to an animated sticker!**" ,
19
- parse_mode = enums .ParseMode .MARKDOWN
21
+ parse_mode = enums .ParseMode .MARKDOWN ,
20
22
)
21
23
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
+ )
23
27
24
28
# Download sticker
25
- tgs_path = await client . download_media ( reply )
29
+ tgs_path = await reply . download ( )
26
30
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
+ )
28
34
29
35
# Conversion process
30
36
json_path = "temp.json"
31
37
output_path = "MoonUB.tgs"
32
38
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 )
36
48
37
49
# Modify JSON data
38
50
with open (json_path , "r+" ) as f :
39
51
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
+ )
45
59
f .seek (0 )
46
60
f .write (modified )
47
61
f .truncate ()
48
62
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 )
53
67
54
68
# 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 )
59
70
await edit_msg .delete ()
60
71
61
72
except Exception as e :
@@ -70,6 +81,4 @@ async def destroy_sticker(client: Client, message: Message):
70
81
print (f"Cleanup error: { clean_error } " )
71
82
72
83
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