forked from TeamUltroid/Ultroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathziptools.py
147 lines (133 loc) · 4.32 KB
/
ziptools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Ultroid - UserBot
# Copyright (C) 2021 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
✘ Commands Available
• `{i}zip <reply to file>
zip the replied file
• `{i}unzip <reply to zip file>`
unzip the replied file.
• `{i}azip <reply to file>`
add file to batch for batch upload zip
• `{i}dozip`
upload batch zip the files u added from `{i}azip`
"""
import os
import time
from . import *
@ultroid_cmd(pattern="zip$")
async def zipp(event):
reply = await event.get_reply_message()
t = time.time()
if not reply:
await eor(event, "Reply to any media/Document.")
return
xx = await eor(event, "`Processing...`")
if reply.media:
if hasattr(reply.media, "document"):
file = reply.media.document
image = await downloader(
reply.file.name, reply.media.document, xx, t, "Downloading..."
)
file = image.name
else:
file = await event.download_media(reply)
inp = file.replace(file.split(".")[-1], "zip")
await bash(f"zip -r {inp} {file}")
k = time.time()
xxx = await uploader(inp, inp, k, xx, "Uploading...")
await event.client.send_file(
event.chat_id,
xxx,
force_document=True,
thumb="resources/extras/ultroid.jpg",
caption=f"`{xxx.name}`",
reply_to=reply,
)
os.remove(inp)
os.remove(file)
await xx.delete()
@ultroid_cmd(pattern="unzip$")
async def unzipp(event):
reply = await event.get_reply_message()
t = time.time()
if not reply:
await eor(event, "Reply to any media/Document.")
return
xx = await eor(event, "`Processing...`")
if reply.media:
if hasattr(reply.media, "document"):
file = reply.media.document
mime_type = file.mime_type
if "application" not in mime_type:
return await xx.edit("`Reply To zipped File`")
image = await downloader(
reply.file.name, reply.media.document, xx, t, "Downloading..."
)
file = image.name
if not file.endswith(("zip", "rar", "exe")):
return await xx.edit("`Reply To zip File Only`")
else:
return await xx.edit("`Reply to zip file only`")
if not os.path.isdir("unzip"):
os.mkdir("unzip")
else:
os.system("rm -rf unzip")
os.mkdir("unzip")
await bash(f"7z x {file} -aoa -ounzip")
ok = get_all_files("unzip")
for x in ok:
k = time.time()
xxx = await uploader(x, x, k, xx, "Uploading...")
await event.client.send_file(
event.chat_id,
xxx,
force_document=True,
thumb="resources/extras/ultroid.jpg",
caption=f"`{xxx.name}`",
)
await xx.delete()
@ultroid_cmd(pattern="addzip$")
async def azipp(event):
reply = await event.get_reply_message()
t = time.time()
if not reply:
await eor(event, "Reply to any media/Document.")
return
xx = await eor(event, "`Processing...`")
if not os.path.isdir("zip"):
os.mkdir("zip")
if reply.media:
if hasattr(reply.media, "document"):
file = reply.media.document
image = await downloader(
"zip/" + reply.file.name, reply.media.document, xx, t, "Downloading..."
)
file = image.name
else:
file = await event.download_media(reply.media, "zip/")
await xx.edit(
f"Downloaded `{file}` succesfully\nNow Reply To Other Files To Add And Zip all at once"
)
@ultroid_cmd(pattern="dozip$")
async def do_zip(event):
if not os.path.isdir("zip"):
return await eor(
event, "First All Files Via {i}addzip then doZip to zip all files at one."
)
xx = await eor(event, "`processing`")
await bash(f"zip -r ultroid.zip zip/*")
k = time.time()
xxx = await uploader("ultroid.zip", "ultroid.zip", k, xx, "Uploading...")
await event.client.send_file(
event.chat_id,
xxx,
force_document=True,
thumb="resources/extras/ultroid.jpg",
)
os.system("rm -rf zip")
os.remove("ultroid.zip")
await xx.delete()