randydev commited on
Commit
206840f
·
verified ·
1 Parent(s): 47cd08e

Update chatbot/plugins/join_request.py

Browse files
Files changed (1) hide show
  1. chatbot/plugins/join_request.py +31 -3
chatbot/plugins/join_request.py CHANGED
@@ -23,7 +23,7 @@ from pyrogram.types import (
23
  Message
24
  )
25
 
26
- from PIL import Image, ImageDraw, ImageFont
27
 
28
  logging.basicConfig(level=logging.INFO)
29
  logger = logging.getLogger(__name__)
@@ -48,13 +48,41 @@ def generate_captcha_multiple_choice():
48
  wrong_choice = ''.join(random.choice(letters) for _ in range(5))
49
  choices.append(wrong_choice)
50
  random.shuffle(choices)
51
- img = Image.new('RGB', (300, 60), color=(255, 255, 255))
 
 
 
52
  d = ImageDraw.Draw(img)
 
 
 
 
 
 
 
53
  try:
54
  font = ImageFont.truetype("arial.ttf", 45)
55
  except IOError:
56
  font = ImageFont.load_default()
57
- d.text((10, 10), captcha_text, font=font, fill=(0, 0, 0))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  img_path = f"captcha_{captcha_text}.png"
59
  img.save(img_path)
60
  return captcha_text, img_path, choices
 
23
  Message
24
  )
25
 
26
+ from PIL import Image, ImageDraw, ImageFont, ImageFilter
27
 
28
  logging.basicConfig(level=logging.INFO)
29
  logger = logging.getLogger(__name__)
 
48
  wrong_choice = ''.join(random.choice(letters) for _ in range(5))
49
  choices.append(wrong_choice)
50
  random.shuffle(choices)
51
+
52
+ width, height = 200, 80
53
+ background_color = (random.randint(200, 255), random.randint(200, 255), random.randint(200, 255)) # Warna pastel
54
+ img = Image.new('RGB', (width, height), color=background_color)
55
  d = ImageDraw.Draw(img)
56
+
57
+ for _ in range(500):
58
+ x = random.randint(0, width)
59
+ y = random.randint(0, height)
60
+ noise_color = (random.randint(150, 200), random.randint(150, 200), random.randint(150, 200))
61
+ d.point((x, y), fill=noise_color)
62
+
63
  try:
64
  font = ImageFont.truetype("arial.ttf", 45)
65
  except IOError:
66
  font = ImageFont.load_default()
67
+
68
+ text_width, text_height = d.textsize(captcha_text, font=font)
69
+ text_x = (width - text_width) / 2
70
+ text_y = (height - text_height) / 2
71
+
72
+ text_image = Image.new('RGBA', (text_width, text_height), (255, 255, 255, 0))
73
+ text_draw = ImageDraw.Draw(text_image)
74
+ text_draw.text((0, 0), captcha_text, font=font, fill=(0, 0, 0))
75
+ rotated_text = text_image.rotate(random.randint(-25, 25), expand=1)
76
+ img.paste(rotated_text, (int(text_x), int(text_y)), rotated_text)
77
+
78
+ for _ in range(5):
79
+ start = (random.randint(0, width), random.randint(0, height))
80
+ end = (random.randint(0, width), random.randint(0, height))
81
+ line_color = (random.randint(0, 150), random.randint(0, 150), random.randint(0, 150))
82
+ d.line([start, end], fill=line_color, width=2)
83
+
84
+ img = img.filter(ImageFilter.BLUR)
85
+
86
  img_path = f"captcha_{captcha_text}.png"
87
  img.save(img_path)
88
  return captcha_text, img_path, choices