man balls man balls man balls 2

This commit is contained in:
Owl 2025-05-11 04:22:27 +07:00
parent ec664162f6
commit aa09fef729

31
bot.py
View file

@ -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()