From cf2899e24a4af701552b2a6197bcfc6961f07c09 Mon Sep 17 00:00:00 2001
From: owl <lonelyowl@hitler.rocks>
Date: Tue, 13 May 2025 03:28:09 +0700
Subject: [PATCH] shevkan

---
 Dockerfile.tgbot |  2 +-
 bot.py           | 65 ++++++++++++++++++++++++++++++++++--------------
 2 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/Dockerfile.tgbot b/Dockerfile.tgbot
index d89c754..963772e 100644
--- a/Dockerfile.tgbot
+++ b/Dockerfile.tgbot
@@ -1,4 +1,4 @@
-FROM python:3.11
+FROM python:3.13
 
 COPY tgbot/requirements.txt .
 
diff --git a/bot.py b/bot.py
index d31562b..c55af9b 100644
--- a/bot.py
+++ b/bot.py
@@ -9,8 +9,10 @@ import logging
 from tgbot.shit.fed import build_fediverse_inline_results, extract_content
 from tgbot.config import TOKEN, PROMPTING_USERS, EXEC_UIDS
 from tgbot.shit.handlers import handle_xitter, handle_red_ebalo, handle_hentai, handle_cute_button
+from tgbot.shit.shitty_encoder import encode_balls, decode_balls, encode_shevkan, guess_coding, CodingType, \
+    decode_shevkan
 from tgbot.shit.prompting import gen_image
-from tgbot.shit.render import render_text_on_image, image_to_string, encode_text, decode_text
+from tgbot.shit.render import render_text_on_image, image_to_string
 from io import BytesIO
 
 logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
@@ -28,23 +30,11 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
 async def handle_text(update: Update, context: ContextTypes.DEFAULT_TYPE):
 
     if update.message.text.startswith("encode"):
-        text = update.message.text.replace("encode", "")
-
-        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))
-
+        await handle_encode(update, context)
         return
 
     if update.message.text.startswith("decode"):
-        text = update.message.text.replace("decode", "")
-        await context.bot.send_message(chat_id=update.effective_chat.id, text=decode_text(text))
+        await handle_decode(update, context)
         return
 
     if not update.message.text.startswith("prompting") or update.message.from_user["username"] not in PROMPTING_USERS:
@@ -53,7 +43,40 @@ async def handle_text(update: Update, context: ContextTypes.DEFAULT_TYPE):
     else:
         await gen_image(update, context)
 
-# man balls man-balls
+
+async def handle_encode(update: Update, context: ContextTypes.DEFAULT_TYPE):
+    text = update.message.text.replace("encode", "", count=1).strip()
+
+    if text.startswith("shevkan"):
+        text = text.replace("shevkan", "", count=1)
+        encoded_text = encode_shevkan(text)
+    else:
+        encoded_text = encode_balls(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))
+
+
+async def handle_decode(update: Update, context: ContextTypes.DEFAULT_TYPE):
+
+    text = update.message.text.replace("decode", "", count=1)
+
+    coding_type = guess_coding(text)
+
+    if coding_type == CodingType.balls:
+        decoded_text = decode_balls(text)
+    else:
+        decoded_text = decode_shevkan(text)
+
+    await context.bot.send_message(chat_id=update.effective_chat.id, text=decoded_text)
+
+
+# man balls man-balls and shevkan
 async def handle_txt_upload(update: Update, context: ContextTypes.DEFAULT_TYPE):
     document = update.message.document
 
@@ -64,8 +87,14 @@ async def handle_txt_upload(update: Update, context: ContextTypes.DEFAULT_TYPE):
     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))
+    coding_type = guess_coding(text_content)
+
+    if coding_type == CodingType.balls:
+        decoded_text = decode_balls(text_content)
+    else:
+        decoded_text = decode_shevkan(text_content)
+
+    await update.message.reply_text(decoded_text)
 
 
 async def image2string(update: Update, context: ContextTypes.DEFAULT_TYPE):