From aa09fef7296b4013dd691b603010445485759a87 Mon Sep 17 00:00:00 2001 From: owl Date: Sun, 11 May 2025 04:22:27 +0700 Subject: [PATCH] man balls man balls man balls 2 --- bot.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index b88b4d1..9e3613a 100644 --- a/bot.py +++ b/bot.py @@ -1,4 +1,4 @@ -from telegram import Update +from telegram import Update, InputFile from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, filters, InlineQueryHandler, \ CallbackContext, CallbackQueryHandler import logging @@ -26,8 +26,16 @@ async def handle_text(update: Update, context: ContextTypes.DEFAULT_TYPE): if update.message.text.startswith("encode"): text = update.message.text.replace("encode", "") - await context.bot.send_message(chat_id=update.effective_chat.id, text=encode_text(text)) - return + + encoded_text = encode_text(text) + + if len(encoded_text) < 4096: + await context.bot.send_message(chat_id=update.effective_chat.id, text=encoded_text) + + else: + bio = BytesIO(encoded_text.encode("utf-8")) + bio.name = "output.txt" # must set filename + await update.message.reply_document(document=InputFile(bio)) if update.message.text.startswith("decode"): text = update.message.text.replace("decode", "") @@ -40,6 +48,20 @@ async def handle_text(update: Update, context: ContextTypes.DEFAULT_TYPE): else: await gen_image(update, context) +# man balls man-balls +async def handle_txt_upload(update: Update, context: ContextTypes.DEFAULT_TYPE): + document = update.message.document + + if not document or not document.file_name.endswith(".txt"): + return + + file = await document.get_file() + file_bytes = await file.download_as_bytearray() + text_content = file_bytes.decode("utf-8") + + # Do something with the content + await update.message.reply_text(decode_text(text_content)) + async def image2string(update: Update, context: ContextTypes.DEFAULT_TYPE): photo = update.message.photo[-1] @@ -108,6 +130,9 @@ def main(): application.add_handler(InlineQueryHandler(handle_inline)) application.add_handler(CallbackQueryHandler(callback_query_handler)) + txt_file_filter = filters.Document.FileExtension("txt") + application.add_handler(MessageHandler(txt_file_filter, handle_txt_upload)) + application.run_polling()