Kaynağa Gözat

fix: conflict

TheHamkerCat 1 yıl önce
ebeveyn
işleme
c1f11d9a7b

+ 6 - 9
Dockerfile

@@ -1,21 +1,18 @@
-FROM python:3.9-slim-bullseye
-
+FROM python:slim-bullseye
 WORKDIR /wbb
 RUN chmod 777 /wbb
 
 RUN apt-get -qq update && apt-get -qq -y upgrade
 RUN DEBIAN_FRONTEND=noninteractive apt-get install -y git gcc build-essential
+ENV PYTHONUNBUFFERED=1
 
-RUN pip3 install -U pip
-COPY requirements.txt .
-RUN pip3 install --no-cache-dir -U -r requirements.txt
+# Copying All Source
+COPY . .
+RUN pip3 install -U pip setuptools wheel && pip3 install --no-cache-dir -U -r requirements.txt
 
 # If u want to use /update feature, uncomment the following and edit
 #RUN git config --global user.email "your_email"
 #RUN git config --global user.name "git_username"
 
-# Copying All Source
-COPY . .
-
 # Starting Bot
-CMD ["python3", "-m", "wbb"]
+ENTRYPOINT ["python3", "-m", "wbb"]

+ 1 - 1
requirements.txt

@@ -26,4 +26,4 @@ img2pdf~=0.5.1
 telegraph~=2.2.0
 pytube~=15.0.0
 pytz~=2024.1
-kurigram==2.2.7
+kurigram==2.2.12

+ 2 - 0
wbb/__init__.py

@@ -25,6 +25,7 @@ import asyncio
 import time
 from inspect import getfullargspec
 from os import path
+from pathlib import Path
 
 from aiohttp import ClientSession
 from motor.motor_asyncio import AsyncIOMotorClient as MongoClient
@@ -41,6 +42,7 @@ if is_config:
 else:
     from sample_config import *
 
+Path("sessions").mkdir(exist_ok=True)
 
 USERBOT_PREFIX = USERBOT_PREFIX
 GBAN_LOG_GROUP_ID = GBAN_LOG_GROUP_ID

+ 1 - 1
wbb/modules/anonymize.py

@@ -25,7 +25,7 @@ from asyncio import gather
 from io import BytesIO
 from json import loads
 from os import remove
-from random import choice
+from secrets import choice
 from traceback import format_exc
 
 from pyrogram import filters

+ 9 - 6
wbb/modules/carbon.py

@@ -40,9 +40,12 @@ async def carbon_func(_, message):
         return await message.reply_text(
             "Reply to a text message to make carbon."
         )
-    m = await message.reply_text("Preparing Carbon")
-    carbon = await make_carbon(message.reply_to_message.text)
-    await m.edit("Uploading")
-    await app.send_document(message.chat.id, carbon)
-    await m.delete()
-    carbon.close()
+    status = await message.reply_text("Preparing Carbon…")
+    try:
+        carbon = await make_carbon(message.reply_to_message.text)
+        await status.edit("Uploading…")
+        await app.send_document(message.chat.id, carbon)
+    except Exception as e:
+        await status.edit(f"❌ Failed: {e}")
+    else:
+        await status.delete()

+ 0 - 2
wbb/modules/greetings.py

@@ -23,7 +23,6 @@ SOFTWARE.
 """
 
 import asyncio
-import os
 from re import findall
 from datetime import datetime, timedelta
 from random import shuffle
@@ -221,7 +220,6 @@ async def handle_new_member(member, chat):
         caption=text,
         reply_markup=keyboard,
     )
-    os.remove(captcha_image)
 
     # Save captcha answers etc in mongodb in case the bot gets crashed or restarted.
     await update_captcha_cache(answers_dicc)

+ 23 - 24
wbb/utils/functions.py

@@ -56,43 +56,42 @@ def generate_captcha():
         return chr(randint(65, 90))
 
     def rndColor():
-        return randint(64, 255), randint(64, 255), randint(64, 255)
+        return (randint(64, 255), randint(64, 255), randint(64, 255))
 
     def rndColor2():
-        return randint(32, 127), randint(32, 127), randint(32, 127)
-
-    # Generate a 4 letter word
-    def gen_wrong_answer():
-        word = ""
-        for _ in range(4):
-            word += gen_letter()
-        return word
-
-    # Generate 8 wrong captcha answers
-    wrong_answers = []
-    for _ in range(8):
-        wrong_answers.append(gen_wrong_answer())
-
-    width = 80 * 4
-    height = 100
+        return (randint(32, 127), randint(32, 127), randint(32, 127))
+
+    wrong_answers = [
+        "".join(gen_letter() for _ in range(4)) for _ in range(8)
+    ]
+
+    width, height = 320, 100
     correct_answer = ""
     font = ImageFont.truetype("assets/arial.ttf", 55)
-    file = f"assets/{randint(1000, 9999)}.jpg"
+
+    # White background
     image = Image.new("RGB", (width, height), (255, 255, 255))
     draw = ImageDraw.Draw(image)
 
-    # Draw random points on image
-    for x in range(width):
-        for y in range(height):
-            draw.point((x, y), fill=rndColor())
+    # Noise (draw random lines instead of painting every pixel)
+    for _ in range(120):
+        x1, y1 = randint(0, width), randint(0, height)
+        x2, y2 = randint(0, width), randint(0, height)
+        draw.line((x1, y1, x2, y2), fill=rndColor(), width=1)
 
+    # Text
     for t in range(4):
         letter = gen_letter()
         correct_answer += letter
         draw.text((60 * t + 50, 15), letter, font=font, fill=rndColor2())
+
     image = image.filter(ImageFilter.BLUR)
-    image.save(file, "jpeg")
-    return [file, correct_answer, wrong_answers]
+    
+    buf = BytesIO() # on memory
+    image.save(buf, "JPEG")
+    buf.name = "captcha.jpg"
+    buf.seek(0)
+    return [buf, correct_answer, wrong_answers]
 
 
 def test_speedtest():