randydev commited on
Commit
4d31582
·
verified ·
1 Parent(s): 0ed11be
Files changed (1) hide show
  1. chatbot/plugins/join_request.py +0 -242
chatbot/plugins/join_request.py DELETED
@@ -1,242 +0,0 @@
1
- import os
2
- import time
3
- import json
4
- import asyncio
5
- import io
6
- import os
7
- import re
8
- import logging
9
- import string
10
- import random
11
- import requests
12
- from pyrogram import *
13
- from pyrogram.types import *
14
- from pyrogram.errors import *
15
- from database import db
16
- from logger import LOGS
17
-
18
- from pyrogram import Client, filters
19
- from pyrogram.enums import ChatMemberStatus, ChatMembersFilter, ChatType
20
- from pyrogram.types import (
21
- CallbackQuery,
22
- InlineKeyboardMarkup,
23
- InlineKeyboardButton,
24
- Message
25
- )
26
-
27
- from PIL import Image, ImageDraw, ImageFont, ImageFilter
28
-
29
- logging.basicConfig(level=logging.INFO)
30
- logger = logging.getLogger(__name__)
31
-
32
- user_list = []
33
- captcha_texts = {}
34
-
35
- def thanks_hacker_by_randydev():
36
- url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR0u8UqJ2JDhfmPOCb_zAHjUQG2NYMjTwLbkq_sQhCQOxX8hn66YbaGFvLL&s=10"
37
- response = requests.get(url)
38
- image_hacker = "hacker.png"
39
- with open(image_hacker, "wb") as f:
40
- f.write(response.content)
41
- return image_hacker
42
-
43
- async def remove_captcha_after_timeout(client, user_id, delay=300):
44
- await asyncio.sleep(delay)
45
- if user_id in captcha_texts:
46
- del captcha_texts[user_id]
47
- await client.send_message(user_id, "⏰ Your CAPTCHA verification has expired. Please try again.")
48
- logger.info(f"CAPTCHA for user {user_id} has expired and been removed.")
49
-
50
- def generate_captcha_multiple_choice():
51
- letters = string.ascii_uppercase + string.digits
52
- captcha_text = ''.join(random.choice(letters) for _ in range(5))
53
- choices = [captcha_text]
54
- for _ in range(2):
55
- wrong_choice = ''.join(random.choice(letters) for _ in range(5))
56
- while wrong_choice in choices:
57
- wrong_choice = ''.join(random.choice(letters) for _ in range(5))
58
- choices.append(wrong_choice)
59
- random.shuffle(choices)
60
-
61
- width, height = 200, 80
62
- background_color = (random.randint(200, 255), random.randint(200, 255), random.randint(200, 255)) # Warna pastel
63
- img = Image.new('RGB', (width, height), color=background_color)
64
- d = ImageDraw.Draw(img)
65
-
66
- for _ in range(500):
67
- x = random.randint(0, width)
68
- y = random.randint(0, height)
69
- noise_color = (random.randint(150, 200), random.randint(150, 200), random.randint(150, 200))
70
- d.point((x, y), fill=noise_color)
71
-
72
- try:
73
- font = ImageFont.truetype("arial.ttf", 45)
74
- except IOError:
75
- font = ImageFont.load_default()
76
-
77
- text_width, text_height = d.textsize(captcha_text, font=font)
78
- text_x = (width - text_width) / 2
79
- text_y = (height - text_height) / 2
80
-
81
- text_image = Image.new('RGBA', (text_width, text_height), (255, 255, 255, 0))
82
- text_draw = ImageDraw.Draw(text_image)
83
- text_draw.text((0, 0), captcha_text, font=font, fill=(0, 0, 0))
84
- rotated_text = text_image.rotate(random.randint(-25, 25), expand=1)
85
- img.paste(rotated_text, (int(text_x), int(text_y)), rotated_text)
86
-
87
- for _ in range(5):
88
- start = (random.randint(0, width), random.randint(0, height))
89
- end = (random.randint(0, width), random.randint(0, height))
90
- line_color = (random.randint(0, 150), random.randint(0, 150), random.randint(0, 150))
91
- d.line([start, end], fill=line_color, width=2)
92
-
93
- img = img.filter(ImageFilter.BLUR)
94
-
95
- img_path = f"captcha_{captcha_text}.png"
96
- img.save(img_path)
97
- return captcha_text, img_path, choices
98
-
99
- @Client.on_chat_join_request(filters.chat("KillerXSupport"))
100
- async def join_request(client: Client, event: ChatJoinRequest):
101
- member = await client.get_chat_member(event.chat.id, "me")
102
- if member.status != ChatMemberStatus.ADMINISTRATOR:
103
- return await client.send_message(event.chat.id, text="I am not an administrator in this group.")
104
- async for m in client.get_chat_members(event.chat.id, filter=ChatMembersFilter.ADMINISTRATORS):
105
- if not m.user.is_bot:
106
- user_list.append(m.user.id)
107
- captcha_text, img_path, choices = generate_captcha_multiple_choice()
108
- captcha_texts[event.from_user.id] = captcha_text
109
- captcha_texts["chat_id"] = event.chat.id
110
- captcha_texts["chat_username"] = event.chat.username
111
- keyboard = InlineKeyboardMarkup(
112
- [
113
- [InlineKeyboardButton(choice, callback_data=f"verify_{event.from_user.id}_{choice}")]
114
- for choice in choices
115
- ] + [
116
- [InlineKeyboardButton("🔄 Refresh CAPTCHA", callback_data="refresh_captcha")],
117
- [InlineKeyboardButton("❌ Cancel", callback_data="cancel_captcha")]
118
- ]
119
- )
120
- if event.chat.type == ChatType.SUPERGROUP:
121
- try:
122
- await client.send_photo(
123
- event.from_user.id,
124
- photo=img_path,
125
- caption=f"❗️ **Verify that you are human!**\n\n❔ Please select the correct CAPTCHA text shown in the image below.",
126
- reply_markup=keyboard
127
- )
128
- os.remove(img_path)
129
- asyncio.create_task(remove_captcha_after_timeout(client, event.from_user.id))
130
- except Exception as e:
131
- await client.send_message(
132
- event.chat.id,
133
- text=str(e)
134
- )
135
- logger.error(str(e))
136
-
137
- @Client.on_callback_query(filters.regex("^cancel_captcha$"))
138
- async def cancel_captcha_callback(client: Client, cb: CallbackQuery):
139
- user_id = cb.from_user.id
140
- if user_id in captcha_texts:
141
- del captcha_texts[user_id]
142
- logger.info(f"User {user_id} has canceled CAPTCHA verification.")
143
- await cb.edit_message_text(
144
- "❌ CAPTCHA verification has been canceled. If you wish to try again,",
145
- disable_web_page_preview=True
146
- )
147
- await cb.answer("CAPTCHA verification canceled.", show_alert=False)
148
- else:
149
- await cb.answer("No active CAPTCHA verification found.", show_alert=True)
150
-
151
- @Client.on_callback_query(filters.regex("^close$"))
152
- async def close_final(client: Client, cb: CallbackQuery):
153
- await cb.message.delete()
154
-
155
- def create_button_join_group(username):
156
- return InlineKeyboardMarkup(
157
- [
158
- [InlineKeyboardButton("🔘 Close", callback_data="close")],
159
- [InlineKeyboardButton("👁️ Join chat", url=f"https://t.me/{username}")],
160
- ]
161
- )
162
-
163
- @Client.on_callback_query(filters.regex("^refresh_captcha$"))
164
- async def refresh_captcha_callback(client: Client, cb: CallbackQuery):
165
- user_id = cb.from_user.id
166
- if user_id in captcha_texts:
167
- del captcha_texts[user_id]
168
- captcha_text, img_path, choices = generate_captcha_multiple_choice()
169
- captcha_texts[user_id] = captcha_text
170
- keyboard = InlineKeyboardMarkup(
171
- [
172
- [InlineKeyboardButton("🔄 Refresh CAPTCHA", callback_data="refresh_captcha")],
173
- [InlineKeyboardButton("✅ Verify", callback_data="verify_captcha")],
174
- [InlineKeyboardButton("❌ Cancel", callback_data="cancel_captcha")]
175
- ]
176
- )
177
- await cb.edit_message_media(
178
- media=InputMediaPhoto(
179
- img_path,
180
- caption=f"❗️ **Verify that you are human!**\n\n❔ Please select the correct CAPTCHA text shown in the image below.",
181
- ),
182
- reply_markup=keyboard
183
- )
184
- os.remove(img_path)
185
- await cb.answer("CAPTCHA refreshed!", show_alert=False)
186
-
187
- @Client.on_callback_query(filters.regex("^verify_"))
188
- async def verify_captcha_multiple_choice_callback(client: Client, cb: CallbackQuery):
189
- data = cb.data.split("_")
190
- if len(data) != 3:
191
- await cb.answer("Invalid data format.", show_alert=True)
192
- return
193
- _, user_id_str, user_choice = data
194
- try:
195
- user_id = int(user_id_str)
196
- except ValueError:
197
- await cb.answer("Invalid user ID.", show_alert=True)
198
- return
199
- if user_id not in captcha_texts:
200
- await cb.answer("❗️ Please start the CAPTCHA verification first.", show_alert=True)
201
- logger.warning(f"User {user_id} attempted to verify CAPTCHA without starting verification.")
202
- return
203
- correct_captcha = captcha_texts.get(user_id)
204
- logger.info(f"User {user_id} selected CAPTCHA: {user_choice} (Expected: {correct_captcha})")
205
- if user_choice == correct_captcha:
206
- hacker_image = thanks_hacker_by_randydev()
207
- await cb.edit_message_media(
208
- media=InputMediaPhoto(
209
- hacker_image,
210
- caption="✅ CAPTCHA verification successful!"
211
- ),
212
- reply_markup=create_button_join_group(captcha_texts.get("chat_username"))
213
- )
214
- logger.info(f"User {user_id} successfully verified CAPTCHA.")
215
- await client.approve_chat_join_request(
216
- chat_id=captcha_texts.get("chat_id"),
217
- user_id=user_id
218
- )
219
- del captcha_texts[user_id]
220
- del captcha_texts["chat_id"]
221
- del captcha_texts["chat_username"]
222
- else:
223
- await cb.edit_message_text("❌ Incorrect CAPTCHA. Please try again")
224
- logger.info(f"User {user_id} failed CAPTCHA verification.")
225
- await client.decline_chat_join_request(
226
- chat_id=captcha_texts.get("chat_id"),
227
- user_id=user_id
228
- )
229
- del captcha_texts[user_id]
230
- del captcha_texts["chat_id"]
231
- del captcha_texts["chat_username"]
232
-
233
- @Client.on_callback_query(filters.regex("^verify_captcha$"))
234
- async def verify_captcha_callback(client: Client, cb: CallbackQuery):
235
- user_id = cb.from_user.id
236
- if user_id not in captcha_texts:
237
- await cb.answer("❗️ Please start the CAPTCHA verification first", show_alert=True)
238
- logger.warning(f"User {user_id} attempted to verify CAPTCHA without starting verification.")
239
- return
240
- await cb.message.reply_text("🔍 **Please enter the CAPTCHA text exactly as shown in the image:**")
241
- await cb.answer()
242
- logger.info(f"User {user_id} is attempting to verify CAPTCHA.")