From 818713ce93b6bde2e7ac04bfaa221c046000369e Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 21 Jun 2025 00:56:29 +0500 Subject: feat: save uploaded file --- main.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 59535a3..d1cf5da 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,26 @@ +from os.path import exists + +from telegram import Update +from telegram.ext import ApplicationBuilder, MessageHandler, CallbackContext, filters +from os import mkdir + +async def download_file(update: Update, _: CallbackContext) -> None: + if not exists("./temp"): + mkdir("./temp") + + if len(update.message.photo) > 0: + file_id = update.message.photo[-1] + file = await update.get_bot().get_file(file_id) + file_path = f"./temp/{file_id.file_unique_id}" + await file.download_to_drive(file_path) + + await update.message.reply_text('Saved!') + def run(): - print("kill all niggers") + print("Starting the bot...") + app = ApplicationBuilder().token("xd").build() + app.add_handler(MessageHandler(filters.PHOTO, download_file)) + app.run_polling() if __name__ == "__main__": run() \ No newline at end of file -- cgit v1.2.3