nvd commited on
Update bot.py
Browse files
bot.py
CHANGED
|
@@ -8,7 +8,7 @@ import aiohttp
|
|
| 8 |
import httpx
|
| 9 |
import logging
|
| 10 |
import tempfile
|
| 11 |
-
import
|
| 12 |
from urllib.parse import unquote
|
| 13 |
|
| 14 |
# ---------- Logging ----------
|
|
@@ -185,16 +185,21 @@ async def download_file(url, dest_path):
|
|
| 185 |
f.write(chunk)
|
| 186 |
logger.info(f"✅ Downloaded file to {dest_path}")
|
| 187 |
|
| 188 |
-
# ---------- APK
|
| 189 |
def create_password_zip(apk_path, zip_path, password="bale"):
|
| 190 |
"""
|
| 191 |
-
Creates a password
|
| 192 |
-
Uses
|
| 193 |
"""
|
| 194 |
-
with
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
# ---------- Message / Callback handlers ----------
|
| 200 |
async def handle_message(message: dict):
|
|
@@ -263,10 +268,10 @@ async def handle_callback(callback: dict):
|
|
| 263 |
# APK handling: compress with password
|
| 264 |
is_apk = original_filename.lower().endswith('.apk')
|
| 265 |
if is_apk:
|
| 266 |
-
base_name = original_filename[:-4] #
|
| 267 |
zip_filename = base_name + ".zip"
|
| 268 |
caption = "🔐 APK inside password‑protected ZIP.\nPassword: `bale`"
|
| 269 |
-
|
| 270 |
else:
|
| 271 |
zip_filename = None
|
| 272 |
caption = "Here you go!"
|
|
@@ -282,19 +287,17 @@ async def handle_callback(callback: dict):
|
|
| 282 |
await download_file(url, tmp_path)
|
| 283 |
|
| 284 |
if is_apk:
|
| 285 |
-
#
|
| 286 |
zip_tmp = tempfile.NamedTemporaryFile(delete=False, suffix="_" + zip_filename)
|
| 287 |
zip_path = zip_tmp.name
|
| 288 |
zip_tmp.close()
|
| 289 |
create_password_zip(tmp_path, zip_path, password="bale")
|
| 290 |
-
#
|
| 291 |
os.unlink(tmp_path)
|
| 292 |
-
# The upload will use the ZIP
|
| 293 |
upload_path = zip_path
|
| 294 |
upload_filename = zip_filename
|
| 295 |
file_size = os.path.getsize(upload_path)
|
| 296 |
-
|
| 297 |
-
await send_message(chat_id, f"🔐 APK compressed into password‑protected ZIP ({os.path.basename(zip_filename)})")
|
| 298 |
else:
|
| 299 |
upload_path = tmp_path
|
| 300 |
upload_filename = original_filename
|
|
|
|
| 8 |
import httpx
|
| 9 |
import logging
|
| 10 |
import tempfile
|
| 11 |
+
import zipfile
|
| 12 |
from urllib.parse import unquote
|
| 13 |
|
| 14 |
# ---------- Logging ----------
|
|
|
|
| 185 |
f.write(chunk)
|
| 186 |
logger.info(f"✅ Downloaded file to {dest_path}")
|
| 187 |
|
| 188 |
+
# ---------- APK → password‑protected ZIP ----------
|
| 189 |
def create_password_zip(apk_path, zip_path, password="bale"):
|
| 190 |
"""
|
| 191 |
+
Creates a password‑protected ZIP archive containing the APK.
|
| 192 |
+
Uses standard library zipfile with ZipCrypto.
|
| 193 |
"""
|
| 194 |
+
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
|
| 195 |
+
arcname = os.path.basename(apk_path)
|
| 196 |
+
# Read the APK and write it with password
|
| 197 |
+
with open(apk_path, 'rb') as fapk:
|
| 198 |
+
data = fapk.read()
|
| 199 |
+
zinfo = zipfile.ZipInfo(arcname)
|
| 200 |
+
zinfo.compress_type = zipfile.ZIP_DEFLATED
|
| 201 |
+
zf.writestr(zinfo, data, pwd=password.encode())
|
| 202 |
+
logger.info(f"🔐 Created password‑protected ZIP: {zip_path}")
|
| 203 |
|
| 204 |
# ---------- Message / Callback handlers ----------
|
| 205 |
async def handle_message(message: dict):
|
|
|
|
| 268 |
# APK handling: compress with password
|
| 269 |
is_apk = original_filename.lower().endswith('.apk')
|
| 270 |
if is_apk:
|
| 271 |
+
base_name = original_filename[:-4] # remove ".apk"
|
| 272 |
zip_filename = base_name + ".zip"
|
| 273 |
caption = "🔐 APK inside password‑protected ZIP.\nPassword: `bale`"
|
| 274 |
+
await send_message(chat_id, f"🔐 Compressing APK into password‑protected ZIP...")
|
| 275 |
else:
|
| 276 |
zip_filename = None
|
| 277 |
caption = "Here you go!"
|
|
|
|
| 287 |
await download_file(url, tmp_path)
|
| 288 |
|
| 289 |
if is_apk:
|
| 290 |
+
# Create password‑protected ZIP
|
| 291 |
zip_tmp = tempfile.NamedTemporaryFile(delete=False, suffix="_" + zip_filename)
|
| 292 |
zip_path = zip_tmp.name
|
| 293 |
zip_tmp.close()
|
| 294 |
create_password_zip(tmp_path, zip_path, password="bale")
|
| 295 |
+
# Remove original APK
|
| 296 |
os.unlink(tmp_path)
|
|
|
|
| 297 |
upload_path = zip_path
|
| 298 |
upload_filename = zip_filename
|
| 299 |
file_size = os.path.getsize(upload_path)
|
| 300 |
+
await send_message(chat_id, f"🔐 Compressed. ZIP size: {file_size/1024/1024:.2f} MB")
|
|
|
|
| 301 |
else:
|
| 302 |
upload_path = tmp_path
|
| 303 |
upload_filename = original_filename
|