azils3/bash
0
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7"""8✘ Commands Available9 10• `{i}zip <reply to file>`11 zip the replied file12 To set password on zip: `{i}zip <password>` reply to file13 14• `{i}unzip <reply to zip file>`15 unzip the replied file.16 17• `{i}azip <reply to file>`18 add file to batch for batch upload zip19 20• `{i}dozip`21 upload batch zip the files u added from `{i}azip`22 To set Password: `{i}dozip <password>`23 24"""25import os26import time27 28from . import (29 HNDLR,30 ULTConfig,31 asyncio,32 bash,33 downloader,34 get_all_files,35 get_string,36 ultroid_cmd,37 uploader,38)39 40 41@ultroid_cmd(pattern="zip( (.*)|$)")42async def zipp(event):43 reply = await event.get_reply_message()44 t = time.time()45 if not reply:46 await event.eor(get_string("zip_1"))47 return48 xx = await event.eor(get_string("com_1"))49 if reply.media:50 if hasattr(reply.media, "document"):51 file = reply.media.document52 image = await downloader(53 reply.file.name, reply.media.document, xx, t, get_string("com_5")54 )55 file = image.name56 else:57 file = await event.download_media(reply)58 inp = file.replace(file.split(".")[-1], "zip")59 if event.pattern_match.group(1).strip():60 await bash(61 f"zip -r --password {event.pattern_match.group(1).strip()} {inp} {file}"62 )63 else:64 await bash(f"zip -r {inp} {file}")65 k = time.time()66 n_file, _ = await event.client.fast_uploader(67 inp, show_progress=True, event=event, message="Uploading...", to_delete=True68 )69 await event.client.send_file(70 event.chat_id,71 n_file,72 force_document=True,73 thumb=ULTConfig.thumb,74 caption=f"`{n_file.name}`",75 reply_to=reply,76 )77 os.remove(inp)78 os.remove(file)79 await xx.delete()80 81 82@ultroid_cmd(pattern="unzip( (.*)|$)")83async def unzipp(event):84 reply = await event.get_reply_message()85 file = event.pattern_match.group(1).strip()86 t = time.time()87 if not ((reply and reply.media) or file):88 await event.eor(get_string("zip_1"))89 return90 xx = await event.eor(get_string("com_1"))91 if reply.media:92 if not hasattr(reply.media, "document"):93 return await xx.edit(get_string("zip_3"))94 file = reply.media.document95 if not reply.file.name.endswith(("zip", "rar", "exe")):96 return await xx.edit(get_string("zip_3"))97 image = await downloader(98 reply.file.name, reply.media.document, xx, t, get_string("com_5")99 )100 file = image.name101 if os.path.isdir("unzip"):102 await bash("rm -rf unzip")103 os.mkdir("unzip")104 await bash(f"7z x {file} -aoa -ounzip")105 await asyncio.sleep(4)106 ok = get_all_files("unzip")107 for x in ok:108 k = time.time()109 n_file, _ = await event.client.fast_uploader(110 x, show_progress=True, event=event, message="Uploading...", to_delete=True111 )112 await event.client.send_file(113 event.chat_id,114 n_file,115 force_document=True,116 thumb=ULTConfig.thumb,117 caption=f"`{n_file.name}`",118 )119 await xx.delete()120 121 122@ultroid_cmd(pattern="addzip$")123async def azipp(event):124 reply = await event.get_reply_message()125 t = time.time()126 if not (reply and reply.media):127 await event.eor(get_string("zip_1"))128 return129 xx = await event.eor(get_string("com_1"))130 if not os.path.isdir("zip"):131 os.mkdir("zip")132 if reply.media:133 if hasattr(reply.media, "document"):134 file = reply.media.document135 image = await downloader(136 f"zip/{reply.file.name}",137 reply.media.document,138 xx,139 t,140 get_string("com_5"),141 )142 143 file = image.name144 else:145 file = await event.download_media(reply.media, "zip/")146 await xx.edit(147 f"Downloaded `{file}` succesfully\nNow Reply To Other Files To Add And Zip all at once"148 )149 150 151@ultroid_cmd(pattern="dozip( (.*)|$)")152async def do_zip(event):153 if not os.path.isdir("zip"):154 return await event.eor(get_string("zip_2").format(HNDLR))155 xx = await event.eor(get_string("com_1"))156 if event.pattern_match.group(1).strip():157 await bash(158 f"zip -r --password {event.pattern_match.group(1).strip()} ultroid.zip zip/*"159 )160 else:161 await bash("zip -r ultroid.zip zip/*")162 k = time.time()163 xxx = await uploader("ultroid.zip", "ultroid.zip", k, xx, get_string("com_6"))164 await event.client.send_file(165 event.chat_id,166 xxx,167 force_document=True,168 thumb=ULTConfig.thumb,169 )170 await bash("rm -rf zip")171 os.remove("ultroid.zip")172 await xx.delete()173 