Spaces:
Running
Running
Upload join_request.py
Browse files- chatbot/plugins/join_request.py +92 -113
chatbot/plugins/join_request.py
CHANGED
@@ -3,52 +3,44 @@ 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 |
captcha_modes = {}
|
35 |
|
36 |
def generate_math_captcha():
|
37 |
operations = ['+', '-', '*']
|
38 |
operation = random.choice(operations)
|
39 |
-
|
40 |
num1 = random.randint(1, 20)
|
41 |
num2 = random.randint(1, 20)
|
42 |
-
|
43 |
if operation == '+':
|
44 |
correct_answer = num1 + num2
|
45 |
elif operation == '-':
|
46 |
correct_answer = num1 - num2
|
47 |
else:
|
48 |
correct_answer = num1 * num2
|
49 |
-
|
50 |
captcha_text = f"{num1} {operation} {num2} = ?"
|
51 |
-
|
52 |
choices = [str(correct_answer)]
|
53 |
while len(choices) < 3:
|
54 |
wrong_answer = correct_answer + random.choice([-5, -3, -2, 2, 3, 5])
|
@@ -89,7 +81,7 @@ def generate_math_captcha():
|
|
89 |
choice_x = 50 + idx * 80
|
90 |
choice_y = height - choice_height - 20
|
91 |
d.text((choice_x, choice_y), choice_text, font=choice_font, fill=(0, 0, 0))
|
92 |
-
|
93 |
for _ in range(5):
|
94 |
start = (random.randint(0, width), random.randint(0, height))
|
95 |
end = (random.randint(0, width), random.randint(0, height))
|
@@ -97,8 +89,10 @@ def generate_math_captcha():
|
|
97 |
d.line([start, end], fill=line_color, width=2)
|
98 |
|
99 |
img = img.filter(ImageFilter.BLUR)
|
|
|
100 |
img_path = f"captcha_math_{captcha_text}.png"
|
101 |
img.save(img_path)
|
|
|
102 |
return captcha_text, img_path, choices, correct_answer
|
103 |
|
104 |
def generate_text_captcha():
|
@@ -155,6 +149,7 @@ def generate_text_captcha():
|
|
155 |
img = img.filter(ImageFilter.BLUR)
|
156 |
img_path = f"captcha_text_{captcha_text}.png"
|
157 |
img.save(img_path)
|
|
|
158 |
return captcha_text, img_path, choices, captcha_text
|
159 |
|
160 |
def generate_captcha(user_id, mode='math'):
|
@@ -206,20 +201,20 @@ async def mode_callback(client: Client, cb: CallbackQuery):
|
|
206 |
user_id = cb.from_user.id
|
207 |
data = cb.data.split("_")
|
208 |
if len(data) != 2:
|
209 |
-
await cb.answer("Invalid selection.", show_alert=True)
|
210 |
return
|
211 |
mode = data[1]
|
212 |
if mode not in ['math', 'text']:
|
213 |
-
await cb.answer("Invalid mode.", show_alert=True)
|
214 |
return
|
215 |
captcha_modes[user_id] = mode
|
216 |
-
await cb.edit_message_text(f"CAPTCHA mode has been set to **{'Mathematics' if mode == 'math' else 'Text'}**.")
|
217 |
await cb.answer("The mode has been changed.", show_alert=False)
|
218 |
logger.info(f"User {user_id} set CAPTCHA mode to {mode}.")
|
219 |
|
220 |
@Client.on_callback_query(filters.regex("^cancel_mode$"))
|
221 |
async def cancel_mode_callback(client: Client, cb: CallbackQuery):
|
222 |
-
await cb.edit_message_text("CAPTCHA mode setting has been canceled.")
|
223 |
await cb.answer("Cancellation successful.", show_alert=False)
|
224 |
logger.info(f"User {cb.from_user.id} canceled CAPTCHA mode setting.")
|
225 |
|
@@ -228,27 +223,32 @@ async def join_request(client: Client, event: ChatJoinRequest):
|
|
228 |
member = await client.get_chat_member(event.chat.id, "me")
|
229 |
if member.status != ChatMemberStatus.ADMINISTRATOR:
|
230 |
return await client.send_message(event.chat.id, text="I am not an administrator in this group.")
|
231 |
-
|
232 |
-
if not m.user.is_bot:
|
233 |
-
user_list.append(m.user.id)
|
234 |
try:
|
235 |
chat_link = await client.export_chat_invite_link(event.chat.id)
|
236 |
except ChatAdminRequired:
|
237 |
await client.send_message(event.chat.id, text="I need to be an administrator to perform this action.")
|
238 |
return
|
|
|
239 |
mode = captcha_modes.get(event.from_user.id, "math")
|
240 |
captcha_text, img_path, choices, correct_answer = generate_captcha(event.from_user.id, mode)
|
241 |
-
captcha_texts[event.from_user.id] =
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
247 |
buttons.append([
|
248 |
InlineKeyboardButton("π Refresh CAPTCHA", callback_data="refresh_captcha"),
|
249 |
InlineKeyboardButton("β Cancel", callback_data="cancel_captcha")
|
250 |
])
|
251 |
keyboard = InlineKeyboardMarkup(buttons)
|
|
|
252 |
if event.chat.type == ChatType.SUPERGROUP:
|
253 |
try:
|
254 |
await client.send_message(
|
@@ -271,70 +271,6 @@ async def join_request(client: Client, event: ChatJoinRequest):
|
|
271 |
)
|
272 |
logger.error(str(e))
|
273 |
|
274 |
-
@Client.on_callback_query(filters.regex("^cancel_captcha$"))
|
275 |
-
async def cancel_captcha_callback(client: Client, cb: CallbackQuery):
|
276 |
-
user_id = cb.from_user.id
|
277 |
-
if user_id in captcha_texts:
|
278 |
-
del captcha_texts[user_id]
|
279 |
-
logger.info(f"User {user_id} has canceled CAPTCHA verification.")
|
280 |
-
await cb.edit_message_text(
|
281 |
-
"β CAPTCHA verification has been canceled. If you wish to try again,",
|
282 |
-
disable_web_page_preview=True
|
283 |
-
)
|
284 |
-
await cb.answer("CAPTCHA verification canceled.", show_alert=False)
|
285 |
-
else:
|
286 |
-
await cb.answer("No active CAPTCHA verification found.", show_alert=True)
|
287 |
-
|
288 |
-
@Client.on_callback_query(filters.regex("^close$"))
|
289 |
-
async def close_final(client: Client, cb: CallbackQuery):
|
290 |
-
await cb.message.delete()
|
291 |
-
|
292 |
-
def create_button_join_group(chat_link):
|
293 |
-
return InlineKeyboardMarkup(
|
294 |
-
[
|
295 |
-
[InlineKeyboardButton("ποΈ Join chat", url=chat_linkp)],
|
296 |
-
[InlineKeyboardButton("π Close", callback_data="close")],
|
297 |
-
]
|
298 |
-
)
|
299 |
-
|
300 |
-
def create_button_userinfo(user_id, username):
|
301 |
-
return InlineKeyboardMarkup(
|
302 |
-
[
|
303 |
-
[InlineKeyboardButton("π€ Chmod +W $USER", url=f"tg://user?id={user_id}")],
|
304 |
-
[InlineKeyboardButton("π Check human Bot", url=f"https://t.me/{username}")],
|
305 |
-
]
|
306 |
-
)
|
307 |
-
|
308 |
-
@Client.on_callback_query(filters.regex("^refresh_captcha$"))
|
309 |
-
async def refresh_captcha_callback(client: Client, cb: CallbackQuery):
|
310 |
-
user_id = cb.from_user.id
|
311 |
-
mode = captcha_modes.get(user_id, 'math')
|
312 |
-
if user_id in captcha_texts:
|
313 |
-
del captcha_texts[user_id]
|
314 |
-
logger.info(f"Old CAPTCHA for user {user_id} has been removed.")
|
315 |
-
captcha_text, img_path, choices, correct_answer = generate_captcha(user_id, mode)
|
316 |
-
captcha_texts[user_id] = (captcha_text, correct_answer)
|
317 |
-
logger.info(f"Generated new {mode} CAPTCHA for user {user_id}: {captcha_text}")
|
318 |
-
buttons = []
|
319 |
-
for choice in choices:
|
320 |
-
buttons.append([InlineKeyboardButton(choice, callback_data=f"verify_{user_id}_{choice}")])
|
321 |
-
buttons.append([
|
322 |
-
InlineKeyboardButton("π Refresh CAPTCHA", callback_data="refresh_captcha"),
|
323 |
-
InlineKeyboardButton("β Cancel", callback_data="cancel_captcha")
|
324 |
-
])
|
325 |
-
keyboard = InlineKeyboardMarkup(buttons)
|
326 |
-
try:
|
327 |
-
await cb.edit_message_media(
|
328 |
-
media=InputMediaPhoto(img_path),
|
329 |
-
reply_markup=keyboard
|
330 |
-
)
|
331 |
-
logger.info(f"Updated CAPTCHA image for user {user_id}.")
|
332 |
-
except Exception as e:
|
333 |
-
await cb.answer("β Failed to update CAPTCHA.", show_alert=True)
|
334 |
-
logger.error(f"Error refreshing CAPTCHA for user {user_id}: {e}")
|
335 |
-
os.remove(img_path)
|
336 |
-
await cb.answer("π CAPTCHA has been updated!", show_alert=False)
|
337 |
-
|
338 |
@Client.on_callback_query(filters.regex("^verify_"))
|
339 |
async def verify_captcha_callback(client: Client, cb: CallbackQuery):
|
340 |
data = cb.data.split("_")
|
@@ -355,9 +291,15 @@ async def verify_captcha_callback(client: Client, cb: CallbackQuery):
|
|
355 |
await cb.answer("βοΈ No active CAPTCHA verification.", show_alert=True)
|
356 |
logger.warning(f"User {user_id} mencoba memverifikasi CAPTCHA tanpa aktif.")
|
357 |
return
|
358 |
-
|
|
|
|
|
|
|
|
|
|
|
359 |
failed_image = failed_hacker_by_randydev()
|
360 |
hacker_image = thanks_hacker_by_randydev()
|
|
|
361 |
try:
|
362 |
if str(user_choice) == str(correct_answer):
|
363 |
await cb.edit_message_media(
|
@@ -365,16 +307,14 @@ async def verify_captcha_callback(client: Client, cb: CallbackQuery):
|
|
365 |
hacker_image,
|
366 |
caption="β
CAPTCHA verification successful!"
|
367 |
),
|
368 |
-
reply_markup=create_button_join_group(
|
369 |
)
|
370 |
logger.info(f"User {user_id} berhasil memverifikasi CAPTCHA.")
|
371 |
await client.approve_chat_join_request(
|
372 |
-
chat_id=
|
373 |
user_id=user_id
|
374 |
)
|
375 |
del captcha_texts[user_id]
|
376 |
-
del captcha_texts["chat_id"]
|
377 |
-
del captcha_texts["chat_link"]
|
378 |
else:
|
379 |
await cb.edit_message_media(
|
380 |
media=InputMediaPhoto(
|
@@ -383,21 +323,49 @@ async def verify_captcha_callback(client: Client, cb: CallbackQuery):
|
|
383 |
)
|
384 |
)
|
385 |
await client.decline_chat_join_request(
|
386 |
-
chat_id=
|
387 |
user_id=user_id
|
388 |
)
|
389 |
logger.info(f"User {user_id} gagal memverifikasi CAPTCHA.")
|
390 |
del captcha_texts[user_id]
|
391 |
-
del captcha_texts["chat_id"]
|
392 |
-
del captcha_texts["chat_link"]
|
393 |
except Exception as e:
|
394 |
await cb.answer(f"Error CAPTCHA: {e}", show_alert=True)
|
395 |
|
396 |
-
@Client.on_callback_query(filters.regex("^
|
397 |
-
async def
|
398 |
-
|
399 |
-
|
400 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
401 |
|
402 |
@Client.on_callback_query(filters.regex("^cancel_captcha$"))
|
403 |
async def cancel_captcha_callback(client: Client, cb: CallbackQuery):
|
@@ -413,12 +381,23 @@ async def cancel_captcha_callback(client: Client, cb: CallbackQuery):
|
|
413 |
await cb.answer("βοΈ No active CAPTCHA verification found.", show_alert=True)
|
414 |
logger.warning(f"User {user_id} attempted to cancel CAPTCHA without active verification.")
|
415 |
|
416 |
-
@Client.on_callback_query(filters.regex("^
|
417 |
-
async def
|
418 |
-
|
419 |
-
if user_id not in captcha_texts:
|
420 |
-
await cb.answer("βοΈ Please start the CAPTCHA verification first", show_alert=True)
|
421 |
-
return
|
422 |
-
await cb.message.reply_text("π **Please enter the CAPTCHA text exactly as shown in the image:**")
|
423 |
await cb.answer()
|
424 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import json
|
4 |
import asyncio
|
5 |
import io
|
|
|
6 |
import re
|
7 |
import logging
|
8 |
import string
|
9 |
import random
|
10 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
from pyrogram import Client, filters
|
|
|
12 |
from pyrogram.types import (
|
13 |
CallbackQuery,
|
14 |
InlineKeyboardMarkup,
|
15 |
InlineKeyboardButton,
|
16 |
+
Message,
|
17 |
+
ChatJoinRequest,
|
18 |
+
ChatType
|
19 |
)
|
20 |
+
from pyrogram.enums import ChatMemberStatus, ChatMembersFilter
|
21 |
+
from pyrogram.errors import ChatAdminRequired
|
22 |
|
23 |
from PIL import Image, ImageDraw, ImageFont, ImageFilter
|
24 |
|
25 |
logging.basicConfig(level=logging.INFO)
|
26 |
logger = logging.getLogger(__name__)
|
27 |
|
|
|
28 |
captcha_texts = {}
|
29 |
captcha_modes = {}
|
30 |
|
31 |
def generate_math_captcha():
|
32 |
operations = ['+', '-', '*']
|
33 |
operation = random.choice(operations)
|
|
|
34 |
num1 = random.randint(1, 20)
|
35 |
num2 = random.randint(1, 20)
|
36 |
+
|
37 |
if operation == '+':
|
38 |
correct_answer = num1 + num2
|
39 |
elif operation == '-':
|
40 |
correct_answer = num1 - num2
|
41 |
else:
|
42 |
correct_answer = num1 * num2
|
|
|
43 |
captcha_text = f"{num1} {operation} {num2} = ?"
|
|
|
44 |
choices = [str(correct_answer)]
|
45 |
while len(choices) < 3:
|
46 |
wrong_answer = correct_answer + random.choice([-5, -3, -2, 2, 3, 5])
|
|
|
81 |
choice_x = 50 + idx * 80
|
82 |
choice_y = height - choice_height - 20
|
83 |
d.text((choice_x, choice_y), choice_text, font=choice_font, fill=(0, 0, 0))
|
84 |
+
|
85 |
for _ in range(5):
|
86 |
start = (random.randint(0, width), random.randint(0, height))
|
87 |
end = (random.randint(0, width), random.randint(0, height))
|
|
|
89 |
d.line([start, end], fill=line_color, width=2)
|
90 |
|
91 |
img = img.filter(ImageFilter.BLUR)
|
92 |
+
|
93 |
img_path = f"captcha_math_{captcha_text}.png"
|
94 |
img.save(img_path)
|
95 |
+
|
96 |
return captcha_text, img_path, choices, correct_answer
|
97 |
|
98 |
def generate_text_captcha():
|
|
|
149 |
img = img.filter(ImageFilter.BLUR)
|
150 |
img_path = f"captcha_text_{captcha_text}.png"
|
151 |
img.save(img_path)
|
152 |
+
|
153 |
return captcha_text, img_path, choices, captcha_text
|
154 |
|
155 |
def generate_captcha(user_id, mode='math'):
|
|
|
201 |
user_id = cb.from_user.id
|
202 |
data = cb.data.split("_")
|
203 |
if len(data) != 2:
|
204 |
+
await cb.answer("β Invalid selection.", show_alert=True)
|
205 |
return
|
206 |
mode = data[1]
|
207 |
if mode not in ['math', 'text']:
|
208 |
+
await cb.answer("β Invalid mode.", show_alert=True)
|
209 |
return
|
210 |
captcha_modes[user_id] = mode
|
211 |
+
await cb.edit_message_text(f"β
CAPTCHA mode has been set to **{'Mathematics' if mode == 'math' else 'Text'}**.")
|
212 |
await cb.answer("The mode has been changed.", show_alert=False)
|
213 |
logger.info(f"User {user_id} set CAPTCHA mode to {mode}.")
|
214 |
|
215 |
@Client.on_callback_query(filters.regex("^cancel_mode$"))
|
216 |
async def cancel_mode_callback(client: Client, cb: CallbackQuery):
|
217 |
+
await cb.edit_message_text("β CAPTCHA mode setting has been canceled.")
|
218 |
await cb.answer("Cancellation successful.", show_alert=False)
|
219 |
logger.info(f"User {cb.from_user.id} canceled CAPTCHA mode setting.")
|
220 |
|
|
|
223 |
member = await client.get_chat_member(event.chat.id, "me")
|
224 |
if member.status != ChatMemberStatus.ADMINISTRATOR:
|
225 |
return await client.send_message(event.chat.id, text="I am not an administrator in this group.")
|
226 |
+
|
|
|
|
|
227 |
try:
|
228 |
chat_link = await client.export_chat_invite_link(event.chat.id)
|
229 |
except ChatAdminRequired:
|
230 |
await client.send_message(event.chat.id, text="I need to be an administrator to perform this action.")
|
231 |
return
|
232 |
+
|
233 |
mode = captcha_modes.get(event.from_user.id, "math")
|
234 |
captcha_text, img_path, choices, correct_answer = generate_captcha(event.from_user.id, mode)
|
235 |
+
captcha_texts[event.from_user.id] = {
|
236 |
+
'captcha_text': captcha_text,
|
237 |
+
'correct_answer': correct_answer,
|
238 |
+
'chat_id': event.chat.id,
|
239 |
+
'chat_link': chat_link
|
240 |
+
}
|
241 |
+
|
242 |
+
buttons = [
|
243 |
+
[InlineKeyboardButton(choice, callback_data=f"verify_{event.from_user.id}_{choice}")]
|
244 |
+
for choice in choices
|
245 |
+
]
|
246 |
buttons.append([
|
247 |
InlineKeyboardButton("π Refresh CAPTCHA", callback_data="refresh_captcha"),
|
248 |
InlineKeyboardButton("β Cancel", callback_data="cancel_captcha")
|
249 |
])
|
250 |
keyboard = InlineKeyboardMarkup(buttons)
|
251 |
+
|
252 |
if event.chat.type == ChatType.SUPERGROUP:
|
253 |
try:
|
254 |
await client.send_message(
|
|
|
271 |
)
|
272 |
logger.error(str(e))
|
273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
@Client.on_callback_query(filters.regex("^verify_"))
|
275 |
async def verify_captcha_callback(client: Client, cb: CallbackQuery):
|
276 |
data = cb.data.split("_")
|
|
|
291 |
await cb.answer("βοΈ No active CAPTCHA verification.", show_alert=True)
|
292 |
logger.warning(f"User {user_id} mencoba memverifikasi CAPTCHA tanpa aktif.")
|
293 |
return
|
294 |
+
captcha_data = captcha_texts.get(user_id)
|
295 |
+
captcha_text = captcha_data['captcha_text']
|
296 |
+
correct_answer = captcha_data['correct_answer']
|
297 |
+
chat_id = captcha_data['chat_id']
|
298 |
+
chat_link = captcha_data['chat_link']
|
299 |
+
|
300 |
failed_image = failed_hacker_by_randydev()
|
301 |
hacker_image = thanks_hacker_by_randydev()
|
302 |
+
|
303 |
try:
|
304 |
if str(user_choice) == str(correct_answer):
|
305 |
await cb.edit_message_media(
|
|
|
307 |
hacker_image,
|
308 |
caption="β
CAPTCHA verification successful!"
|
309 |
),
|
310 |
+
reply_markup=create_button_join_group(chat_link)
|
311 |
)
|
312 |
logger.info(f"User {user_id} berhasil memverifikasi CAPTCHA.")
|
313 |
await client.approve_chat_join_request(
|
314 |
+
chat_id=chat_id,
|
315 |
user_id=user_id
|
316 |
)
|
317 |
del captcha_texts[user_id]
|
|
|
|
|
318 |
else:
|
319 |
await cb.edit_message_media(
|
320 |
media=InputMediaPhoto(
|
|
|
323 |
)
|
324 |
)
|
325 |
await client.decline_chat_join_request(
|
326 |
+
chat_id=chat_id,
|
327 |
user_id=user_id
|
328 |
)
|
329 |
logger.info(f"User {user_id} gagal memverifikasi CAPTCHA.")
|
330 |
del captcha_texts[user_id]
|
|
|
|
|
331 |
except Exception as e:
|
332 |
await cb.answer(f"Error CAPTCHA: {e}", show_alert=True)
|
333 |
|
334 |
+
@Client.on_callback_query(filters.regex("^refresh_captcha$"))
|
335 |
+
async def refresh_captcha_callback(client: Client, cb: CallbackQuery):
|
336 |
+
user_id = cb.from_user.id
|
337 |
+
mode = captcha_modes.get(user_id, 'math')
|
338 |
+
if user_id in captcha_texts:
|
339 |
+
del captcha_texts[user_id]
|
340 |
+
logger.info(f"Old CAPTCHA for user {user_id} has been removed.")
|
341 |
+
captcha_text, img_path, choices, correct_answer = generate_captcha(user_id, mode)
|
342 |
+
captcha_texts[user_id] = {
|
343 |
+
'captcha_text': captcha_text,
|
344 |
+
'correct_answer': correct_answer,
|
345 |
+
'chat_id': captcha_texts[user_id]['chat_id'],
|
346 |
+
'chat_link': captcha_texts[user_id]['chat_link']
|
347 |
+
}
|
348 |
+
logger.info(f"Generated new {mode} CAPTCHA for user {user_id}: {captcha_text}")
|
349 |
+
buttons = [
|
350 |
+
[InlineKeyboardButton(choice, callback_data=f"verify_{user_id}_{choice}")]
|
351 |
+
for choice in choices
|
352 |
+
]
|
353 |
+
buttons.append([
|
354 |
+
InlineKeyboardButton("π Refresh CAPTCHA", callback_data="refresh_captcha"),
|
355 |
+
InlineKeyboardButton("β Cancel", callback_data="cancel_captcha")
|
356 |
+
])
|
357 |
+
keyboard = InlineKeyboardMarkup(buttons)
|
358 |
+
try:
|
359 |
+
await cb.edit_message_media(
|
360 |
+
media=InputMediaPhoto(open(img_path, "rb")),
|
361 |
+
reply_markup=keyboard
|
362 |
+
)
|
363 |
+
logger.info(f"Updated CAPTCHA image for user {user_id}.")
|
364 |
+
except Exception as e:
|
365 |
+
await cb.answer("β Failed to update CAPTCHA.", show_alert=True)
|
366 |
+
logger.error(f"Error refreshing CAPTCHA for user {user_id}: {e}")
|
367 |
+
os.remove(img_path)
|
368 |
+
await cb.answer("π CAPTCHA has been updated!", show_alert=False)
|
369 |
|
370 |
@Client.on_callback_query(filters.regex("^cancel_captcha$"))
|
371 |
async def cancel_captcha_callback(client: Client, cb: CallbackQuery):
|
|
|
381 |
await cb.answer("βοΈ No active CAPTCHA verification found.", show_alert=True)
|
382 |
logger.warning(f"User {user_id} attempted to cancel CAPTCHA without active verification.")
|
383 |
|
384 |
+
@Client.on_callback_query(filters.regex("^close$"))
|
385 |
+
async def close_final(client: Client, cb: CallbackQuery):
|
386 |
+
await cb.message.delete()
|
|
|
|
|
|
|
|
|
387 |
await cb.answer()
|
388 |
+
|
389 |
+
def create_button_join_group(chat_link):
|
390 |
+
return InlineKeyboardMarkup(
|
391 |
+
[
|
392 |
+
[InlineKeyboardButton("ποΈ Join chat", url=chat_link)],
|
393 |
+
[InlineKeyboardButton("π Close", callback_data="close")],
|
394 |
+
]
|
395 |
+
)
|
396 |
+
|
397 |
+
def create_button_userinfo(user_id, username):
|
398 |
+
return InlineKeyboardMarkup(
|
399 |
+
[
|
400 |
+
[InlineKeyboardButton("π€ Chmod +W $USER", url=f"tg://user?id={user_id}")],
|
401 |
+
[InlineKeyboardButton("π Check human Bot", url=f"https://t.me/{username}")],
|
402 |
+
]
|
403 |
+
)
|